[Gtest][Fixed build issues for the build failures of dependent modules]
[platform/upstream/gtest.git] / googletest / test / googletest-filter-unittest.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2005 Google Inc. All Rights Reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 #     * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 #     * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 #     * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 """Unit test for Google Test test filters.
32
33 A user can specify which test(s) in a Google Test program to run via either
34 the GTEST_FILTER environment variable or the --gtest_filter flag.
35 This script tests such functionality by invoking
36 googletest-filter-unittest_ (a program written with Google Test) with different
37 environments and command line flags.
38
39 Note that test sharding may also influence which tests are filtered. Therefore,
40 we test that here also.
41 """
42
43 import os
44 import re
45 try:
46   from sets import Set as set  # For Python 2.3 compatibility
47 except ImportError:
48   pass
49 import sys
50 import gtest_test_utils
51
52 # Constants.
53
54 # Checks if this platform can pass empty environment variables to child
55 # processes.  We set an env variable to an empty string and invoke a python
56 # script in a subprocess to print whether the variable is STILL in
57 # os.environ.  We then use 'eval' to parse the child's output so that an
58 # exception is thrown if the input is anything other than 'True' nor 'False'.
59 CAN_PASS_EMPTY_ENV = False
60 if sys.executable:
61   os.environ['EMPTY_VAR'] = ''
62   child = gtest_test_utils.Subprocess(
63       [sys.executable, '-c', 'import os; print(\'EMPTY_VAR\' in os.environ)'])
64   CAN_PASS_EMPTY_ENV = eval(child.output)
65
66
67 # Check if this platform can unset environment variables in child processes.
68 # We set an env variable to a non-empty string, unset it, and invoke
69 # a python script in a subprocess to print whether the variable
70 # is NO LONGER in os.environ.
71 # We use 'eval' to parse the child's output so that an exception
72 # is thrown if the input is neither 'True' nor 'False'.
73 CAN_UNSET_ENV = False
74 if sys.executable:
75   os.environ['UNSET_VAR'] = 'X'
76   del os.environ['UNSET_VAR']
77   child = gtest_test_utils.Subprocess(
78       [sys.executable, '-c', 'import os; print(\'UNSET_VAR\' not in os.environ)'
79       ])
80   CAN_UNSET_ENV = eval(child.output)
81
82
83 # Checks if we should test with an empty filter. This doesn't
84 # make sense on platforms that cannot pass empty env variables (Win32)
85 # and on platforms that cannot unset variables (since we cannot tell
86 # the difference between "" and NULL -- Borland and Solaris < 5.10)
87 CAN_TEST_EMPTY_FILTER = (CAN_PASS_EMPTY_ENV and CAN_UNSET_ENV)
88
89
90 # The environment variable for specifying the test filters.
91 FILTER_ENV_VAR = 'GTEST_FILTER'
92
93 # The environment variables for test sharding.
94 TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
95 SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'
96 SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
97
98 # The command line flag for specifying the test filters.
99 FILTER_FLAG = 'gtest_filter'
100
101 # The command line flag for including disabled tests.
102 ALSO_RUN_DISABLED_TESTS_FLAG = 'gtest_also_run_disabled_tests'
103
104 # Command to run the googletest-filter-unittest_ program.
105 COMMAND = gtest_test_utils.GetTestExecutablePath('googletest-filter-unittest_')
106
107 # Regex for determining whether parameterized tests are enabled in the binary.
108 PARAM_TEST_REGEX = re.compile(r'/ParamTest')
109
110 # Regex for parsing test case names from Google Test's output.
111 TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)')
112
113 # Regex for parsing test names from Google Test's output.
114 TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)')
115
116 # The command line flag to tell Google Test to output the list of tests it
117 # will run.
118 LIST_TESTS_FLAG = '--gtest_list_tests'
119
120 # Indicates whether Google Test supports death tests.
121 SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
122     [COMMAND, LIST_TESTS_FLAG]).output
123
124 # Full names of all tests in googletest-filter-unittests_.
125 PARAM_TESTS = [
126     'SeqP/ParamTest.TestX/0',
127     'SeqP/ParamTest.TestX/1',
128     'SeqP/ParamTest.TestY/0',
129     'SeqP/ParamTest.TestY/1',
130     'SeqQ/ParamTest.TestX/0',
131     'SeqQ/ParamTest.TestX/1',
132     'SeqQ/ParamTest.TestY/0',
133     'SeqQ/ParamTest.TestY/1',
134     ]
135
136 DISABLED_TESTS = [
137     'BarTest.DISABLED_TestFour',
138     'BarTest.DISABLED_TestFive',
139     'BazTest.DISABLED_TestC',
140     'DISABLED_FoobarTest.Test1',
141     'DISABLED_FoobarTest.DISABLED_Test2',
142     'DISABLED_FoobarbazTest.TestA',
143     ]
144
145 if SUPPORTS_DEATH_TESTS:
146   DEATH_TESTS = [
147     'HasDeathTest.Test1',
148     'HasDeathTest.Test2',
149     ]
150 else:
151   DEATH_TESTS = []
152
153 # All the non-disabled tests.
154 ACTIVE_TESTS = [
155     'FooTest.Abc',
156     'FooTest.Xyz',
157
158     'BarTest.TestOne',
159     'BarTest.TestTwo',
160     'BarTest.TestThree',
161
162     'BazTest.TestOne',
163     'BazTest.TestA',
164     'BazTest.TestB',
165     ] + DEATH_TESTS + PARAM_TESTS
166
167 param_tests_present = None
168
169 # Utilities.
170
171 environ = os.environ.copy()
172
173
174 def SetEnvVar(env_var, value):
175   """Sets the env variable to 'value'; unsets it when 'value' is None."""
176
177   if value is not None:
178     environ[env_var] = value
179   elif env_var in environ:
180     del environ[env_var]
181
182
183 def RunAndReturnOutput(args = None):
184   """Runs the test program and returns its output."""
185
186   return gtest_test_utils.Subprocess([COMMAND] + (args or []),
187                                      env=environ).output
188
189
190 def RunAndExtractTestList(args = None):
191   """Runs the test program and returns its exit code and a list of tests run."""
192
193   p = gtest_test_utils.Subprocess([COMMAND] + (args or []), env=environ)
194   tests_run = []
195   test_case = ''
196   test = ''
197   for line in p.output.split('\n'):
198     match = TEST_CASE_REGEX.match(line)
199     if match is not None:
200       test_case = match.group(1)
201     else:
202       match = TEST_REGEX.match(line)
203       if match is not None:
204         test = match.group(1)
205         tests_run.append(test_case + '.' + test)
206   return (tests_run, p.exit_code)
207
208
209 def InvokeWithModifiedEnv(extra_env, function, *args, **kwargs):
210   """Runs the given function and arguments in a modified environment."""
211   try:
212     original_env = environ.copy()
213     environ.update(extra_env)
214     return function(*args, **kwargs)
215   finally:
216     environ.clear()
217     environ.update(original_env)
218
219
220 def RunWithSharding(total_shards, shard_index, command):
221   """Runs a test program shard and returns exit code and a list of tests run."""
222
223   extra_env = {SHARD_INDEX_ENV_VAR: str(shard_index),
224                TOTAL_SHARDS_ENV_VAR: str(total_shards)}
225   return InvokeWithModifiedEnv(extra_env, RunAndExtractTestList, command)
226
227 # The unit test.
228
229
230 class GTestFilterUnitTest(gtest_test_utils.TestCase):
231   """Tests the env variable or the command line flag to filter tests."""
232
233   # Utilities.
234
235   def AssertSetEqual(self, lhs, rhs):
236     """Asserts that two sets are equal."""
237
238     for elem in lhs:
239       self.assert_(elem in rhs, '%s in %s' % (elem, rhs))
240
241     for elem in rhs:
242       self.assert_(elem in lhs, '%s in %s' % (elem, lhs))
243
244   def AssertPartitionIsValid(self, set_var, list_of_sets):
245     """Asserts that list_of_sets is a valid partition of set_var."""
246
247     full_partition = []
248     for slice_var in list_of_sets:
249       full_partition.extend(slice_var)
250     self.assertEqual(len(set_var), len(full_partition))
251     self.assertEqual(set(set_var), set(full_partition))
252
253   def AdjustForParameterizedTests(self, tests_to_run):
254     """Adjust tests_to_run in case value parameterized tests are disabled."""
255
256     global param_tests_present
257     if not param_tests_present:
258       return list(set(tests_to_run) - set(PARAM_TESTS))
259     else:
260       return tests_to_run
261
262   def RunAndVerify(self, gtest_filter, tests_to_run):
263     """Checks that the binary runs correct set of tests for a given filter."""
264
265     tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
266
267     # First, tests using the environment variable.
268
269     # Windows removes empty variables from the environment when passing it
270     # to a new process.  This means it is impossible to pass an empty filter
271     # into a process using the environment variable.  However, we can still
272     # test the case when the variable is not supplied (i.e., gtest_filter is
273     # None).
274     # pylint: disable-msg=C6403
275     if CAN_TEST_EMPTY_FILTER or gtest_filter != '':
276       SetEnvVar(FILTER_ENV_VAR, gtest_filter)
277       tests_run = RunAndExtractTestList()[0]
278       SetEnvVar(FILTER_ENV_VAR, None)
279       self.AssertSetEqual(tests_run, tests_to_run)
280     # pylint: enable-msg=C6403
281
282     # Next, tests using the command line flag.
283
284     if gtest_filter is None:
285       args = []
286     else:
287       args = ['--%s=%s' % (FILTER_FLAG, gtest_filter)]
288
289     tests_run = RunAndExtractTestList(args)[0]
290     self.AssertSetEqual(tests_run, tests_to_run)
291
292   def RunAndVerifyWithSharding(self, gtest_filter, total_shards, tests_to_run,
293                                args=None, check_exit_0=False):
294     """Checks that binary runs correct tests for the given filter and shard.
295
296     Runs all shards of googletest-filter-unittest_ with the given filter, and
297     verifies that the right set of tests were run. The union of tests run
298     on each shard should be identical to tests_to_run, without duplicates.
299     If check_exit_0, .
300
301     Args:
302       gtest_filter: A filter to apply to the tests.
303       total_shards: A total number of shards to split test run into.
304       tests_to_run: A set of tests expected to run.
305       args   :      Arguments to pass to the to the test binary.
306       check_exit_0: When set to a true value, make sure that all shards
307                     return 0.
308     """
309
310     tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
311
312     # Windows removes empty variables from the environment when passing it
313     # to a new process.  This means it is impossible to pass an empty filter
314     # into a process using the environment variable.  However, we can still
315     # test the case when the variable is not supplied (i.e., gtest_filter is
316     # None).
317     # pylint: disable-msg=C6403
318     if CAN_TEST_EMPTY_FILTER or gtest_filter != '':
319       SetEnvVar(FILTER_ENV_VAR, gtest_filter)
320       partition = []
321       for i in range(0, total_shards):
322         (tests_run, exit_code) = RunWithSharding(total_shards, i, args)
323         if check_exit_0:
324           self.assertEqual(0, exit_code)
325         partition.append(tests_run)
326
327       self.AssertPartitionIsValid(tests_to_run, partition)
328       SetEnvVar(FILTER_ENV_VAR, None)
329     # pylint: enable-msg=C6403
330
331   def RunAndVerifyAllowingDisabled(self, gtest_filter, tests_to_run):
332     """Checks that the binary runs correct set of tests for the given filter.
333
334     Runs googletest-filter-unittest_ with the given filter, and enables
335     disabled tests. Verifies that the right set of tests were run.
336
337     Args:
338       gtest_filter: A filter to apply to the tests.
339       tests_to_run: A set of tests expected to run.
340     """
341
342     tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
343
344     # Construct the command line.
345     args = ['--%s' % ALSO_RUN_DISABLED_TESTS_FLAG]
346     if gtest_filter is not None:
347       args.append('--%s=%s' % (FILTER_FLAG, gtest_filter))
348
349     tests_run = RunAndExtractTestList(args)[0]
350     self.AssertSetEqual(tests_run, tests_to_run)
351
352   def setUp(self):
353     """Sets up test case.
354
355     Determines whether value-parameterized tests are enabled in the binary and
356     sets the flags accordingly.
357     """
358
359     global param_tests_present
360     if param_tests_present is None:
361       param_tests_present = PARAM_TEST_REGEX.search(
362           RunAndReturnOutput()) is not None
363
364   def testDefaultBehavior(self):
365     """Tests the behavior of not specifying the filter."""
366
367     self.RunAndVerify(None, ACTIVE_TESTS)
368
369   def testDefaultBehaviorWithShards(self):
370     """Tests the behavior without the filter, with sharding enabled."""
371
372     self.RunAndVerifyWithSharding(None, 1, ACTIVE_TESTS)
373     self.RunAndVerifyWithSharding(None, 2, ACTIVE_TESTS)
374     self.RunAndVerifyWithSharding(None, len(ACTIVE_TESTS) - 1, ACTIVE_TESTS)
375     self.RunAndVerifyWithSharding(None, len(ACTIVE_TESTS), ACTIVE_TESTS)
376     self.RunAndVerifyWithSharding(None, len(ACTIVE_TESTS) + 1, ACTIVE_TESTS)
377
378   def testEmptyFilter(self):
379     """Tests an empty filter."""
380
381     self.RunAndVerify('', [])
382     self.RunAndVerifyWithSharding('', 1, [])
383     self.RunAndVerifyWithSharding('', 2, [])
384
385   def testBadFilter(self):
386     """Tests a filter that matches nothing."""
387
388     self.RunAndVerify('BadFilter', [])
389     self.RunAndVerifyAllowingDisabled('BadFilter', [])
390
391   def testFullName(self):
392     """Tests filtering by full name."""
393
394     self.RunAndVerify('FooTest.Xyz', ['FooTest.Xyz'])
395     self.RunAndVerifyAllowingDisabled('FooTest.Xyz', ['FooTest.Xyz'])
396     self.RunAndVerifyWithSharding('FooTest.Xyz', 5, ['FooTest.Xyz'])
397
398   def testUniversalFilters(self):
399     """Tests filters that match everything."""
400
401     self.RunAndVerify('*', ACTIVE_TESTS)
402     self.RunAndVerify('*.*', ACTIVE_TESTS)
403     self.RunAndVerifyWithSharding('*.*', len(ACTIVE_TESTS) - 3, ACTIVE_TESTS)
404     self.RunAndVerifyAllowingDisabled('*', ACTIVE_TESTS + DISABLED_TESTS)
405     self.RunAndVerifyAllowingDisabled('*.*', ACTIVE_TESTS + DISABLED_TESTS)
406
407   def testFilterByTestCase(self):
408     """Tests filtering by test case name."""
409
410     self.RunAndVerify('FooTest.*', ['FooTest.Abc', 'FooTest.Xyz'])
411
412     BAZ_TESTS = ['BazTest.TestOne', 'BazTest.TestA', 'BazTest.TestB']
413     self.RunAndVerify('BazTest.*', BAZ_TESTS)
414     self.RunAndVerifyAllowingDisabled('BazTest.*',
415                                       BAZ_TESTS + ['BazTest.DISABLED_TestC'])
416
417   def testFilterByTest(self):
418     """Tests filtering by test name."""
419
420     self.RunAndVerify('*.TestOne', ['BarTest.TestOne', 'BazTest.TestOne'])
421
422   def testFilterDisabledTests(self):
423     """Select only the disabled tests to run."""
424
425     self.RunAndVerify('DISABLED_FoobarTest.Test1', [])
426     self.RunAndVerifyAllowingDisabled('DISABLED_FoobarTest.Test1',
427                                       ['DISABLED_FoobarTest.Test1'])
428
429     self.RunAndVerify('*DISABLED_*', [])
430     self.RunAndVerifyAllowingDisabled('*DISABLED_*', DISABLED_TESTS)
431
432     self.RunAndVerify('*.DISABLED_*', [])
433     self.RunAndVerifyAllowingDisabled('*.DISABLED_*', [
434         'BarTest.DISABLED_TestFour',
435         'BarTest.DISABLED_TestFive',
436         'BazTest.DISABLED_TestC',
437         'DISABLED_FoobarTest.DISABLED_Test2',
438         ])
439
440     self.RunAndVerify('DISABLED_*', [])
441     self.RunAndVerifyAllowingDisabled('DISABLED_*', [
442         'DISABLED_FoobarTest.Test1',
443         'DISABLED_FoobarTest.DISABLED_Test2',
444         'DISABLED_FoobarbazTest.TestA',
445         ])
446
447   def testWildcardInTestCaseName(self):
448     """Tests using wildcard in the test case name."""
449
450     self.RunAndVerify('*a*.*', [
451         'BarTest.TestOne',
452         'BarTest.TestTwo',
453         'BarTest.TestThree',
454
455         'BazTest.TestOne',
456         'BazTest.TestA',
457         'BazTest.TestB', ] + DEATH_TESTS + PARAM_TESTS)
458
459   def testWildcardInTestName(self):
460     """Tests using wildcard in the test name."""
461
462     self.RunAndVerify('*.*A*', ['FooTest.Abc', 'BazTest.TestA'])
463
464   def testFilterWithoutDot(self):
465     """Tests a filter that has no '.' in it."""
466
467     self.RunAndVerify('*z*', [
468         'FooTest.Xyz',
469
470         'BazTest.TestOne',
471         'BazTest.TestA',
472         'BazTest.TestB',
473         ])
474
475   def testTwoPatterns(self):
476     """Tests filters that consist of two patterns."""
477
478     self.RunAndVerify('Foo*.*:*A*', [
479         'FooTest.Abc',
480         'FooTest.Xyz',
481
482         'BazTest.TestA',
483         ])
484
485     # An empty pattern + a non-empty one
486     self.RunAndVerify(':*A*', ['FooTest.Abc', 'BazTest.TestA'])
487
488   def testThreePatterns(self):
489     """Tests filters that consist of three patterns."""
490
491     self.RunAndVerify('*oo*:*A*:*One', [
492         'FooTest.Abc',
493         'FooTest.Xyz',
494
495         'BarTest.TestOne',
496
497         'BazTest.TestOne',
498         'BazTest.TestA',
499         ])
500
501     # The 2nd pattern is empty.
502     self.RunAndVerify('*oo*::*One', [
503         'FooTest.Abc',
504         'FooTest.Xyz',
505
506         'BarTest.TestOne',
507
508         'BazTest.TestOne',
509         ])
510
511     # The last 2 patterns are empty.
512     self.RunAndVerify('*oo*::', [
513         'FooTest.Abc',
514         'FooTest.Xyz',
515         ])
516
517   def testNegativeFilters(self):
518     self.RunAndVerify('*-BazTest.TestOne', [
519         'FooTest.Abc',
520         'FooTest.Xyz',
521
522         'BarTest.TestOne',
523         'BarTest.TestTwo',
524         'BarTest.TestThree',
525
526         'BazTest.TestA',
527         'BazTest.TestB',
528         ] + DEATH_TESTS + PARAM_TESTS)
529
530     self.RunAndVerify('*-FooTest.Abc:BazTest.*', [
531         'FooTest.Xyz',
532
533         'BarTest.TestOne',
534         'BarTest.TestTwo',
535         'BarTest.TestThree',
536         ] + DEATH_TESTS + PARAM_TESTS)
537
538     self.RunAndVerify('BarTest.*-BarTest.TestOne', [
539         'BarTest.TestTwo',
540         'BarTest.TestThree',
541         ])
542
543     # Tests without leading '*'.
544     self.RunAndVerify('-FooTest.Abc:FooTest.Xyz:BazTest.*', [
545         'BarTest.TestOne',
546         'BarTest.TestTwo',
547         'BarTest.TestThree',
548         ] + DEATH_TESTS + PARAM_TESTS)
549
550     # Value parameterized tests.
551     self.RunAndVerify('*/*', PARAM_TESTS)
552
553     # Value parameterized tests filtering by the sequence name.
554     self.RunAndVerify('SeqP/*', [
555         'SeqP/ParamTest.TestX/0',
556         'SeqP/ParamTest.TestX/1',
557         'SeqP/ParamTest.TestY/0',
558         'SeqP/ParamTest.TestY/1',
559         ])
560
561     # Value parameterized tests filtering by the test name.
562     self.RunAndVerify('*/0', [
563         'SeqP/ParamTest.TestX/0',
564         'SeqP/ParamTest.TestY/0',
565         'SeqQ/ParamTest.TestX/0',
566         'SeqQ/ParamTest.TestY/0',
567         ])
568
569   def testFlagOverridesEnvVar(self):
570     """Tests that the filter flag overrides the filtering env. variable."""
571
572     SetEnvVar(FILTER_ENV_VAR, 'Foo*')
573     args = ['--%s=%s' % (FILTER_FLAG, '*One')]
574     tests_run = RunAndExtractTestList(args)[0]
575     SetEnvVar(FILTER_ENV_VAR, None)
576
577     self.AssertSetEqual(tests_run, ['BarTest.TestOne', 'BazTest.TestOne'])
578
579   def testShardStatusFileIsCreated(self):
580     """Tests that the shard file is created if specified in the environment."""
581
582     shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
583                                      'shard_status_file')
584     self.assert_(not os.path.exists(shard_status_file))
585
586     extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
587     try:
588       InvokeWithModifiedEnv(extra_env, RunAndReturnOutput)
589     finally:
590       self.assert_(os.path.exists(shard_status_file))
591       os.remove(shard_status_file)
592
593   def testShardStatusFileIsCreatedWithListTests(self):
594     """Tests that the shard file is created with the "list_tests" flag."""
595
596     shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
597                                      'shard_status_file2')
598     self.assert_(not os.path.exists(shard_status_file))
599
600     extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
601     try:
602       output = InvokeWithModifiedEnv(extra_env,
603                                      RunAndReturnOutput,
604                                      [LIST_TESTS_FLAG])
605     finally:
606       # This assertion ensures that Google Test enumerated the tests as
607       # opposed to running them.
608       self.assert_('[==========]' not in output,
609                    'Unexpected output during test enumeration.\n'
610                    'Please ensure that LIST_TESTS_FLAG is assigned the\n'
611                    'correct flag value for listing Google Test tests.')
612
613       self.assert_(os.path.exists(shard_status_file))
614       os.remove(shard_status_file)
615
616   if SUPPORTS_DEATH_TESTS:
617     def testShardingWorksWithDeathTests(self):
618       """Tests integration with death tests and sharding."""
619
620       gtest_filter = 'HasDeathTest.*:SeqP/*'
621       expected_tests = [
622           'HasDeathTest.Test1',
623           'HasDeathTest.Test2',
624
625           'SeqP/ParamTest.TestX/0',
626           'SeqP/ParamTest.TestX/1',
627           'SeqP/ParamTest.TestY/0',
628           'SeqP/ParamTest.TestY/1',
629           ]
630
631       for flag in ['--gtest_death_test_style=threadsafe',
632                    '--gtest_death_test_style=fast']:
633         self.RunAndVerifyWithSharding(gtest_filter, 3, expected_tests,
634                                       check_exit_0=True, args=[flag])
635         self.RunAndVerifyWithSharding(gtest_filter, 5, expected_tests,
636                                       check_exit_0=True, args=[flag])
637
638 if __name__ == '__main__':
639   gtest_test_utils.Main()