googletest/googlemock/test/gmock_test_utils.py
Go to the documentation of this file.
1 # Copyright 2006, Google Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
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
13 # distribution.
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.
17 #
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.
29 
30 """Unit test utilities for Google C++ Mocking Framework."""
31 
32 import os
33 
34 # pylint: disable=C6204
35 from googletest.test import gtest_test_utils
36 
37 
38 def GetSourceDir():
39  """Returns the absolute path of the directory where the .py files are."""
40 
42 
43 
44 def GetTestExecutablePath(executable_name):
45  """Returns the absolute path of the test binary given its name.
46 
47  The function will print a message and abort the program if the resulting file
48  doesn't exist.
49 
50  Args:
51  executable_name: name of the test binary that the test script runs.
52 
53  Returns:
54  The absolute path of the test binary.
55  """
56 
57  return gtest_test_utils.GetTestExecutablePath(executable_name)
58 
59 
60 def GetExitStatus(exit_code):
61  """Returns the argument to exit(), or -1 if exit() wasn't called.
62 
63  Args:
64  exit_code: the result value of os.system(command).
65  """
66 
67  if os.name == 'nt':
68  # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
69  # the argument to exit() directly.
70  return exit_code
71  else:
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)
76  else:
77  return -1
78 
79 
80 # Suppresses the "Invalid const name" lint complaint
81 # pylint: disable-msg=C6409
82 
83 # Exposes utilities from gtest_test_utils.
84 Subprocess = gtest_test_utils.Subprocess
85 TestCase = gtest_test_utils.TestCase
86 environ = gtest_test_utils.environ
87 SetEnvVar = gtest_test_utils.SetEnvVar
88 PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
89 
90 # pylint: enable-msg=C6409
91 
92 
93 def Main():
94  """Runs the unit test."""
95 
gtest_test_utils.Subprocess
Definition: bloaty/third_party/googletest/googletest/test/gtest_test_utils.py:202
gmock_test_utils.GetSourceDir
def GetSourceDir()
Definition: bloaty/third_party/googletest/googlemock/test/gmock_test_utils.py:50
gtest_test_utils.GetTestExecutablePath
def GetTestExecutablePath(executable_name, build_dir=None)
Definition: bloaty/third_party/googletest/googletest/test/gtest_test_utils.py:151
gmock_test_utils.Main
def Main()
Definition: bloaty/third_party/googletest/googlemock/test/gmock_test_utils.py:105
gmock_test_utils.GetExitStatus
def GetExitStatus(exit_code)
Definition: bloaty/third_party/googletest/googlemock/test/gmock_test_utils.py:72
gtest_test_utils.GetSourceDir
def GetSourceDir()
Definition: bloaty/third_party/googletest/googletest/test/gtest_test_utils.py:123
gtest_test_utils.Main
def Main()
Definition: bloaty/third_party/googletest/googletest/test/gtest_test_utils.py:301
gmock_test_utils.GetTestExecutablePath
def GetTestExecutablePath(executable_name)
Definition: bloaty/third_party/googletest/googlemock/test/gmock_test_utils.py:56


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:39