]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Makes the Python tests more portable by calling standard functions to interpret the...
authorshiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>
Thu, 18 Sep 2008 21:18:11 +0000 (21:18 +0000)
committershiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>
Thu, 18 Sep 2008 21:18:11 +0000 (21:18 +0000)
test/gtest_break_on_failure_unittest.py
test/gtest_color_test.py
test/gtest_test_utils.py
test/gtest_uninitialized_test.py
test/gtest_xml_outfiles_test.py
test/gtest_xml_output_unittest.py

index 674ef11d47e6fcf256bf116aea5c27fad38a9b03..88716c9c8b20cec25b8cd3661551e3a5e121483a 100755 (executable)
@@ -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.
index 7189176806944fabc6e08af3326f627c237559b2..5260a89967e35446e24d6699d1ddb9a609741fb1 100755 (executable)
@@ -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):
index 6c1588716378fee8bb0597e1aeb7862e18983e10..f454774d24b8b63707cc02a3afb362a1f3bc71d0 100755 (executable)
@@ -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."""
 
index d553bbf970a019cb4c104a2c42c1c9d587b85858..037daa8f0e9765d23108e112e4958d09433e4d39 100755 (executable)
@@ -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)
index df0b95bc3b52e5e9ce892df2acc5b3acdda97c7b..c76e1f789c03c483e1271a20ef5a91b489a24024 100755 (executable)
@@ -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
index af021a9fa98178339c09fe016607f1a4c1743546..013e7397964a311859ee82a2d86e59970e58ae9c 100755 (executable)
@@ -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)