From d201456903f3ecae1f7794edfab0d5678e642265 Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 3 Jul 2008 22:38:12 +0000 Subject: Initial import. --- test/gtest_xml_output_unittest.py | 171 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100755 test/gtest_xml_output_unittest.py (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py new file mode 100755 index 00000000..af021a9f --- /dev/null +++ b/test/gtest_xml_output_unittest.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python +# +# Copyright 2006, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Unit test for the gtest_xml_output module""" + +__author__ = 'eefacm@gmail.com (Sean Mcafee)' + +import errno +import gtest_test_utils +import os +import sys +import tempfile +import unittest + +from xml.dom import minidom, Node + +import gtest_xml_test_utils + +GTEST_OUTPUT_FLAG = "--gtest_output" +GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" + +EXPECTED_NON_EMPTY_XML = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +""" + + +EXPECTED_EMPTY_XML = """ + +""" + + +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, 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) + 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)) + + expected = minidom.parseString(expected_xml) + actual = minidom.parse(xml_path) + self._NormalizeXml(actual.documentElement) + self._AssertEquivalentElements(expected.documentElement, + actual.documentElement) + expected.unlink() + actual .unlink() + + + +if __name__ == '__main__': + os.environ['GTEST_STACK_TRACE_DEPTH'] = '0' + gtest_test_utils.Main() -- cgit v1.2.3 From e79c3ccb73d68543e8ad98d69179dee74abff7ab Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 18 Sep 2008 21:18:11 +0000 Subject: 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. --- test/gtest_xml_output_unittest.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index af021a9f..013e7397 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -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) -- cgit v1.2.3 From 64cdcb69b28fc26e78d95c574187f7dd9830c84c Mon Sep 17 00:00:00 2001 From: shiqian Date: Fri, 26 Sep 2008 16:08:30 +0000 Subject: Lots of changes: * changes the XML report format to match JUnit/Ant's. * improves file path handling. * allows the user to disable RTTI using the GTEST_HAS_RTTI macro. * makes the code compile with -Wswitch-enum. --- test/gtest_xml_output_unittest.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 013e7397..7206006c 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -54,14 +54,20 @@ EXPECTED_NON_EMPTY_XML = """ - + - - + + @@ -160,14 +166,14 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): expected = minidom.parseString(expected_xml) actual = minidom.parse(xml_path) - self._NormalizeXml(actual.documentElement) - self._AssertEquivalentElements(expected.documentElement, - actual.documentElement) + self.NormalizeXml(actual.documentElement) + self.AssertEquivalentNodes(expected.documentElement, + actual.documentElement) expected.unlink() actual .unlink() if __name__ == '__main__': - os.environ['GTEST_STACK_TRACE_DEPTH'] = '0' + os.environ['GTEST_STACK_TRACE_DEPTH'] = '1' gtest_test_utils.Main() -- cgit v1.2.3 From 514265c415e072caf92fb4eed57aacdfea9964f1 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Sat, 22 Nov 2008 02:26:23 +0000 Subject: Fixed two of the failing tests mentioned in issue 9 --- test/gtest_xml_output_unittest.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 7206006c..c5f9f57f 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -131,9 +131,9 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): if e.errno != errno.ENOENT: raise - status = os.system("cd %s && %s %s=xml &> /dev/null" - % (temp_dir, gtest_prog_path, - GTEST_OUTPUT_FLAG)) + status = gtest_test_utils.RunCommandSuppressOutput( + "%s %s=xml" % (gtest_prog_path, GTEST_OUTPUT_FLAG), + working_dir=temp_dir) self.assertEquals(0, gtest_test_utils.GetExitStatus(status)) self.assert_(os.path.isfile(output_file)) @@ -150,9 +150,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): 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) + command = ("%s %s=xml:%s" % (gtest_prog_path, GTEST_OUTPUT_FLAG, xml_path)) + status = gtest_test_utils.RunCommandSuppressOutput(command) if os.WIFSIGNALED(status): signal = os.WTERMSIG(status) self.assert_(False, -- cgit v1.2.3 From 95536ab53bba952d748f6c1535ba9a3b2ff7e294 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Wed, 26 Nov 2008 20:02:45 +0000 Subject: Fixed gtest_break_on_failure_unittest on Ubuntu 8.04 and Windows --- test/gtest_xml_output_unittest.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index c5f9f57f..5e0b220b 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -131,10 +131,11 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): if e.errno != errno.ENOENT: raise - status = gtest_test_utils.RunCommandSuppressOutput( - "%s %s=xml" % (gtest_prog_path, GTEST_OUTPUT_FLAG), - working_dir=temp_dir) - self.assertEquals(0, gtest_test_utils.GetExitStatus(status)) + p = gtest_test_utils.Subprocess( + [gtest_prog_path, "%s=xml" % GTEST_OUTPUT_FLAG], + working_dir=temp_dir) + self.assert_(p.exited) + self.assertEquals(0, p.exit_code) self.assert_(os.path.isfile(output_file)) @@ -150,18 +151,17 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), gtest_prog_name) - command = ("%s %s=xml:%s" % (gtest_prog_path, GTEST_OUTPUT_FLAG, xml_path)) - status = gtest_test_utils.RunCommandSuppressOutput(command) - if os.WIFSIGNALED(status): - signal = os.WTERMSIG(status) + command = [gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path)] + p = gtest_test_utils.Subprocess(command) + if p.terminated_by_signal: self.assert_(False, - "%s was killed by signal %d" % (gtest_prog_name, signal)) + "%s was killed by signal %d" % (gtest_prog_name, p.signal)) else: - exit_code = gtest_test_utils.GetExitStatus(status) - self.assertEquals(expected_exit_code, exit_code, + self.assert_(p.exited) + self.assertEquals(expected_exit_code, p.exit_code, "'%s' exited with code %s, which doesn't match " "the expected exit code %s." - % (command, exit_code, expected_exit_code)) + % (command, p.exit_code, expected_exit_code)) expected = minidom.parseString(expected_xml) actual = minidom.parse(xml_path) -- cgit v1.2.3 From 2c0fc6d415343b732a4ae39cce1458be1170b9f6 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 24 Mar 2009 20:39:44 +0000 Subject: Cleans up death test implementation (by Vlad Losev); changes the XML format to be closer to junitreport (by Zhanyong Wan). --- test/gtest_xml_output_unittest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 5e0b220b..4587c41b 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -48,7 +48,7 @@ GTEST_OUTPUT_FLAG = "--gtest_output" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" EXPECTED_NON_EMPTY_XML = """ - + @@ -85,12 +85,12 @@ Expected: 2]]> -""" +""" EXPECTED_EMPTY_XML = """ - -""" + +""" class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): -- cgit v1.2.3 From 7fa242a44b47ce74d7246440b14571f7a5dd1b17 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 9 Apr 2009 02:57:38 +0000 Subject: Makes the Python tests more stable (by Vlad Losev); fixes a memory leak in GetThreadCount() on Mac (by Vlad Losev); improves fuse_gtest_files.py to support fusing Google Mock files (by Zhanyong Wan). --- test/gtest_xml_output_unittest.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 4587c41b..622251ea 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -121,10 +121,9 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): 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") + output_file = os.path.join(temp_dir, GTEST_DEFAULT_OUTPUT_FILE) + gtest_prog_path = gtest_test_utils.GetTestExecutablePath( + "gtest_no_test_unittest") try: os.remove(output_file) except OSError, e: @@ -148,8 +147,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): """ 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) + gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) command = [gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path)] p = gtest_test_utils.Subprocess(command) -- cgit v1.2.3 From 532dc2de35f2cef191bc91c3587a9f8f4974756f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 17 Jun 2009 21:06:27 +0000 Subject: Implements a subset of TR1 tuple needed by gtest and gmock (by Zhanyong Wan); cleaned up the Python tests (by Vlad Losev); made run_tests.py invokable from any directory (by Vlad Losev). --- test/gtest_xml_output_unittest.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 622251ea..a0cd4d09 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -34,19 +34,24 @@ __author__ = 'eefacm@gmail.com (Sean Mcafee)' import errno -import gtest_test_utils import os import sys -import tempfile -import unittest - from xml.dom import minidom, Node +import gtest_test_utils import gtest_xml_test_utils + GTEST_OUTPUT_FLAG = "--gtest_output" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" +SUPPORTS_STACK_TRACES = False + +if SUPPORTS_STACK_TRACES: + STACK_TRACE_TEMPLATE = "\nStack trace:\n*" +else: + STACK_TRACE_TEMPLATE = "" + EXPECTED_NON_EMPTY_XML = """ @@ -56,7 +61,7 @@ EXPECTED_NON_EMPTY_XML = """ +Expected: 1%(stack)s]]> @@ -64,10 +69,10 @@ Expected: 1]]> +Expected: 1%(stack)s]]> +Expected: 2%(stack)s]]> @@ -85,7 +90,7 @@ Expected: 2]]> -""" +""" % {'stack': STACK_TRACE_TEMPLATE} EXPECTED_EMPTY_XML = """ @@ -120,8 +125,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): 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) + output_file = os.path.join(gtest_test_utils.GetTempDir(), + GTEST_DEFAULT_OUTPUT_FILE) gtest_prog_path = gtest_test_utils.GetTestExecutablePath( "gtest_no_test_unittest") try: @@ -132,7 +137,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): p = gtest_test_utils.Subprocess( [gtest_prog_path, "%s=xml" % GTEST_OUTPUT_FLAG], - working_dir=temp_dir) + working_dir=gtest_test_utils.GetTempDir()) self.assert_(p.exited) self.assertEquals(0, p.exit_code) self.assert_(os.path.isfile(output_file)) @@ -145,8 +150,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): 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") + xml_path = os.path.join(gtest_test_utils.GetTempDir(), + gtest_prog_name + "out.xml") gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) command = [gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path)] -- cgit v1.2.3 From 16e9dd6e28a8a7fb2d611011e7353e042fcb282f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 4 Sep 2009 18:30:25 +0000 Subject: More implementation of the event listener interface (by Vlad Losev); Reduces the stack space usage of assertions by moving AssertHelper's fields to the heap (by Jorg Brown); Makes String faster, smaller, and simpler (by Zhanyong Wan); Fixes a bug in String::Format() (by Chandler); Adds the /MD version of VC projects to the distribution (by Vlad Losev). --- test/gtest_xml_output_unittest.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index a0cd4d09..3ee6846e 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -44,6 +44,7 @@ import gtest_xml_test_utils GTEST_OUTPUT_FLAG = "--gtest_output" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" +GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_" SUPPORTS_STACK_TRACES = False @@ -108,8 +109,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): 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) + self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1) def testEmptyXmlOutput(self): """ @@ -142,6 +142,35 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): self.assertEquals(0, p.exit_code) self.assert_(os.path.isfile(output_file)) + def testSuppressedXmlOutput(self): + """ + Tests that no XML file is generated if the default XML listener is + shut down before RUN_ALL_TESTS is invoked. + """ + + xml_path = os.path.join(gtest_test_utils.GetTempDir(), + GTEST_PROGRAM_NAME + "out.xml") + if os.path.isfile(xml_path): + os.remove(xml_path) + + gtest_prog_path = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) + + command = [gtest_prog_path, + "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path), + "--shut_down_xml"] + p = gtest_test_utils.Subprocess(command) + if p.terminated_by_signal: + self.assert_(False, + "%s was killed by signal %d" % (gtest_prog_name, p.signal)) + else: + self.assert_(p.exited) + self.assertEquals(1, p.exit_code, + "'%s' exited with code %s, which doesn't match " + "the expected exit code %s." + % (command, p.exit_code, 1)) + + self.assert_(not os.path.isfile(xml_path)) + def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): """ -- cgit v1.2.3 From f8b268ee86ca74bba3276352f1e7de53d1336c3e Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 30 Sep 2009 20:23:50 +0000 Subject: Makes gtest compile cleanly with MSVC's /W4 (by Zhanyong Wan). Renames EventListenrs to TestEventListeners (by Zhanyong Wan). Fixes invalid characters in XML report (by Vlad Losev). Refacotrs SConscript (by Vlad Losev). --- test/gtest_xml_output_unittest.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 3ee6846e..6d44929c 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -54,7 +54,7 @@ else: STACK_TRACE_TEMPLATE = "" EXPECTED_NON_EMPTY_XML = """ - + @@ -77,6 +77,20 @@ Expected: 2%(stack)s]]> + + + ]]>%(stack)s]]> + + + + + + + -- cgit v1.2.3 From 9bcf4d0a654b27732e2fa901fe98c09aba71773a Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 2 Feb 2011 00:49:33 +0000 Subject: Adds type_param and value_param as attributes to the XML report; also removes the comment() and test_case_comment() fields of TestInfo. Proposed and initally implemented by Joey Oravec. Re-implemented by Vlad Losev. --- test/gtest_xml_output_unittest.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 6d44929c..bdd50353 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -54,7 +54,7 @@ else: STACK_TRACE_TEMPLATE = "" EXPECTED_NON_EMPTY_XML = """ - + @@ -105,6 +105,24 @@ Invalid characters in brackets []%(stack)s]]> + + + + + + + + + + + + + + + + + + """ % {'stack': STACK_TRACE_TEMPLATE} -- cgit v1.2.3 From cc265df8b44e613ca118ce5da145f91d66f6c440 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Mon, 13 Jun 2011 19:00:37 +0000 Subject: Fixes broken build on VC++ 7.1. --- test/gtest_xml_output_unittest.py | 54 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index bdd50353..06637e5b 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -42,6 +42,7 @@ import gtest_test_utils import gtest_xml_test_utils +GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' GTEST_OUTPUT_FLAG = "--gtest_output" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_" @@ -49,9 +50,9 @@ GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_" SUPPORTS_STACK_TRACES = False if SUPPORTS_STACK_TRACES: - STACK_TRACE_TEMPLATE = "\nStack trace:\n*" + STACK_TRACE_TEMPLATE = '\nStack trace:\n*' else: - STACK_TRACE_TEMPLATE = "" + STACK_TRACE_TEMPLATE = '' EXPECTED_NON_EMPTY_XML = """ @@ -130,18 +131,26 @@ EXPECTED_EMPTY_XML = """ """ +GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) + +SUPPORTS_TYPED_TESTS = 'TypedTest' in gtest_test_utils.Subprocess( + [GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False).output + 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_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1) + # This test currently breaks on platforms that do not support typed and + # type-parameterized tests, so we don't run it under them. + if SUPPORTS_TYPED_TESTS: + 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_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1) def testEmptyXmlOutput(self): """ @@ -149,8 +158,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): tests that the XML output is expected. """ - self._TestXmlOutput("gtest_no_test_unittest", - EXPECTED_EMPTY_XML, 0) + self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_EMPTY_XML, 0) def testDefaultOutputFile(self): """ @@ -160,7 +168,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): output_file = os.path.join(gtest_test_utils.GetTempDir(), GTEST_DEFAULT_OUTPUT_FILE) gtest_prog_path = gtest_test_utils.GetTestExecutablePath( - "gtest_no_test_unittest") + 'gtest_no_test_unittest') try: os.remove(output_file) except OSError, e: @@ -168,7 +176,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): raise p = gtest_test_utils.Subprocess( - [gtest_prog_path, "%s=xml" % GTEST_OUTPUT_FLAG], + [gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG], working_dir=gtest_test_utils.GetTempDir()) self.assert_(p.exited) self.assertEquals(0, p.exit_code) @@ -181,24 +189,22 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): """ xml_path = os.path.join(gtest_test_utils.GetTempDir(), - GTEST_PROGRAM_NAME + "out.xml") + GTEST_PROGRAM_NAME + 'out.xml') if os.path.isfile(xml_path): os.remove(xml_path) - gtest_prog_path = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) - - command = [gtest_prog_path, - "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path), - "--shut_down_xml"] + command = [GTEST_PROGRAM_PATH, + '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path), + '--shut_down_xml'] p = gtest_test_utils.Subprocess(command) if p.terminated_by_signal: self.assert_(False, - "%s was killed by signal %d" % (gtest_prog_name, p.signal)) + '%s was killed by signal %d' % (gtest_prog_name, p.signal)) else: self.assert_(p.exited) self.assertEquals(1, p.exit_code, "'%s' exited with code %s, which doesn't match " - "the expected exit code %s." + 'the expected exit code %s.' % (command, p.exit_code, 1)) self.assert_(not os.path.isfile(xml_path)) @@ -212,19 +218,19 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): expected_exit_code. """ xml_path = os.path.join(gtest_test_utils.GetTempDir(), - gtest_prog_name + "out.xml") + gtest_prog_name + 'out.xml') gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) - command = [gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path)] + command = [gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] p = gtest_test_utils.Subprocess(command) if p.terminated_by_signal: self.assert_(False, - "%s was killed by signal %d" % (gtest_prog_name, p.signal)) + '%s was killed by signal %d' % (gtest_prog_name, p.signal)) else: self.assert_(p.exited) self.assertEquals(expected_exit_code, p.exit_code, "'%s' exited with code %s, which doesn't match " - "the expected exit code %s." + 'the expected exit code %s.' % (command, p.exit_code, expected_exit_code)) expected = minidom.parseString(expected_xml) -- cgit v1.2.3 From 431a8be1662a3bc9601240914f412b0436d94703 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Wed, 5 Oct 2011 05:52:34 +0000 Subject: Implements the timestamp attribute for the testsuites element in the output XML (external contribution by Dirk Meister). --- test/gtest_xml_output_unittest.py | 64 ++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 06637e5b..83903002 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -33,8 +33,10 @@ __author__ = 'eefacm@gmail.com (Sean Mcafee)' +import datetime import errno import os +import re import sys from xml.dom import minidom, Node @@ -55,7 +57,7 @@ else: STACK_TRACE_TEMPLATE = '' EXPECTED_NON_EMPTY_XML = """ - + @@ -128,7 +130,7 @@ Invalid characters in brackets []%(stack)s]]> EXPECTED_EMPTY_XML = """ - + """ GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) @@ -153,13 +155,39 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1) def testEmptyXmlOutput(self): - """ + """Verifies XML output for a Google Test binary without actual tests. + 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 testTimestampValue(self): + """Checks whether the timestamp attribute in the XML output is valid. + + Runs a test program that generates an empty XML output, and checks if + the timestamp attribute in the testsuites tag is valid. + """ + actual = self._GetXmlOutput('gtest_no_test_unittest', 0) + date_time_str = actual.documentElement.getAttributeNode('timestamp').value + # datetime.strptime() is only available in Python 2.5+ so we have to + # parse the expected datetime manually. + match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str) + self.assertTrue( + re.match, + 'XML datettime string %s has incorrect format' % date_time_str) + date_time_from_xml = datetime.datetime( + year=int(match.group(1)), month=int(match.group(2)), + day=int(match.group(3)), hour=int(match.group(4)), + minute=int(match.group(5)), second=int(match.group(6))) + + time_delta = abs(datetime.datetime.now() - date_time_from_xml) + # timestamp value should be near the current local time + self.assertTrue(time_delta < datetime.timedelta(seconds=600), + 'time_delta is %s' % time_delta) + actual.unlink() + def testDefaultOutputFile(self): """ Confirms that Google Test produces an XML output file with the expected @@ -198,8 +226,10 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): '--shut_down_xml'] p = gtest_test_utils.Subprocess(command) if p.terminated_by_signal: - self.assert_(False, - '%s was killed by signal %d' % (gtest_prog_name, p.signal)) + # p.signal is avalable only if p.terminated_by_signal is True. + self.assertFalse( + p.terminated_by_signal, + '%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal)) else: self.assert_(p.exited) self.assertEquals(1, p.exit_code, @@ -209,13 +239,10 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): self.assert_(not os.path.isfile(xml_path)) - - def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): + def _GetXmlOutput(self, gtest_prog_name, 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. + Returns the xml output generated by running the program gtest_prog_name. + Furthermore, the program's exit code must be expected_exit_code. """ xml_path = os.path.join(gtest_test_utils.GetTempDir(), gtest_prog_name + 'out.xml') @@ -232,15 +259,24 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): "'%s' exited with code %s, which doesn't match " 'the expected exit code %s.' % (command, p.exit_code, expected_exit_code)) + actual = minidom.parse(xml_path) + return actual + 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. + """ + + actual = self._GetXmlOutput(gtest_prog_name, 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() - + actual.unlink() if __name__ == '__main__': -- cgit v1.2.3 From 4d6f296e8e5d3f839ef4868390bbec27cb12e068 Mon Sep 17 00:00:00 2001 From: jgm Date: Tue, 17 Jan 2012 15:11:32 +0000 Subject: Adds file and line information to the "message", which is used as the summary of a failure. --- test/gtest_xml_output_unittest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 83903002..1bcd4187 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -63,7 +63,7 @@ EXPECTED_NON_EMPTY_XML = """ - @@ -71,10 +71,10 @@ Expected: 1%(stack)s]]> - - @@ -82,14 +82,14 @@ Expected: 2%(stack)s]]> - ]]>%(stack)s]]> - -- cgit v1.2.3 From f5fa71f728ce77c5d5c1a940a9bd8bb1d64c9f78 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Fri, 5 Apr 2013 20:50:46 +0000 Subject: Implements support for calling Test::RecordProperty() outside of a test. --- test/gtest_xml_output_unittest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 1bcd4187..3d794e6b 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -57,7 +57,7 @@ else: STACK_TRACE_TEMPLATE = '' EXPECTED_NON_EMPTY_XML = """ - + @@ -97,7 +97,7 @@ Invalid characters in brackets []%(stack)s]]> - + -- cgit v1.2.3 From c506784b08473f3ba8f37d588fd08d8d3f948245 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 25 Apr 2013 17:58:52 +0000 Subject: When --gtest_filter is specified, XML report now doesn't contain information about tests that are filtered out (issue 141). --- test/gtest_xml_output_unittest.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'test/gtest_xml_output_unittest.py') diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 3d794e6b..f605d4ee 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -44,6 +44,7 @@ import gtest_test_utils import gtest_xml_test_utils +GTEST_FILTER_FLAG = '--gtest_filter' GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' GTEST_OUTPUT_FLAG = "--gtest_output" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" @@ -128,9 +129,18 @@ Invalid characters in brackets []%(stack)s]]> """ % {'stack': STACK_TRACE_TEMPLATE} +EXPECTED_FILTERED_TEST_XML = """ + + + + +""" EXPECTED_EMPTY_XML = """ - + """ GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) @@ -169,7 +179,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): Runs a test program that generates an empty XML output, and checks if the timestamp attribute in the testsuites tag is valid. """ - actual = self._GetXmlOutput('gtest_no_test_unittest', 0) + actual = self._GetXmlOutput('gtest_no_test_unittest', [], 0) date_time_str = actual.documentElement.getAttributeNode('timestamp').value # datetime.strptime() is only available in Python 2.5+ so we have to # parse the expected datetime manually. @@ -239,7 +249,17 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): self.assert_(not os.path.isfile(xml_path)) - def _GetXmlOutput(self, gtest_prog_name, expected_exit_code): + def testFilteredTestXmlOutput(self): + """Verifies XML output when a filter is applied. + + Runs a test program that executes only some tests and verifies that + non-selected tests do not show up in the XML output. + """ + + self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0, + extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG]) + + def _GetXmlOutput(self, gtest_prog_name, extra_args, expected_exit_code): """ Returns the xml output generated by running the program gtest_prog_name. Furthermore, the program's exit code must be expected_exit_code. @@ -248,7 +268,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): gtest_prog_name + 'out.xml') gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) - command = [gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] + command = ([gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] + + extra_args) p = gtest_test_utils.Subprocess(command) if p.terminated_by_signal: self.assert_(False, @@ -262,7 +283,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): actual = minidom.parse(xml_path) return actual - def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): + def _TestXmlOutput(self, gtest_prog_name, expected_xml, + expected_exit_code, extra_args=None): """ Asserts that the XML document generated by running the program gtest_prog_name matches expected_xml, a string containing another @@ -270,7 +292,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): expected_exit_code. """ - actual = self._GetXmlOutput(gtest_prog_name, expected_exit_code) + actual = self._GetXmlOutput(gtest_prog_name, extra_args or [], + expected_exit_code) expected = minidom.parseString(expected_xml) self.NormalizeXml(actual.documentElement) self.AssertEquivalentNodes(expected.documentElement, -- cgit v1.2.3