Merge a6d3656c49a74af4ea1794ebd0d6d62387be2b8a into a0f06a70e3da7afa88da9527c43951bca1f7cef2

This commit is contained in:
Kirtikumar Anandrao Ramchandani 2026-07-29 15:06:03 -04:00 committed by GitHub
commit d21bca2e90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View File

@ -6004,6 +6004,8 @@ bool UnitTestImpl::RunAllTests() {
const bool has_tests_to_run = const bool has_tests_to_run =
FilterTests(should_shard ? HONOR_SHARDING_PROTOCOL FilterTests(should_shard ? HONOR_SHARDING_PROTOCOL
: IGNORE_SHARDING_PROTOCOL) > 0; : IGNORE_SHARDING_PROTOCOL) > 0;
const bool has_tests_selected =
has_tests_to_run || reportable_disabled_test_count() > 0;
// Lists the tests and exits if the --gtest_list_tests flag was specified. // Lists the tests and exits if the --gtest_list_tests flag was specified.
if (GTEST_FLAG_GET(list_tests)) { if (GTEST_FLAG_GET(list_tests)) {
@ -6058,8 +6060,11 @@ bool UnitTestImpl::RunAllTests() {
// Tells the unit test event listeners that the tests are about to start. // Tells the unit test event listeners that the tests are about to start.
repeater->OnTestIterationStart(*parent_, i); repeater->OnTestIterationStart(*parent_, i);
// Runs each test suite if there is at least one test to run. // Sets up and tears down environments if there is at least one test to run,
if (has_tests_to_run) { // or if the selected tests are all disabled. The disabled tests still do
// not run, but global tear-down can clean resources created before
// RUN_ALL_TESTS().
if (has_tests_selected) {
// Sets up all environments beforehand. If test environments aren't // Sets up all environments beforehand. If test environments aren't
// recreated for each iteration, only do so on the first iteration. // recreated for each iteration, only do so on the first iteration.
if (i == 0 || recreate_environments_when_repeating) { if (i == 0 || recreate_environments_when_repeating) {

View File

@ -86,6 +86,8 @@ class MyEnvironment : public testing::Environment {
// was run. // was run.
TEST(FooTest, Bar) { test_was_run = true; } TEST(FooTest, Bar) { test_was_run = true; }
TEST(FooTest, DISABLED_Baz) { test_was_run = true; }
// Prints the message and aborts the program if condition is false. // Prints the message and aborts the program if condition is false.
void Check(bool condition, const char* msg) { void Check(bool condition, const char* msg) {
if (!condition) { if (!condition) {
@ -172,6 +174,21 @@ void TestNoTestsSkipsSetUp() {
"as the global set-up was not run."); "as the global set-up was not run.");
} }
// Verifies that RUN_ALL_TESTS() still runs environment tear-down when the
// selected tests are disabled.
void TestDisabledTestsRunEnvironmentTearDown() {
MyEnvironment* const env = RegisterTestEnv();
GTEST_FLAG_SET(filter, "FooTest.DISABLED_Baz");
Check(RunAllTests(env, NO_FAILURE) != 0,
"RUN_ALL_TESTS() should return non-zero, as the global tear-down "
"should generate a failure.");
Check(!test_was_run, "The disabled test body should not run.");
Check(set_up_was_run,
"The global set-up should run, as a disabled test was selected.");
Check(tear_down_was_run,
"The global tear-down should run, as the global set-up was run.");
}
} // namespace } // namespace
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -181,6 +198,7 @@ int main(int argc, char** argv) {
TestTestsRun(); TestTestsRun();
TestNoTestsRunSetUpFailure(); TestNoTestsRunSetUpFailure();
TestNoTestsSkipsSetUp(); TestNoTestsSkipsSetUp();
TestDisabledTestsRunEnvironmentTearDown();
printf("PASS\n"); printf("PASS\n");
return 0; return 0;