1 # Copyright 2006, Google Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 """Unit test utilities for Google C++ Mocking Framework."""
34 # pylint: disable=C6204
35 from googletest.test import gtest_test_utils
39 """Returns the absolute path of the directory where the .py files are."""
41 return gtest_test_utils.GetSourceDir()
44 def GetTestExecutablePath(executable_name):
45 """Returns the absolute path of the test binary given its name.
47 The function will print a message and abort the program if the resulting file
51 executable_name: name of the test binary that the test script runs.
54 The absolute path of the test binary.
57 return gtest_test_utils.GetTestExecutablePath(executable_name)
60 def GetExitStatus(exit_code):
61 """Returns the argument to exit(), or -1 if exit() wasn't called.
64 exit_code: the result value of os.system(command).
68 # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
69 # the argument to exit() directly.
72 # On Unix, os.WEXITSTATUS() must be used to extract the exit status
73 # from the result of os.system().
74 if os.WIFEXITED(exit_code):
75 return os.WEXITSTATUS(exit_code)
80 # Exposes utilities from gtest_test_utils.
81 Subprocess = gtest_test_utils.Subprocess
82 TestCase = gtest_test_utils.TestCase
83 environ = gtest_test_utils.environ
84 SetEnvVar = gtest_test_utils.SetEnvVar
85 PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
89 """Runs the unit test."""
91 gtest_test_utils.Main()