def _TestOutFile(self, test_name, expected_xml): gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), test_name) 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, gtest_test_utils.GetExitStatus(status)) # TODO([email protected]): libtool causes the built test binary to be # named lt-gtest_xml_outfiles_test_ instead of # gtest_xml_outfiles_test_. To account for this possibillity, we # allow both names in the following code. We should remove this # hack when Chandler Carruth's libtool replacement tool is ready. output_file_name1 = test_name + ".xml" output_file1 = os.path.join(self.output_dir_, output_file_name1) output_file_name2 = 'lt-' + output_file_name1 output_file2 = os.path.join(self.output_dir_, output_file_name2) self.assert_( os.path.isfile(output_file1) or os.path.isfile(output_file2), output_file1) expected = minidom.parseString(expected_xml) if os.path.isfile(output_file1): actual = minidom.parse(output_file1) else: actual = minidom.parse(output_file2) self._NormalizeXml(actual.documentElement) self._AssertEquivalentElements(expected.documentElement, actual.documentElement) expected.unlink() actual.unlink()
def TestExitCodeAndOutput(command): """Runs the given command and verifies its exit code and output.""" # Verifies that 'command' exits with code 1. AssertEq(1, gtest_test_utils.GetExitStatus(os.system(command))) output = GetOutput(command) Assert('InitGoogleTest' in output)
def UsesColor(term, color_env_var, color_flag): """Runs gtest_color_test_ and returns its exit code.""" SetEnvVar('TERM', term) SetEnvVar(COLOR_ENV_VAR, color_env_var) cmd = COMMAND if color_flag is not None: cmd += ' --%s=%s' % (COLOR_FLAG, color_flag) return gtest_test_utils.GetExitStatus(os.system(cmd))
class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): """ Unit test for Google Test's XML output functionality. """ def testNonEmptyXmlOutput(self): """ Runs a test program that generates a non-empty XML output, and tests that the XML output is expected. """ self._TestXmlOutput("gtest_xml_output_unittest_", EXPECTED_NON_EMPTY_XML, 1) def testEmptyXmlOutput(self): """ Runs a test program that generates an empty XML output, and tests that the XML output is expected. """ self._TestXmlOutput("gtest_no_test_unittest", EXPECTED_EMPTY_XML, 0) def testDefaultOutputFile(self): """ Confirms that Google Test produces an XML output file with the expected default name if no name is explicitly specified. """ temp_dir = tempfile.mkdtemp() output_file = os.path.join(temp_dir, GTEST_DEFAULT_OUTPUT_FILE) gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), "gtest_no_test_unittest") try: os.remove(output_file) except OSError, e: if e.errno != errno.ENOENT: raise status = os.system("cd %s && %s %s=xml &> /dev/null" % (temp_dir, gtest_prog_path, GTEST_OUTPUT_FLAG)) self.assertEquals(0, gtest_test_utils.GetExitStatus(status)) self.assert_(os.path.isfile(output_file))
def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): """ Asserts that the XML document generated by running the program gtest_prog_name matches expected_xml, a string containing another XML document. Furthermore, the program's exit code must be expected_exit_code. """ xml_path = os.path.join(tempfile.mkdtemp(), gtest_prog_name + "out.xml") gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), gtest_prog_name) command = ("%s %s=xml:%s &> /dev/null" % (gtest_prog_path, GTEST_OUTPUT_FLAG, xml_path)) status = os.system(command) 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) self.NormalizeXml(actual.documentElement) self.AssertEquivalentNodes(expected.documentElement, actual.documentElement) expected.unlink() actual.unlink()