![]() |
|
|||
File indexing completed on 2025-08-06 08:19:59
0001 #!/usr/bin/env python 0002 # 0003 # Copyright 2006, Google Inc. 0004 # All rights reserved. 0005 # 0006 # Redistribution and use in source and binary forms, with or without 0007 # modification, are permitted provided that the following conditions are 0008 # met: 0009 # 0010 # * Redistributions of source code must retain the above copyright 0011 # notice, this list of conditions and the following disclaimer. 0012 # * Redistributions in binary form must reproduce the above 0013 # copyright notice, this list of conditions and the following disclaimer 0014 # in the documentation and/or other materials provided with the 0015 # distribution. 0016 # * Neither the name of Google Inc. nor the names of its 0017 # contributors may be used to endorse or promote products derived from 0018 # this software without specific prior written permission. 0019 # 0020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0023 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0024 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0025 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0026 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0027 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0028 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0029 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0031 0032 """Unit test utilities for Google C++ Mocking Framework.""" 0033 0034 __author__ = 'wan@google.com (Zhanyong Wan)' 0035 0036 import os 0037 import sys 0038 0039 0040 # Determines path to gtest_test_utils and imports it. 0041 SCRIPT_DIR = os.path.dirname(__file__) or '.' 0042 0043 # isdir resolves symbolic links. 0044 gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test') 0045 if os.path.isdir(gtest_tests_util_dir): 0046 GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir 0047 else: 0048 GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test') 0049 0050 sys.path.append(GTEST_TESTS_UTIL_DIR) 0051 import gtest_test_utils # pylint: disable-msg=C6204 0052 0053 0054 def GetSourceDir(): 0055 """Returns the absolute path of the directory where the .py files are.""" 0056 0057 return gtest_test_utils.GetSourceDir() 0058 0059 0060 def GetTestExecutablePath(executable_name): 0061 """Returns the absolute path of the test binary given its name. 0062 0063 The function will print a message and abort the program if the resulting file 0064 doesn't exist. 0065 0066 Args: 0067 executable_name: name of the test binary that the test script runs. 0068 0069 Returns: 0070 The absolute path of the test binary. 0071 """ 0072 0073 return gtest_test_utils.GetTestExecutablePath(executable_name) 0074 0075 0076 def GetExitStatus(exit_code): 0077 """Returns the argument to exit(), or -1 if exit() wasn't called. 0078 0079 Args: 0080 exit_code: the result value of os.system(command). 0081 """ 0082 0083 if os.name == 'nt': 0084 # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns 0085 # the argument to exit() directly. 0086 return exit_code 0087 else: 0088 # On Unix, os.WEXITSTATUS() must be used to extract the exit status 0089 # from the result of os.system(). 0090 if os.WIFEXITED(exit_code): 0091 return os.WEXITSTATUS(exit_code) 0092 else: 0093 return -1 0094 0095 0096 # Suppresses the "Invalid const name" lint complaint 0097 # pylint: disable-msg=C6409 0098 0099 # Exposes utilities from gtest_test_utils. 0100 Subprocess = gtest_test_utils.Subprocess 0101 TestCase = gtest_test_utils.TestCase 0102 environ = gtest_test_utils.environ 0103 SetEnvVar = gtest_test_utils.SetEnvVar 0104 PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR 0105 0106 # pylint: enable-msg=C6409 0107 0108 0109 def Main(): 0110 """Runs the unit test.""" 0111 0112 gtest_test_utils.Main()
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |