mirror of
https://github.com/google/googletest.git
synced 2026-06-15 08:26:11 +08:00
Merge a6d3656c49a74af4ea1794ebd0d6d62387be2b8a into 7140cd416cecd7462a8aae488024abeee55598e4
This commit is contained in:
commit
4a81acf9c5
@ -6002,6 +6002,8 @@ bool UnitTestImpl::RunAllTests() {
|
||||
const bool has_tests_to_run =
|
||||
FilterTests(should_shard ? HONOR_SHARDING_PROTOCOL
|
||||
: 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.
|
||||
if (GTEST_FLAG_GET(list_tests)) {
|
||||
@ -6056,8 +6058,11 @@ bool UnitTestImpl::RunAllTests() {
|
||||
// Tells the unit test event listeners that the tests are about to start.
|
||||
repeater->OnTestIterationStart(*parent_, i);
|
||||
|
||||
// Runs each test suite if there is at least one test to run.
|
||||
if (has_tests_to_run) {
|
||||
// Sets up and tears down environments if there is at least one test 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
|
||||
// recreated for each iteration, only do so on the first iteration.
|
||||
if (i == 0 || recreate_environments_when_repeating) {
|
||||
|
||||
@ -86,6 +86,8 @@ class MyEnvironment : public testing::Environment {
|
||||
// was run.
|
||||
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.
|
||||
void Check(bool condition, const char* msg) {
|
||||
if (!condition) {
|
||||
@ -172,6 +174,21 @@ void TestNoTestsSkipsSetUp() {
|
||||
"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
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@ -181,6 +198,7 @@ int main(int argc, char** argv) {
|
||||
TestTestsRun();
|
||||
TestNoTestsRunSetUpFailure();
|
||||
TestNoTestsSkipsSetUp();
|
||||
TestDisabledTestsRunEnvironmentTearDown();
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user