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
This commit is contained in:
Abseil Team 2022-03-22 09:07:20 -07:00 committed by Copybara-Service
parent 1754febbaa
commit 5d6f38c1e2
2 changed files with 32 additions and 1 deletions

View File

@ -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;
}

View File

@ -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."""