3
# Copyright 2006, Google Inc.
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are
10
# * Redistributions of source code must retain the above copyright
11
# notice, this list of conditions and the following disclaimer.
12
# * Redistributions in binary form must reproduce the above
13
# copyright notice, this list of conditions and the following disclaimer
14
# in the documentation and/or other materials provided with the
16
# * Neither the name of Google Inc. nor the names of its
17
# contributors may be used to endorse or promote products derived from
18
# this software without specific prior written permission.
20
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
"""Unit test for Google Test's --gtest_list_tests flag.
34
A user can ask Google Test to list all tests by specifying the
35
--gtest_list_tests flag. This script tests such functionality
36
by invoking gtest_list_tests_unittest_ (a program written with
37
Google Test) the command line flags.
40
__author__ = 'phanna@google.com (Patrick Hanna)'
42
import gtest_test_utils
47
# The command line flag for enabling/disabling listing all tests.
48
LIST_TESTS_FLAG = 'gtest_list_tests'
50
# Path to the gtest_list_tests_unittest_ program.
51
EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_list_tests_unittest_')
53
# The expected output when running gtest_list_tests_unittest_ with
55
EXPECTED_OUTPUT_NO_FILTER = """FooDeathTest.
72
# The expected output when running gtest_list_tests_unittest_ with
73
# --gtest_list_tests and --gtest_filter=Foo*.
74
EXPECTED_OUTPUT_FILTER_FOO = """FooDeathTest.
92
"""Runs gtest_list_tests_unittest_ and returns the list of tests printed."""
94
return gtest_test_utils.Subprocess([EXE_PATH] + args,
95
capture_stderr=False).output
100
class GTestListTestsUnitTest(gtest_test_utils.TestCase):
101
"""Tests using the --gtest_list_tests flag to list all tests."""
103
def RunAndVerify(self, flag_value, expected_output, other_flag):
104
"""Runs gtest_list_tests_unittest_ and verifies that it prints
108
flag_value: value of the --gtest_list_tests flag;
109
None if the flag should not be present.
111
expected_output: the expected output after running command;
113
other_flag: a different flag to be passed to command
114
along with gtest_list_tests;
115
None if the flag should not be present.
118
if flag_value is None:
120
flag_expression = 'not set'
121
elif flag_value == '0':
122
flag = '--%s=0' % LIST_TESTS_FLAG
123
flag_expression = '0'
125
flag = '--%s' % LIST_TESTS_FLAG
126
flag_expression = '1'
130
if other_flag is not None:
135
msg = ('when %s is %s, the output of "%s" is "%s".' %
136
(LIST_TESTS_FLAG, flag_expression, ' '.join(args), output))
138
if expected_output is not None:
139
self.assert_(output == expected_output, msg)
141
self.assert_(output != EXPECTED_OUTPUT_NO_FILTER, msg)
143
def testDefaultBehavior(self):
144
"""Tests the behavior of the default mode."""
146
self.RunAndVerify(flag_value=None,
147
expected_output=None,
151
"""Tests using the --gtest_list_tests flag."""
153
self.RunAndVerify(flag_value='0',
154
expected_output=None,
156
self.RunAndVerify(flag_value='1',
157
expected_output=EXPECTED_OUTPUT_NO_FILTER,
160
def testOverrideNonFilterFlags(self):
161
"""Tests that --gtest_list_tests overrides the non-filter flags."""
163
self.RunAndVerify(flag_value='1',
164
expected_output=EXPECTED_OUTPUT_NO_FILTER,
165
other_flag='--gtest_break_on_failure')
167
def testWithFilterFlags(self):
168
"""Tests that --gtest_list_tests takes into account the
169
--gtest_filter flag."""
171
self.RunAndVerify(flag_value='1',
172
expected_output=EXPECTED_OUTPUT_FILTER_FOO,
173
other_flag='--gtest_filter=Foo*')
176
if __name__ == '__main__':
177
gtest_test_utils.Main()