32"""Tests the --help flag of Google C++ Testing and Mocking Framework.
35 gtest_help_test.py --build_dir=BUILD/DIR
42import gtest_test_utils
45IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
46IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
47IS_WINDOWS = os.name == 'nt'
49PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')
50FLAG_PREFIX = '--gtest_'
51DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style'
52STREAM_RESULT_TO_FLAG = FLAG_PREFIX + 'stream_result_to'
53UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing'
54LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
55INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG),
56 re.sub('^--',
'/', LIST_TESTS_FLAG),
57 re.sub(
'_',
'-', LIST_TESTS_FLAG)]
58INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX +
'internal_flag_for_testing'
61 [PROGRAM_PATH, LIST_TESTS_FLAG]).output
64HELP_REGEX = re.compile(
65 FLAG_PREFIX +
r'list_tests.*' +
66 FLAG_PREFIX +
r'filter=.*' +
67 FLAG_PREFIX +
r'also_run_disabled_tests.*' +
68 FLAG_PREFIX +
r'repeat=.*' +
69 FLAG_PREFIX +
r'shuffle.*' +
70 FLAG_PREFIX +
r'random_seed=.*' +
71 FLAG_PREFIX +
r'color=.*' +
72 FLAG_PREFIX +
r'brief.*' +
73 FLAG_PREFIX +
r'print_time.*' +
74 FLAG_PREFIX +
r'output=.*' +
75 FLAG_PREFIX +
r'break_on_failure.*' +
76 FLAG_PREFIX +
r'throw_on_failure.*' +
77 FLAG_PREFIX +
r'catch_exceptions=0.*',
82 """Runs gtest_help_test_ with the given flag.
85 the exit code and the text output
as a tuple.
87 flag: the command-line flag to
pass to gtest_help_test_,
or None.
91 command = [PROGRAM_PATH]
93 command = [PROGRAM_PATH, flag]
95 return child.exit_code, child.output
99 """Tests the --help flag and its equivalent forms."""
102 """Verifies correct behavior when help flag is specified.
104 The right message must be printed and the tests must
105 skipped when the given flag
is specified.
108 flag: A flag to
pass to the binary
or None.
112 self.assertEquals(0, exit_code)
113 self.assert_(HELP_REGEX.search(output), output)
115 if IS_LINUX
or IS_GNUKFREEBSD:
116 self.assert_(STREAM_RESULT_TO_FLAG
in output, output)
118 self.assert_(STREAM_RESULT_TO_FLAG
not in output, output)
120 if SUPPORTS_DEATH_TESTS
and not IS_WINDOWS:
121 self.assert_(DEATH_TEST_STYLE_FLAG
in output, output)
123 self.assert_(DEATH_TEST_STYLE_FLAG
not in output, output)
126 """Verifies correct behavior when no help flag is specified.
128 Verifies that when no help flag is specified, the tests are run
129 and the help message
is not printed.
132 flag: A flag to
pass to the binary
or None.
136 self.assert_(exit_code != 0)
137 self.assert_(not HELP_REGEX.search(output), output)
155 for incorrect_flag
in INCORRECT_FLAG_VARIANTS:
159 """Verifies that when no help flag is specified, the tests are run
160 and the help message
is not printed.
"""
165 """Verifies that the tests are run and no help message is printed when
166 a flag starting with Google Test prefix
and 'internal_' is supplied.
"""
171if __name__ ==
'__main__':
def TestNonHelpFlag(self, flag)
def testRunsTestsWithGtestInternalFlag(self)
def TestHelpFlag(self, flag)
def testPrintsHelpWithShortFlag(self)
def testPrintsHelpWithUnrecognizedGoogleTestFlag(self)
def testPrintsHelpWithWindowsStyleQuestionFlag(self)
def testPrintsHelpWithQuestionFlag(self)
def testPrintsHelpWithIncorrectFlagStyle(self)
def testPrintsHelpWithFullFlag(self)
def testRunsTestsWithoutHelpFlag(self)