69
69
#include < gtest/gtest.h>
70
70
#include < mpi.h>
71
71
#include < unistd.h>
72
+
73
+ #include < cstdlib>
72
74
#include < set>
73
75
#include < string>
76
+
74
77
#include " gtest_mpi_internal.hpp"
75
78
76
79
namespace gtest_mpi {
@@ -149,7 +152,6 @@ class PrettyMPIUnitTestResultPrinter : public ::testing::TestEventListener {
149
152
void PrettyMPIUnitTestResultPrinter::OnTestIterationStart (const ::testing::UnitTest& unit_test,
150
153
int iteration) {
151
154
using namespace ::testing;
152
- using namespace ::testing::internal;
153
155
if (rank_ != 0 ) return ;
154
156
155
157
if (GTEST_FLAG (repeat) != 1 )
@@ -159,14 +161,14 @@ void PrettyMPIUnitTestResultPrinter::OnTestIterationStart(const ::testing::UnitT
159
161
160
162
// Prints the filter if it's not *. This reminds the user that some
161
163
// tests may be skipped.
162
- if (!String:: CStringEquals (filter, kUniversalFilter )) {
164
+ if (!CStringEquals (filter, kUniversalFilter )) {
163
165
ColoredPrintf (COLOR_YELLOW, " Note: %s filter = %s\n " , GTEST_NAME_, filter);
164
166
}
165
167
166
168
if (ShouldShard (kTestTotalShards , kTestShardIndex , false )) {
167
169
const Int32 shard_index = Int32FromEnvOrDie (kTestShardIndex , -1 );
168
170
ColoredPrintf (COLOR_YELLOW, " Note: This is test shard %d of %s.\n " ,
169
- static_cast <int >(shard_index) + 1 , internal::posix::GetEnv ( kTestTotalShards ));
171
+ static_cast <int >(shard_index) + 1 , std::getenv ( " GTEST_SHARD_STATUS_FILE " ));
170
172
}
171
173
172
174
if (GTEST_FLAG (shuffle)) {
@@ -180,6 +182,22 @@ void PrettyMPIUnitTestResultPrinter::OnTestIterationStart(const ::testing::UnitT
180
182
fflush (stdout);
181
183
}
182
184
185
+ // Taken / modified from Googletest
186
+ // Formats a source file path and a line number as they would appear
187
+ // in an error message from the compiler used to compile this code.
188
+ GTEST_API_ ::std::string FormatFileLocation (const char * file, int line) {
189
+ const std::string file_name (file == nullptr ? " unkown file" : file);
190
+
191
+ if (line < 0 ) {
192
+ return file_name + " :" ;
193
+ }
194
+ #ifdef _MSC_VER
195
+ return file_name + " (" + std::to_string (line) + " ):" ;
196
+ #else
197
+ return file_name + " :" + std::to_string (line) + " :" ;
198
+ #endif // _MSC_VER
199
+ }
200
+
183
201
// Taken / modified from Googletest
184
202
void PrettyMPIUnitTestResultPrinter::OnEnvironmentsSetUpStart (
185
203
const ::testing::UnitTest& /* unit_test*/ ) {
@@ -192,7 +210,6 @@ void PrettyMPIUnitTestResultPrinter::OnEnvironmentsSetUpStart(
192
210
// Taken / modified from Googletest
193
211
void PrettyMPIUnitTestResultPrinter::OnTestCaseStart (const ::testing::TestCase& test_case) {
194
212
using namespace ::testing;
195
- using namespace ::testing::internal;
196
213
if (rank_ != 0 ) return ;
197
214
const std::string counts = FormatCountableNoun (test_case.test_to_run_count (), " test" , " tests" );
198
215
ColoredPrintf (COLOR_GREEN, " [----------] " );
@@ -218,7 +235,6 @@ void PrettyMPIUnitTestResultPrinter::OnTestStart(const ::testing::TestInfo& test
218
235
// Taken / modified from Googletest
219
236
void PrettyMPIUnitTestResultPrinter::OnTestPartResult (const ::testing::TestPartResult& result) {
220
237
using namespace ::testing;
221
- using namespace ::testing::internal;
222
238
// If the test part succeeded, we don't need to do anything.
223
239
if (result.type () == TestPartResult::kSuccess ) return ;
224
240
failed_results_.Add (result);
@@ -228,13 +244,11 @@ void PrettyMPIUnitTestResultPrinter::OnTestPartResult(const ::testing::TestPartR
228
244
void PrintFailedTestResultCollection (const TestPartResultCollection& collection, int rank) {
229
245
for (std::size_t i = 0 ; i < collection.Size (); ++i) {
230
246
std::string m =
231
- (::testing::Message () << " Rank " << rank << " : "
232
- << ::testing::internal::FormatFileLocation (
233
- collection.file_names .get_str (i), collection.line_numbers [i])
234
- << " "
235
- << TestPartResultTypeToString (
236
- ::testing::TestPartResult::Type (collection.types[i]))
237
- << collection.messages.get_str(i))
247
+ (::testing::Message ()
248
+ << " Rank " << rank << " : "
249
+ << FormatFileLocation (collection.file_names .get_str (i), collection.line_numbers [i]) << " "
250
+ << TestPartResultTypeToString (::testing::TestPartResult::Type (collection.types [i]))
251
+ << collection.messages .get_str (i))
238
252
.GetString ();
239
253
printf (" %s\n " , m.c_str ());
240
254
fflush (stdout);
@@ -244,7 +258,6 @@ void PrintFailedTestResultCollection(const TestPartResultCollection& collection,
244
258
// Taken / modified from Googletest
245
259
void PrettyMPIUnitTestResultPrinter::OnTestEnd (const ::testing::TestInfo& test_info) {
246
260
using namespace ::testing;
247
- using namespace ::testing::internal;
248
261
249
262
// check if any ranks failed
250
263
int failed_locally = failed_results_.Size () > 0 ;
@@ -308,7 +321,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestEnd(const ::testing::TestInfo& test_i
308
321
if (failed_globally) PrintFullTestCommentIfPresent (test_info);
309
322
310
323
if (GTEST_FLAG (print_time)) {
311
- printf (" (%s ms)\n " , internal::StreamableToString (test_info.result ()->elapsed_time ()).c_str ());
324
+ printf (" (%s ms)\n " , std::to_string (test_info.result ()->elapsed_time ()).c_str ());
312
325
} else {
313
326
printf (" \n " );
314
327
}
@@ -323,7 +336,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestCaseEnd(const ::testing::TestCase& te
323
336
const std::string counts = FormatCountableNoun (test_case.test_to_run_count (), " test" , " tests" );
324
337
ColoredPrintf (COLOR_GREEN, " [----------] " );
325
338
printf (" %s from %s (%s ms total)\n\n " , counts.c_str (), test_case.name (),
326
- internal::StreamableToString (test_case.elapsed_time ()).c_str ());
339
+ std::to_string (test_case.elapsed_time ()).c_str ());
327
340
fflush (stdout);
328
341
}
329
342
@@ -368,7 +381,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestIterationEnd(const ::testing::UnitTes
368
381
printf (" %s from %s ran on %d ranks." , FormatTestCount (unit_test.test_to_run_count ()).c_str (),
369
382
FormatTestCaseCount (unit_test.test_case_to_run_count ()).c_str (), comm_size_);
370
383
if (GTEST_FLAG (print_time)) {
371
- printf (" (%s ms total)" , internal::StreamableToString (unit_test.elapsed_time ()).c_str ());
384
+ printf (" (%s ms total)" , std::to_string (unit_test.elapsed_time ()).c_str ());
372
385
}
373
386
printf (" \n " );
374
387
ColoredPrintf (COLOR_GREEN, " [ PASSED ] " );
@@ -412,4 +425,3 @@ void PrettyMPIUnitTestResultPrinter::OnEnvironmentsTearDownStart(
412
425
} // namespace gtest_mpi
413
426
414
427
#endif
415
-
0 commit comments