gtest_fail_if_no_test_selected: Rephrase error message.

Sharded tests interact awkwardly with --gtest_fail_if_no_test_selected, but we
can't speak clearly enough to the use cases to complicate the mental model, so
instead we attempt to clarify the simplest approach to debugging a single test
when sharding and --gtest_fail_if_no_test_selected are both in use: unset the
flag.

PiperOrigin-RevId: 829686145
Change-Id: I9ebbddc6e7537feefe2a3707fd323fc9132b99d1
This commit is contained in:
Abseil Team 2025-11-07 20:49:55 -08:00 committed by Copybara-Service
parent dedab73a68
commit 37678c92fb

View File

@ -6088,17 +6088,15 @@ bool UnitTestImpl::RunAllTests() {
repeater->OnEnvironmentsTearDownEnd(*parent_); repeater->OnEnvironmentsTearDownEnd(*parent_);
} }
} else if (GTEST_FLAG_GET(fail_if_no_test_selected)) { } else if (GTEST_FLAG_GET(fail_if_no_test_selected)) {
// If there were no tests to run, bail if we were requested to be // If there were no tests to run, bail if we were requested to be strict.
// strict.
constexpr char kNoTestsSelectedMessage[] = constexpr char kNoTestsSelectedMessage[] =
"No tests ran. Check that tests exist and are not disabled or " "No tests were selected to run. Please make sure at least one test "
"filtered out.\n\n" "exists and is not disabled! If the test is sharded, you may have "
"For sharded runs, this error indicates an empty shard. This can " "defined more shards than test cases, which is wasteful. If you also "
"happen if you have more shards than tests, or if --gtest_filter " "defined --gtest_filter, that filter is taken into account, so "
"leaves a shard with no tests.\n\n" "shards with no matching test cases will hit this error. Either "
"To permit empty shards (e.g., when debugging with a filter), " "disable sharding, set --gtest_fail_if_no_test_selected=false, or "
"specify \n" "remove the filter to resolve this error.";
"--gtest_fail_if_no_test_selected=false.";
ColoredPrintf(GTestColor::kRed, "%s\n", kNoTestsSelectedMessage); ColoredPrintf(GTestColor::kRed, "%s\n", kNoTestsSelectedMessage);
return false; return false;
} }