00001 #!/usr/bin/env python 00002 # 00003 # Copyright 2008, Google Inc. 00004 # All rights reserved. 00005 # 00006 # Redistribution and use in source and binary forms, with or without 00007 # modification, are permitted provided that the following conditions are 00008 # met: 00009 # 00010 # * Redistributions of source code must retain the above copyright 00011 # notice, this list of conditions and the following disclaimer. 00012 # * Redistributions in binary form must reproduce the above 00013 # copyright notice, this list of conditions and the following disclaimer 00014 # in the documentation and/or other materials provided with the 00015 # distribution. 00016 # * Neither the name of Google Inc. nor the names of its 00017 # contributors may be used to endorse or promote products derived from 00018 # this software without specific prior written permission. 00019 # 00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00023 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00024 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00026 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00027 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00028 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 00032 """Verifies that Google Test warns the user when not initialized properly.""" 00033 00034 __author__ = 'wan@google.com (Zhanyong Wan)' 00035 00036 import gtest_test_utils 00037 00038 00039 COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_uninitialized_test_') 00040 00041 00042 def Assert(condition): 00043 if not condition: 00044 raise AssertionError 00045 00046 00047 def AssertEq(expected, actual): 00048 if expected != actual: 00049 print 'Expected: %s' % (expected,) 00050 print ' Actual: %s' % (actual,) 00051 raise AssertionError 00052 00053 00054 def TestExitCodeAndOutput(command): 00055 """Runs the given command and verifies its exit code and output.""" 00056 00057 # Verifies that 'command' exits with code 1. 00058 p = gtest_test_utils.Subprocess(command) 00059 Assert(p.exited) 00060 AssertEq(1, p.exit_code) 00061 Assert('InitGoogleTest' in p.output) 00062 00063 00064 class GTestUninitializedTest(gtest_test_utils.TestCase): 00065 def testExitCodeAndOutput(self): 00066 TestExitCodeAndOutput(COMMAND) 00067 00068 00069 if __name__ == '__main__': 00070 gtest_test_utils.Main()