1 #!/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 (at] google.com (Zhanyong Wan)' 35 36 import gtest_test_utils 37 import os 38 import sys 39 import unittest 40 41 IS_WINDOWS = os.name == 'nt' 42 IS_LINUX = os.name == 'posix' 43 44 if 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 53 if IS_LINUX: 54 COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), 55 'gtest_uninitialized_test_') 56 57 58 def Assert(condition): 59 if not condition: 60 raise AssertionError 61 62 63 def AssertEq(expected, actual): 64 if expected != actual: 65 print 'Expected: %s' % (expected,) 66 print ' Actual: %s' % (actual,) 67 raise AssertionError 68 69 70 def TestExitCodeAndOutput(command): 71 """Runs the given command and verifies its exit code and output.""" 72 73 # Verifies that 'command' exits with code 1. 74 p = gtest_test_utils.Subprocess(command) 75 Assert(p.exited) 76 AssertEq(1, p.exit_code) 77 Assert('InitGoogleTest' in p.output) 78 79 80 if 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 93 if 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() 102