Path: blob/main/contrib/googletest/googlemock/test/gmock_test_utils.py
48254 views
# Copyright 2006, Google Inc.1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions are5# met:6#7# * Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# * Redistributions in binary form must reproduce the above10# copyright notice, this list of conditions and the following disclaimer11# in the documentation and/or other materials provided with the12# distribution.13# * Neither the name of Google Inc. nor the names of its14# contributors may be used to endorse or promote products derived from15# this software without specific prior written permission.16#17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2829"""Unit test utilities for Google C++ Mocking Framework."""3031import os3233# pylint: disable=C620434from googletest.test import gtest_test_utils353637def GetSourceDir():38"""Returns the absolute path of the directory where the .py files are."""3940return gtest_test_utils.GetSourceDir()414243def GetTestExecutablePath(executable_name):44"""Returns the absolute path of the test binary given its name.4546The function will print a message and abort the program if the resulting file47doesn't exist.4849Args:50executable_name: name of the test binary that the test script runs.5152Returns:53The absolute path of the test binary.54"""5556return gtest_test_utils.GetTestExecutablePath(executable_name)575859def GetExitStatus(exit_code):60"""Returns the argument to exit(), or -1 if exit() wasn't called.6162Args:63exit_code: the result value of os.system(command).64"""6566if os.name == 'nt':67# On Windows, os.WEXITSTATUS() doesn't work and os.system() returns68# the argument to exit() directly.69return exit_code70else:71# On Unix, os.WEXITSTATUS() must be used to extract the exit status72# from the result of os.system().73if os.WIFEXITED(exit_code):74return os.WEXITSTATUS(exit_code)75else:76return -1777879# Exposes utilities from gtest_test_utils.80Subprocess = gtest_test_utils.Subprocess81TestCase = gtest_test_utils.TestCase82environ = gtest_test_utils.environ83SetEnvVar = gtest_test_utils.SetEnvVar84PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR858687def Main():88"""Runs the unit test."""8990gtest_test_utils.Main()919293