1b89a7cc2SEnji Cooper#!/usr/bin/env python
2b89a7cc2SEnji Cooper#
3b89a7cc2SEnji Cooper# Copyright 2018 Google LLC. All rights reserved.
4b89a7cc2SEnji Cooper#
5b89a7cc2SEnji Cooper# Redistribution and use in source and binary forms, with or without
6b89a7cc2SEnji Cooper# modification, are permitted provided that the following conditions are
7b89a7cc2SEnji Cooper# met:
8b89a7cc2SEnji Cooper#
9b89a7cc2SEnji Cooper#     * Redistributions of source code must retain the above copyright
10b89a7cc2SEnji Cooper# notice, this list of conditions and the following disclaimer.
11b89a7cc2SEnji Cooper#     * Redistributions in binary form must reproduce the above
12b89a7cc2SEnji Cooper# copyright notice, this list of conditions and the following disclaimer
13b89a7cc2SEnji Cooper# in the documentation and/or other materials provided with the
14b89a7cc2SEnji Cooper# distribution.
15b89a7cc2SEnji Cooper#     * Neither the name of Google Inc. nor the names of its
16b89a7cc2SEnji Cooper# contributors may be used to endorse or promote products derived from
17b89a7cc2SEnji Cooper# this software without specific prior written permission.
18b89a7cc2SEnji Cooper#
19b89a7cc2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20b89a7cc2SEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21b89a7cc2SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22b89a7cc2SEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23b89a7cc2SEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24b89a7cc2SEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25b89a7cc2SEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26b89a7cc2SEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27b89a7cc2SEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28b89a7cc2SEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29b89a7cc2SEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30b89a7cc2SEnji Cooper"""Verifies that Google Test uses filter provided via testbridge."""
31b89a7cc2SEnji Cooper
32b89a7cc2SEnji Cooperimport os
33b89a7cc2SEnji Cooper
3428f6c2f2SEnji Cooperfrom googletest.test import gtest_test_utils
35b89a7cc2SEnji Cooper
36b89a7cc2SEnji Cooperbinary_name = 'gtest_testbridge_test_'
37b89a7cc2SEnji CooperCOMMAND = gtest_test_utils.GetTestExecutablePath(binary_name)
38b89a7cc2SEnji CooperTESTBRIDGE_NAME = 'TESTBRIDGE_TEST_ONLY'
39b89a7cc2SEnji Cooper
40b89a7cc2SEnji Cooper
41b89a7cc2SEnji Cooperdef Assert(condition):
42b89a7cc2SEnji Cooper  if not condition:
43b89a7cc2SEnji Cooper    raise AssertionError
44b89a7cc2SEnji Cooper
45b89a7cc2SEnji Cooper
46b89a7cc2SEnji Cooperclass GTestTestFilterTest(gtest_test_utils.TestCase):
47b89a7cc2SEnji Cooper
48b89a7cc2SEnji Cooper  def testTestExecutionIsFiltered(self):
49b89a7cc2SEnji Cooper    """Tests that the test filter is picked up from the testbridge env var."""
50b89a7cc2SEnji Cooper    subprocess_env = os.environ.copy()
51b89a7cc2SEnji Cooper
52b89a7cc2SEnji Cooper    subprocess_env[TESTBRIDGE_NAME] = '*.TestThatSucceeds'
53b89a7cc2SEnji Cooper    p = gtest_test_utils.Subprocess(COMMAND, env=subprocess_env)
54b89a7cc2SEnji Cooper
5528f6c2f2SEnji Cooper    self.assertEqual(0, p.exit_code)
56b89a7cc2SEnji Cooper
57b89a7cc2SEnji Cooper    Assert('filter = *.TestThatSucceeds' in p.output)
58b89a7cc2SEnji Cooper    Assert('[       OK ] TestFilterTest.TestThatSucceeds' in p.output)
59b89a7cc2SEnji Cooper    Assert('[  PASSED  ] 1 test.' in p.output)
60b89a7cc2SEnji Cooper
61b89a7cc2SEnji Cooper
62b89a7cc2SEnji Cooperif __name__ == '__main__':
63b89a7cc2SEnji Cooper  gtest_test_utils.Main()
64