gtest_help_test: Inline test helper functions
`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
This commit is contained in:
parent
fc234d6d18
commit
6513d0272d
@ -116,17 +116,14 @@ def RunWithFlag(flag):
|
|||||||
class GTestHelpTest(gtest_test_utils.TestCase):
|
class GTestHelpTest(gtest_test_utils.TestCase):
|
||||||
"""Tests the --help flag and its equivalent forms."""
|
"""Tests the --help flag and its equivalent forms."""
|
||||||
|
|
||||||
def TestHelpFlag(self, flag):
|
def testPrintsHelpWithFullFlag(self):
|
||||||
"""Verifies correct behavior when help flag is specified.
|
"""Verifies correct behavior when help flag is specified.
|
||||||
|
|
||||||
The right message must be printed and the tests must
|
The right message must be printed and the tests must
|
||||||
skipped when the given flag is specified.
|
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:
|
if HAS_ABSL_FLAGS:
|
||||||
# The Abseil flags library prints the ProgramUsageMessage() with
|
# The Abseil flags library prints the ProgramUsageMessage() with
|
||||||
# --help and returns 1.
|
# --help and returns 1.
|
||||||
@ -146,23 +143,6 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertNotIn(DEATH_TEST_STYLE_FLAG, output)
|
self.assertNotIn(DEATH_TEST_STYLE_FLAG, output)
|
||||||
|
|
||||||
def TestNonHelpFlag(self, flag):
|
|
||||||
"""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)
|
|
||||||
self.assertNotEqual(exit_code, 0)
|
|
||||||
self.assertFalse(HELP_REGEX.search(output), output)
|
|
||||||
|
|
||||||
def testPrintsHelpWithFullFlag(self):
|
|
||||||
self.TestHelpFlag('--help')
|
|
||||||
|
|
||||||
def testRunsTestsWithoutHelpFlag(self):
|
def testRunsTestsWithoutHelpFlag(self):
|
||||||
"""Verifies correct behavior when no help flag is specified.
|
"""Verifies correct behavior when no help flag is specified.
|
||||||
|
|
||||||
@ -170,7 +150,9 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
|||||||
and the help message is not printed.
|
and the help message is not printed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.TestNonHelpFlag(None)
|
exit_code, output = RunWithFlag(None)
|
||||||
|
self.assertNotEqual(exit_code, 0)
|
||||||
|
self.assertFalse(HELP_REGEX.search(output), output)
|
||||||
|
|
||||||
def testRunsTestsWithGtestInternalFlag(self):
|
def testRunsTestsWithGtestInternalFlag(self):
|
||||||
"""Verifies correct behavior when internal testing flag is specified.
|
"""Verifies correct behavior when internal testing flag is specified.
|
||||||
@ -179,7 +161,9 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
|||||||
a flag starting with Google Test prefix and 'internal_' is supplied.
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user