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