32 """Tests the --help flag of Google C++ Testing and Mocking Framework.
35 gtest_help_test.py --build_dir=BUILD/DIR
36 # where BUILD/DIR contains the built gtest_help_test_ file.
42 from googletest.test
import gtest_test_utils
45 IS_LINUX = os.name ==
'posix' and os.uname()[0] ==
'Linux'
46 IS_GNUHURD = os.name ==
'posix' and os.uname()[0] ==
'GNU'
47 IS_GNUKFREEBSD = os.name ==
'posix' and os.uname()[0] ==
'GNU/kFreeBSD'
48 IS_OPENBSD = os.name ==
'posix' and os.uname()[0] ==
'OpenBSD'
49 IS_WINDOWS = os.name ==
'nt'
52 FLAG_PREFIX =
'--gtest_'
53 DEATH_TEST_STYLE_FLAG = FLAG_PREFIX +
'death_test_style'
54 STREAM_RESULT_TO_FLAG = FLAG_PREFIX +
'stream_result_to'
55 UNKNOWN_FLAG = FLAG_PREFIX +
'unknown_flag_for_testing'
56 LIST_TESTS_FLAG = FLAG_PREFIX +
'list_tests'
57 INCORRECT_FLAG_VARIANTS = [re.sub(
'^--',
'-', LIST_TESTS_FLAG),
58 re.sub(
'^--',
'/', LIST_TESTS_FLAG),
59 re.sub(
'_',
'-', LIST_TESTS_FLAG)]
60 INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX +
'internal_flag_for_testing'
63 [PROGRAM_PATH, LIST_TESTS_FLAG]).output
66 HELP_REGEX = re.compile(
67 FLAG_PREFIX +
r'list_tests.*' +
68 FLAG_PREFIX +
r'filter=.*' +
69 FLAG_PREFIX +
r'also_run_disabled_tests.*' +
70 FLAG_PREFIX +
r'repeat=.*' +
71 FLAG_PREFIX +
r'shuffle.*' +
72 FLAG_PREFIX +
r'random_seed=.*' +
73 FLAG_PREFIX +
r'color=.*' +
74 FLAG_PREFIX +
r'brief.*' +
75 FLAG_PREFIX +
r'print_time.*' +
76 FLAG_PREFIX +
r'output=.*' +
77 FLAG_PREFIX +
r'break_on_failure.*' +
78 FLAG_PREFIX +
r'throw_on_failure.*' +
79 FLAG_PREFIX +
r'catch_exceptions=0.*',
84 """Runs gtest_help_test_ with the given flag.
87 the exit code and the text output as a tuple.
89 flag: the command-line flag to pass to gtest_help_test_, or None.
93 command = [PROGRAM_PATH]
95 command = [PROGRAM_PATH, flag]
97 return child.exit_code, child.output
101 """Tests the --help flag and its equivalent forms."""
104 """Verifies correct behavior when help flag is specified.
106 The right message must be printed and the tests must
107 skipped when the given flag is specified.
110 flag: A flag to pass to the binary or None.
114 self.assertEquals(0, exit_code)
115 self.assert_(HELP_REGEX.search(output), output)
117 if IS_LINUX
or IS_GNUHURD
or IS_GNUKFREEBSD
or IS_OPENBSD:
118 self.assert_(STREAM_RESULT_TO_FLAG
in output, output)
120 self.assert_(STREAM_RESULT_TO_FLAG
not in output, output)
122 if SUPPORTS_DEATH_TESTS
and not IS_WINDOWS:
123 self.assert_(DEATH_TEST_STYLE_FLAG
in output, output)
125 self.assert_(DEATH_TEST_STYLE_FLAG
not in output, output)
128 """Verifies correct behavior when no help flag is specified.
130 Verifies that when no help flag is specified, the tests are run
131 and the help message is not printed.
134 flag: A flag to pass to the binary or None.
138 self.assert_(exit_code != 0)
139 self.assert_(
not HELP_REGEX.search(output), output)
157 for incorrect_flag
in INCORRECT_FLAG_VARIANTS:
161 """Verifies that when no help flag is specified, the tests are run
162 and the help message is not printed."""
167 """Verifies that the tests are run and no help message is printed when
168 a flag starting with Google Test prefix and 'internal_' is supplied."""
173 if __name__ ==
'__main__':