Blame googlemock/test/gmock_test_utils.py

Packit bd1cd8
#!/usr/bin/env python
Packit bd1cd8
#
Packit bd1cd8
# Copyright 2006, Google Inc.
Packit bd1cd8
# All rights reserved.
Packit bd1cd8
#
Packit bd1cd8
# Redistribution and use in source and binary forms, with or without
Packit bd1cd8
# modification, are permitted provided that the following conditions are
Packit bd1cd8
# met:
Packit bd1cd8
#
Packit bd1cd8
#     * Redistributions of source code must retain the above copyright
Packit bd1cd8
# notice, this list of conditions and the following disclaimer.
Packit bd1cd8
#     * Redistributions in binary form must reproduce the above
Packit bd1cd8
# copyright notice, this list of conditions and the following disclaimer
Packit bd1cd8
# in the documentation and/or other materials provided with the
Packit bd1cd8
# distribution.
Packit bd1cd8
#     * Neither the name of Google Inc. nor the names of its
Packit bd1cd8
# contributors may be used to endorse or promote products derived from
Packit bd1cd8
# this software without specific prior written permission.
Packit bd1cd8
#
Packit bd1cd8
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit bd1cd8
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit bd1cd8
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit bd1cd8
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit bd1cd8
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit bd1cd8
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit bd1cd8
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit bd1cd8
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit bd1cd8
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit bd1cd8
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit bd1cd8
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit bd1cd8
Packit bd1cd8
"""Unit test utilities for Google C++ Mocking Framework."""
Packit bd1cd8
Packit bd1cd8
__author__ = 'wan@google.com (Zhanyong Wan)'
Packit bd1cd8
Packit bd1cd8
import os
Packit bd1cd8
import sys
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
# Determines path to gtest_test_utils and imports it.
Packit bd1cd8
SCRIPT_DIR = os.path.dirname(__file__) or '.'
Packit bd1cd8
Packit bd1cd8
# isdir resolves symbolic links.
Packit bd1cd8
gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test')
Packit bd1cd8
if os.path.isdir(gtest_tests_util_dir):
Packit bd1cd8
  GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
Packit bd1cd8
else:
Packit bd1cd8
  GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test')
Packit bd1cd8
Packit bd1cd8
sys.path.append(GTEST_TESTS_UTIL_DIR)
Packit bd1cd8
import gtest_test_utils  # pylint: disable-msg=C6204
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
def GetSourceDir():
Packit bd1cd8
  """Returns the absolute path of the directory where the .py files are."""
Packit bd1cd8
Packit bd1cd8
  return gtest_test_utils.GetSourceDir()
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
def GetTestExecutablePath(executable_name):
Packit bd1cd8
  """Returns the absolute path of the test binary given its name.
Packit bd1cd8
Packit bd1cd8
  The function will print a message and abort the program if the resulting file
Packit bd1cd8
  doesn't exist.
Packit bd1cd8
Packit bd1cd8
  Args:
Packit bd1cd8
    executable_name: name of the test binary that the test script runs.
Packit bd1cd8
Packit bd1cd8
  Returns:
Packit bd1cd8
    The absolute path of the test binary.
Packit bd1cd8
  """
Packit bd1cd8
Packit bd1cd8
  return gtest_test_utils.GetTestExecutablePath(executable_name)
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
def GetExitStatus(exit_code):
Packit bd1cd8
  """Returns the argument to exit(), or -1 if exit() wasn't called.
Packit bd1cd8
Packit bd1cd8
  Args:
Packit bd1cd8
    exit_code: the result value of os.system(command).
Packit bd1cd8
  """
Packit bd1cd8
Packit bd1cd8
  if os.name == 'nt':
Packit bd1cd8
    # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
Packit bd1cd8
    # the argument to exit() directly.
Packit bd1cd8
    return exit_code
Packit bd1cd8
  else:
Packit bd1cd8
    # On Unix, os.WEXITSTATUS() must be used to extract the exit status
Packit bd1cd8
    # from the result of os.system().
Packit bd1cd8
    if os.WIFEXITED(exit_code):
Packit bd1cd8
      return os.WEXITSTATUS(exit_code)
Packit bd1cd8
    else:
Packit bd1cd8
      return -1
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
# Suppresses the "Invalid const name" lint complaint
Packit bd1cd8
# pylint: disable-msg=C6409
Packit bd1cd8
Packit bd1cd8
# Exposes utilities from gtest_test_utils.
Packit bd1cd8
Subprocess = gtest_test_utils.Subprocess
Packit bd1cd8
TestCase = gtest_test_utils.TestCase
Packit bd1cd8
environ = gtest_test_utils.environ
Packit bd1cd8
SetEnvVar = gtest_test_utils.SetEnvVar
Packit bd1cd8
PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
Packit bd1cd8
Packit bd1cd8
# pylint: enable-msg=C6409
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
def Main():
Packit bd1cd8
  """Runs the unit test."""
Packit bd1cd8
Packit bd1cd8
  gtest_test_utils.Main()