When --gtest_filter is specified, XML report now doesn't contain information about tests that are filtered out (issue 141).
This commit is contained in:
@@ -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]]></failure>
|
||||
</testsuite>
|
||||
</testsuites>""" % {'stack': STACK_TRACE_TEMPLATE}
|
||||
|
||||
EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0"
|
||||
errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
</testsuites>"""
|
||||
|
||||
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests">
|
||||
</testsuites>"""
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user