From 5d6f38c1e2bc5e462e7bbb743903479ee2c54f7e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 22 Mar 2022 09:07:20 -0700 Subject: [PATCH] Only print disabled test banner if the test matches gtest_filter Currently, the "[ DISABLED ]" banner is printed for every test in a suite. When iterating on a single test gtest_filter this is very noisy. PiperOrigin-RevId: 436489088 Change-Id: If337087a7a0986b073fabf2b0a55d26485eb5c37 --- googletest/src/gtest.cc | 2 +- googletest/test/googletest-filter-unittest.py | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index e422e928..10cff8e8 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2821,7 +2821,7 @@ void UnitTestImpl::RegisterParameterizedTests() { void TestInfo::Run() { TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); if (!should_run_) { - if (is_disabled_) repeater->OnTestDisabled(*this); + if (is_disabled_ && matches_filter_) repeater->OnTestDisabled(*this); return; } diff --git a/googletest/test/googletest-filter-unittest.py b/googletest/test/googletest-filter-unittest.py index bd1d5a5d..2c4a1b18 100755 --- a/googletest/test/googletest-filter-unittest.py +++ b/googletest/test/googletest-filter-unittest.py @@ -113,6 +113,9 @@ TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)') # Regex for parsing test names from Google Test's output. TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)') +# Regex for parsing disabled banner from Google Test's output +DISABLED_BANNER_REGEX = re.compile(r'^\[\s*DISABLED\s*\] (.*)') + # The command line flag to tell Google Test to output the list of tests it # will run. LIST_TESTS_FLAG = '--gtest_list_tests' @@ -206,6 +209,17 @@ def RunAndExtractTestList(args = None): return (tests_run, p.exit_code) +def RunAndExtractDisabledBannerList(args=None): + """Runs the test program and returns tests that printed a disabled banner.""" + p = gtest_test_utils.Subprocess([COMMAND] + (args or []), env=environ) + banners_printed = [] + for line in p.output.split('\n'): + match = DISABLED_BANNER_REGEX.match(line) + if match is not None: + banners_printed.append(match.group(1)) + return banners_printed + + def InvokeWithModifiedEnv(extra_env, function, *args, **kwargs): """Runs the given function and arguments in a modified environment.""" try: @@ -613,6 +627,23 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase): self.assert_(os.path.exists(shard_status_file)) os.remove(shard_status_file) + def testDisabledBanner(self): + """Tests that the disabled banner prints only tests that match filter.""" + make_filter = lambda s: ['--%s=%s' % (FILTER_FLAG, s)] + + banners = RunAndExtractDisabledBannerList(make_filter('*')) + self.AssertSetEqual(banners, [ + 'BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive', + 'BazTest.DISABLED_TestC' + ]) + + banners = RunAndExtractDisabledBannerList(make_filter('Bar*')) + self.AssertSetEqual( + banners, ['BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive']) + + banners = RunAndExtractDisabledBannerList(make_filter('*-Bar*')) + self.AssertSetEqual(banners, ['BazTest.DISABLED_TestC']) + if SUPPORTS_DEATH_TESTS: def testShardingWorksWithDeathTests(self): """Tests integration with death tests and sharding."""