@@ -6113,6 +6113,17 @@ bool UnitTestImpl::RunAllTests() {
6113
6113
environments_.clear ();
6114
6114
}
6115
6115
6116
+ // Try to warn the user if no tests matched the test filter.
6117
+ if (ShouldWarnIfNoTestsMatchFilter ()) {
6118
+ const std::string filter_warning =
6119
+ std::string (" filter \" " ) + GTEST_FLAG_GET (filter) +
6120
+ " \" did not match any test; no tests were run\n " ;
6121
+ ColoredPrintf (GTestColor::kRed , " WARNING: %s" , filter_warning.c_str ());
6122
+ #if GTEST_HAS_FILE_SYSTEM
6123
+ AppendToTestWarningsOutputFile (filter_warning);
6124
+ #endif // GTEST_HAS_FILE_SYSTEM
6125
+ }
6126
+
6116
6127
if (!gtest_is_initialized_before_run_all_tests) {
6117
6128
ColoredPrintf (
6118
6129
GTestColor::kRed ,
@@ -6281,6 +6292,30 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
6281
6292
return num_selected_tests;
6282
6293
}
6283
6294
6295
+ // Returns true if a warning should be issued if no tests match the test filter
6296
+ // flag. We can't simply count the number of tests that ran because, for
6297
+ // instance, test sharding and death tests might mean no tests are expected to
6298
+ // run in this process, but will run in another process.
6299
+ bool UnitTestImpl::ShouldWarnIfNoTestsMatchFilter () const {
6300
+ if (total_test_count () == 0 ) {
6301
+ // No tests were linked in to program.
6302
+ // This case is handled by a different warning.
6303
+ return false ;
6304
+ }
6305
+ const PositiveAndNegativeUnitTestFilter gtest_flag_filter (
6306
+ GTEST_FLAG_GET (filter));
6307
+ for (auto * test_suite : test_suites_) {
6308
+ const std::string& test_suite_name = test_suite->name_ ;
6309
+ for (TestInfo* test_info : test_suite->test_info_list ()) {
6310
+ const std::string& test_name = test_info->name_ ;
6311
+ if (gtest_flag_filter.MatchesTest (test_suite_name, test_name)) {
6312
+ return false ;
6313
+ }
6314
+ }
6315
+ }
6316
+ return true ;
6317
+ }
6318
+
6284
6319
// Prints the given C-string on a single line by replacing all '\n'
6285
6320
// characters with string "\\n". If the output takes more than
6286
6321
// max_length characters, only prints the first max_length characters
0 commit comments