blob: a3ba629cba6833fe89d079a5da4cc2152b5fb0f8 [file] [log] [blame]
shiqiand2014562008-07-03 22:38:12 +00001#!/usr/bin/env python
2#
3# Copyright 2008, Google Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
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
15# distribution.
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.
19#
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.
31
32"""Verifies that Google Test warns the user when not initialized properly."""
33
34__author__ = 'wan@google.com (Zhanyong Wan)'
35
36import gtest_test_utils
37import os
38import sys
39import unittest
40
41IS_WINDOWS = os.name == 'nt'
42IS_LINUX = os.name == 'posix'
43
44if IS_WINDOWS:
45 BUILD_DIRS = [
46 'build.dbg\\',
47 'build.opt\\',
48 'build.dbg8\\',
49 'build.opt8\\',
50 ]
51 COMMAND = 'gtest_uninitialized_test_.exe'
52
53if IS_LINUX:
54 COMMAND = os.path.join(gtest_test_utils.GetBuildDir(),
55 'gtest_uninitialized_test_')
56
57
58def Assert(condition):
59 if not condition:
60 raise AssertionError
61
62
63def AssertEq(expected, actual):
64 if expected != actual:
65 print 'Expected: %s' % (expected,)
66 print ' Actual: %s' % (actual,)
67 raise AssertionError
68
69
shiqiand2014562008-07-03 22:38:12 +000070def TestExitCodeAndOutput(command):
71 """Runs the given command and verifies its exit code and output."""
72
shiqiane4e9a8b2008-07-08 21:32:17 +000073 # Verifies that 'command' exits with code 1.
vladlosev957ed9f2008-11-26 20:06:52 +000074 p = gtest_test_utils.Subprocess(command)
75 Assert(p.exited)
76 AssertEq(1, p.exit_code)
77 Assert('InitGoogleTest' in p.output)
shiqiand2014562008-07-03 22:38:12 +000078
79
80if IS_WINDOWS:
81
82 def main():
83 for build_dir in BUILD_DIRS:
84 command = build_dir + COMMAND
85 print 'Testing with %s . . .' % (command,)
86 TestExitCodeAndOutput(command)
87 return 0
88
89 if __name__ == '__main__':
90 main()
91
92
93if IS_LINUX:
94
95 class GTestUninitializedTest(unittest.TestCase):
96 def testExitCodeAndOutput(self):
97 TestExitCodeAndOutput(COMMAND)
98
99
100 if __name__ == '__main__':
101 gtest_test_utils.Main()