mirror of
https://github.com/google/googletest.git
synced 2024-12-26 17:41:03 +08:00
Makes the Python tests more portable by calling standard functions to interpret the result of os.system(). This could fix the broken Python tests on some users' machines.
This commit is contained in:
parent
f6b0dc0b40
commit
e79c3ccb73
@ -78,10 +78,7 @@ def Run(command):
|
||||
"""
|
||||
|
||||
exit_code = os.system(command)
|
||||
# On Unix-like systems, the lowest 8 bits of the exit code is the
|
||||
# signal number that killed the process (or 0 if it wasn't killed by
|
||||
# a signal).
|
||||
return (exit_code & 255) != 0
|
||||
return os.WIFSIGNALED(exit_code)
|
||||
|
||||
|
||||
# The unit test.
|
||||
|
@ -62,7 +62,7 @@ def UsesColor(term, color_env_var, color_flag):
|
||||
cmd = COMMAND
|
||||
if color_flag is not None:
|
||||
cmd += ' --%s=%s' % (COLOR_FLAG, color_flag)
|
||||
return os.system(cmd)
|
||||
return gtest_test_utils.GetExitStatus(os.system(cmd))
|
||||
|
||||
|
||||
class GTestColorTest(unittest.TestCase):
|
||||
|
@ -96,6 +96,26 @@ def GetBuildDir():
|
||||
return os.path.abspath(GetFlag('gtest_build_dir'))
|
||||
|
||||
|
||||
def GetExitStatus(exit_code):
|
||||
"""Returns the argument to exit(), or -1 if exit() wasn't called.
|
||||
|
||||
Args:
|
||||
exit_code: the result value of os.system(command).
|
||||
"""
|
||||
|
||||
if os.name == 'nt':
|
||||
# On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
|
||||
# the argument to exit() directly.
|
||||
return exit_code
|
||||
else:
|
||||
# On Unix, os.WEXITSTATUS() must be used to extract the exit status
|
||||
# from the result of os.system().
|
||||
if os.WIFEXITED(exit_code):
|
||||
return os.WEXITSTATUS(exit_code)
|
||||
else:
|
||||
return -1
|
||||
|
||||
|
||||
def Main():
|
||||
"""Runs the unit test."""
|
||||
|
||||
|
@ -81,13 +81,7 @@ def TestExitCodeAndOutput(command):
|
||||
"""Runs the given command and verifies its exit code and output."""
|
||||
|
||||
# Verifies that 'command' exits with code 1.
|
||||
if IS_WINDOWS:
|
||||
# On Windows, os.system(command) returns the exit code of 'command'.
|
||||
AssertEq(1, os.system(command))
|
||||
else:
|
||||
# On Unix-like system, os.system(command) returns 256 times the
|
||||
# exit code of 'command'.
|
||||
AssertEq(256, os.system(command))
|
||||
AssertEq(1, gtest_test_utils.GetExitStatus(os.system(command)))
|
||||
|
||||
output = GetOutput(command)
|
||||
Assert('InitGoogleTest' in output)
|
||||
|
@ -103,7 +103,7 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||
command = "cd %s && %s --gtest_output=xml:%s &> /dev/null" % (
|
||||
tempfile.mkdtemp(), gtest_prog_path, self.output_dir_)
|
||||
status = os.system(command)
|
||||
self.assertEquals(0, status)
|
||||
self.assertEquals(0, gtest_test_utils.GetExitStatus(status))
|
||||
|
||||
# TODO(wan@google.com): libtool causes the built test binary to be
|
||||
# named lt-gtest_xml_outfiles_test_ instead of
|
||||
|
@ -128,7 +128,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||
status = os.system("cd %s && %s %s=xml &> /dev/null"
|
||||
% (temp_dir, gtest_prog_path,
|
||||
GTEST_OUTPUT_FLAG))
|
||||
self.assertEquals(0, status)
|
||||
self.assertEquals(0, gtest_test_utils.GetExitStatus(status))
|
||||
self.assert_(os.path.isfile(output_file))
|
||||
|
||||
|
||||
@ -147,14 +147,16 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||
command = ("%s %s=xml:%s &> /dev/null"
|
||||
% (gtest_prog_path, GTEST_OUTPUT_FLAG, xml_path))
|
||||
status = os.system(command)
|
||||
signal = status & 0xff
|
||||
self.assertEquals(0, signal,
|
||||
"%s was killed by signal %d" % (gtest_prog_name, signal))
|
||||
exit_code = status >> 8
|
||||
self.assertEquals(expected_exit_code, exit_code,
|
||||
"'%s' exited with code %s, which doesn't match "
|
||||
"the expected exit code %s."
|
||||
% (command, exit_code, expected_exit_code))
|
||||
if os.WIFSIGNALED(status):
|
||||
signal = os.WTERMSIG(status)
|
||||
self.assert_(False,
|
||||
"%s was killed by signal %d" % (gtest_prog_name, signal))
|
||||
else:
|
||||
exit_code = gtest_test_utils.GetExitStatus(status)
|
||||
self.assertEquals(expected_exit_code, exit_code,
|
||||
"'%s' exited with code %s, which doesn't match "
|
||||
"the expected exit code %s."
|
||||
% (command, exit_code, expected_exit_code))
|
||||
|
||||
expected = minidom.parseString(expected_xml)
|
||||
actual = minidom.parse(xml_path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user