1b89a7cc2SEnji Cooper#!/usr/bin/env python
2b89a7cc2SEnji Cooper#
3b89a7cc2SEnji Cooper# Copyright 2008, Google Inc.
4b89a7cc2SEnji Cooper# All rights reserved.
5b89a7cc2SEnji Cooper#
6b89a7cc2SEnji Cooper# Redistribution and use in source and binary forms, with or without
7b89a7cc2SEnji Cooper# modification, are permitted provided that the following conditions are
8b89a7cc2SEnji Cooper# met:
9b89a7cc2SEnji Cooper#
10b89a7cc2SEnji Cooper#     * Redistributions of source code must retain the above copyright
11b89a7cc2SEnji Cooper# notice, this list of conditions and the following disclaimer.
12b89a7cc2SEnji Cooper#     * Redistributions in binary form must reproduce the above
13b89a7cc2SEnji Cooper# copyright notice, this list of conditions and the following disclaimer
14b89a7cc2SEnji Cooper# in the documentation and/or other materials provided with the
15b89a7cc2SEnji Cooper# distribution.
16b89a7cc2SEnji Cooper#     * Neither the name of Google Inc. nor the names of its
17b89a7cc2SEnji Cooper# contributors may be used to endorse or promote products derived from
18b89a7cc2SEnji Cooper# this software without specific prior written permission.
19b89a7cc2SEnji Cooper#
20b89a7cc2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21b89a7cc2SEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22b89a7cc2SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23b89a7cc2SEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24b89a7cc2SEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25b89a7cc2SEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26b89a7cc2SEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27b89a7cc2SEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28b89a7cc2SEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29b89a7cc2SEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30b89a7cc2SEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31b89a7cc2SEnji Cooper
32b89a7cc2SEnji Cooper"""Verifies that Google Test warns the user when not initialized properly."""
33b89a7cc2SEnji Cooper
3428f6c2f2SEnji Cooperfrom googletest.test import gtest_test_utils
35b89a7cc2SEnji Cooper
3628f6c2f2SEnji CooperCOMMAND = gtest_test_utils.GetTestExecutablePath(
3728f6c2f2SEnji Cooper    'googletest-uninitialized-test_'
3828f6c2f2SEnji Cooper)
39b89a7cc2SEnji Cooper
40b89a7cc2SEnji Cooper
41b89a7cc2SEnji Cooperdef Assert(condition):
42b89a7cc2SEnji Cooper  if not condition:
43b89a7cc2SEnji Cooper    raise AssertionError
44b89a7cc2SEnji Cooper
45b89a7cc2SEnji Cooper
46b89a7cc2SEnji Cooperdef AssertEq(expected, actual):
47b89a7cc2SEnji Cooper  if expected != actual:
4828f6c2f2SEnji Cooper    print('Expected: %s' % (expected,))
4928f6c2f2SEnji Cooper    print('  Actual: %s' % (actual,))
50b89a7cc2SEnji Cooper    raise AssertionError
51b89a7cc2SEnji Cooper
52b89a7cc2SEnji Cooper
53b89a7cc2SEnji Cooperdef TestExitCodeAndOutput(command):
54b89a7cc2SEnji Cooper  """Runs the given command and verifies its exit code and output."""
55b89a7cc2SEnji Cooper
56b89a7cc2SEnji Cooper  # Verifies that 'command' exits with code 1.
57b89a7cc2SEnji Cooper  p = gtest_test_utils.Subprocess(command)
58b89a7cc2SEnji Cooper  if p.exited and p.exit_code == 0:
5928f6c2f2SEnji Cooper    Assert('IMPORTANT NOTICE' in p.output)
60b89a7cc2SEnji Cooper  Assert('InitGoogleTest' in p.output)
61b89a7cc2SEnji Cooper
62b89a7cc2SEnji Cooper
63b89a7cc2SEnji Cooperclass GTestUninitializedTest(gtest_test_utils.TestCase):
6428f6c2f2SEnji Cooper
65b89a7cc2SEnji Cooper  def testExitCodeAndOutput(self):
66b89a7cc2SEnji Cooper    TestExitCodeAndOutput(COMMAND)
67b89a7cc2SEnji Cooper
68b89a7cc2SEnji Cooper
69b89a7cc2SEnji Cooperif __name__ == '__main__':
70b89a7cc2SEnji Cooper  gtest_test_utils.Main()
71