Skip to content

Commit

Permalink
gtest_help_test: Inline test helper functions
Browse files Browse the repository at this point in the history
`TestNonHelpFlag` is only a few asserts with no logic, which is easier to read in line, and helper `TestHelpFlag` is used in a single test case.

PiperOrigin-RevId: 557122793
Change-Id: I7367424abfbb883c10c260fae066a2071e5dfa0e
  • Loading branch information
dinord authored and copybara-github committed Aug 15, 2023
1 parent fc234d6 commit 6513d02
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions googletest/test/gtest_help_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,14 @@ def RunWithFlag(flag):
class GTestHelpTest(gtest_test_utils.TestCase):
"""Tests the --help flag and its equivalent forms."""

def TestHelpFlag(self, flag):
def testPrintsHelpWithFullFlag(self):
"""Verifies correct behavior when help flag is specified.
The right message must be printed and the tests must
skipped when the given flag is specified.
Args:
flag: A flag to pass to the binary or None.
"""

exit_code, output = RunWithFlag(flag)
exit_code, output = RunWithFlag('--help')
if HAS_ABSL_FLAGS:
# The Abseil flags library prints the ProgramUsageMessage() with
# --help and returns 1.
Expand All @@ -146,40 +143,27 @@ def TestHelpFlag(self, flag):
else:
self.assertNotIn(DEATH_TEST_STYLE_FLAG, output)

def TestNonHelpFlag(self, flag):
def testRunsTestsWithoutHelpFlag(self):
"""Verifies correct behavior when no help flag is specified.
Verifies that when no help flag is specified, the tests are run
and the help message is not printed.
Args:
flag: A flag to pass to the binary or None.
"""

exit_code, output = RunWithFlag(flag)
exit_code, output = RunWithFlag(None)
self.assertNotEqual(exit_code, 0)
self.assertFalse(HELP_REGEX.search(output), output)

def testPrintsHelpWithFullFlag(self):
self.TestHelpFlag('--help')

def testRunsTestsWithoutHelpFlag(self):
"""Verifies correct behavior when no help flag is specified.
Verifies that when no help flag is specified, the tests are run
and the help message is not printed.
"""

self.TestNonHelpFlag(None)

def testRunsTestsWithGtestInternalFlag(self):
"""Verifies correct behavior when internal testing flag is specified.
Verifies that the tests are run and no help message is printed when
a flag starting with Google Test prefix and 'internal_' is supplied.
"""

self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING)
exit_code, output = RunWithFlag(INTERNAL_FLAG_FOR_TESTING)
self.assertNotEqual(exit_code, 0)
self.assertFalse(HELP_REGEX.search(output), output)


if __name__ == '__main__':
Expand Down

0 comments on commit 6513d02

Please sign in to comment.