@@ -269,6 +269,13 @@ GTEST_DEFINE_bool_(
269
269
"True if and only if the test should fail if no test case (including "
270
270
" disabled test cases) is linked.");
271
271
272
+ GTEST_DEFINE_bool_ (
273
+ fail_if_no_test_selected,
274
+ testing::internal::BoolFromGTestEnv (" fail_if_no_test_selected" , false ),
275
+ "True if and only if the test should fail if no test case is selected to "
276
+ "run. A test case is selected to run if it is not disabled and is matched "
277
+ "by the filter flag so that it starts executing.");
278
+
272
279
GTEST_DEFINE_bool_ (
273
280
also_run_disabled_tests,
274
281
testing::internal::BoolFromGTestEnv (" also_run_disabled_tests" , false ),
@@ -6079,6 +6086,14 @@ bool UnitTestImpl::RunAllTests() {
6079
6086
TearDownEnvironment);
6080
6087
repeater->OnEnvironmentsTearDownEnd (*parent_);
6081
6088
}
6089
+ } else if (GTEST_FLAG_GET (fail_if_no_test_selected)) {
6090
+ // If there were no tests to run, bail if we were requested to be strict.
6091
+ constexpr char kNoTestsSelectedMessage [] =
6092
+ " No tests were selected to run. Please make sure at least one test "
6093
+ " exists and is not disabled! If the test is sharded, you may have "
6094
+ " defined more shards than test cases, which is wasteful." ;
6095
+ ColoredPrintf (GTestColor::kRed , " %s\n " , kNoTestsSelectedMessage );
6096
+ return false ;
6082
6097
}
6083
6098
6084
6099
elapsed_time_ = timer.Elapsed ();
@@ -6763,6 +6778,7 @@ static bool ParseGoogleTestFlag(const char* const arg) {
6763
6778
GTEST_INTERNAL_PARSE_FLAG (death_test_use_fork);
6764
6779
GTEST_INTERNAL_PARSE_FLAG (fail_fast);
6765
6780
GTEST_INTERNAL_PARSE_FLAG (fail_if_no_test_linked);
6781
+ GTEST_INTERNAL_PARSE_FLAG (fail_if_no_test_selected);
6766
6782
GTEST_INTERNAL_PARSE_FLAG (filter);
6767
6783
GTEST_INTERNAL_PARSE_FLAG (internal_run_death_test);
6768
6784
GTEST_INTERNAL_PARSE_FLAG (list_tests);
0 commit comments