xref: /freebsd/contrib/googletest/googlemock/test/gmock_test_utils.py (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
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
32import os
33
34# pylint: disable=C6204
35from googletest.test import gtest_test_utils
36
37
38def GetSourceDir():
39  """Returns the absolute path of the directory where the .py files are."""
40
41  return gtest_test_utils.GetSourceDir()
42
43
44def 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
60def 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# Exposes utilities from gtest_test_utils.
81Subprocess = gtest_test_utils.Subprocess
82TestCase = gtest_test_utils.TestCase
83environ = gtest_test_utils.environ
84SetEnvVar = gtest_test_utils.SetEnvVar
85PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
86
87
88def Main():
89  """Runs the unit test."""
90
91  gtest_test_utils.Main()
92