Skip to content

Commit e891900

Browse files
committed
Merging, XML tests
1 parent 703b4a8 commit e891900

File tree

4 files changed

+114
-26
lines changed

4 files changed

+114
-26
lines changed

googletest/src/gtest.cc

+36-3
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,11 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
34483448
// to delimit this attribute from prior attributes.
34493449
static std::string TestPropertiesAsXmlAttributes(const TestResult& result);
34503450

3451+
// Streams an XML representation of the test properties of a TestResult
3452+
// object.
3453+
static void OutputXmlTestProperties(std::ostream* stream,
3454+
const TestResult& result);
3455+
34513456
// The output file.
34523457
const std::string output_file_;
34533458

@@ -3659,6 +3664,10 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
36593664
const TestResult& result = *test_info.result();
36603665
const std::string kTestcase = "testcase";
36613666

3667+
if (test_info.is_in_another_shard()) {
3668+
return;
3669+
}
3670+
36623671
*stream << " <testcase";
36633672
OutputXmlAttribute(stream, kTestcase, "name", test_info.name());
36643673

@@ -3675,7 +3684,6 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
36753684
OutputXmlAttribute(stream, kTestcase, "time",
36763685
FormatTimeInMillisAsSeconds(result.elapsed_time()));
36773686
OutputXmlAttribute(stream, kTestcase, "classname", test_case_name);
3678-
*stream << TestPropertiesAsXmlAttributes(result);
36793687

36803688
int failures = 0;
36813689
for (int i = 0; i < result.total_part_count(); ++i) {
@@ -3697,10 +3705,15 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
36973705
}
36983706
}
36993707

3700-
if (failures == 0)
3708+
if (failures == 0 && result.test_property_count() == 0) {
37013709
*stream << " />\n";
3702-
else
3710+
} else {
3711+
if (failures == 0) {
3712+
*stream << ">\n";
3713+
}
3714+
OutputXmlTestProperties(stream, result);
37033715
*stream << " </testcase>\n";
3716+
}
37043717
}
37053718

37063719
// Prints an XML representation of a TestCase object
@@ -3780,6 +3793,26 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
37803793
return attributes.GetString();
37813794
}
37823795

3796+
void XmlUnitTestResultPrinter::OutputXmlTestProperties(
3797+
std::ostream* stream, const TestResult& result) {
3798+
const std::string kProperties = "properties";
3799+
const std::string kProperty = "property";
3800+
3801+
if (result.test_property_count() <= 0) {
3802+
return;
3803+
}
3804+
3805+
*stream << "<" << kProperties << ">\n";
3806+
for (int i = 0; i < result.test_property_count(); ++i) {
3807+
const TestProperty& property = result.GetTestProperty(i);
3808+
*stream << "<" << kProperty;
3809+
*stream << " name=\"" << EscapeXmlAttribute(property.key()) << "\"";
3810+
*stream << " value=\"" << EscapeXmlAttribute(property.value()) << "\"";
3811+
*stream << "/>\n";
3812+
}
3813+
*stream << "</" << kProperties << ">\n";
3814+
}
3815+
37833816
// End XmlUnitTestResultPrinter
37843817

37853818

googletest/test/gtest_xml_outfiles_test.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,27 @@
4343
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
4444
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
4545
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
46-
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" />
46+
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne">
47+
<properties>
48+
<property name="SetUpProp" value="1"/>
49+
<property name="TestSomeProperty" value="1"/>
50+
<property name="TearDownProp" value="1"/>
51+
</properties>
52+
</testcase>
4753
</testsuite>
4854
</testsuites>
4955
"""
5056

5157
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
5258
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
5359
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
54-
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" />
60+
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo">
61+
<properties>
62+
<property name="SetUpProp" value="2"/>
63+
<property name="TestSomeProperty" value="2"/>
64+
<property name="TearDownProp" value="2"/>
65+
</properties>
66+
</testcase>
5567
</testsuite>
5668
</testsuites>
5769
"""

googletest/test/gtest_xml_output_unittest.py

+42-8
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,45 @@
104104
<testcase name="DISABLED_test_not_run" status="notrun" time="*" classname="DisabledTest"/>
105105
</testsuite>
106106
<testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" errors="0" time="*" SetUpTestCase="yes" TearDownTestCase="aye">
107-
<testcase name="OneProperty" status="run" time="*" classname="PropertyRecordingTest" key_1="1"/>
108-
<testcase name="IntValuedProperty" status="run" time="*" classname="PropertyRecordingTest" key_int="1"/>
109-
<testcase name="ThreeProperties" status="run" time="*" classname="PropertyRecordingTest" key_1="1" key_2="2" key_3="3"/>
110-
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" time="*" classname="PropertyRecordingTest" key_1="2"/>
107+
<testcase name="OneProperty" status="run" time="*" classname="PropertyRecordingTest">
108+
<properties>
109+
<property name="key_1" value="1"/>
110+
</properties>
111+
</testcase>
112+
<testcase name="IntValuedProperty" status="run" time="*" classname="PropertyRecordingTest">
113+
<properties>
114+
<property name="key_int" value="1"/>
115+
</properties>
116+
</testcase>
117+
<testcase name="ThreeProperties" status="run" time="*" classname="PropertyRecordingTest">
118+
<properties>
119+
<property name="key_1" value="1"/>
120+
<property name="key_2" value="2"/>
121+
<property name="key_3" value="3"/>
122+
</properties>
123+
</testcase>
124+
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" time="*" classname="PropertyRecordingTest">
125+
<properties>
126+
<property name="key_1" value="2"/>
127+
</properties>
128+
</testcase>
111129
</testsuite>
112130
<testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" errors="0" time="*">
113-
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest" key="1"/>
114-
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_int="1"/>
115-
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_string="1"/>
131+
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest">
132+
<properties>
133+
<property name="key" value="1"/>
134+
</properties>
135+
</testcase>
136+
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" time="*" classname="NoFixtureTest">
137+
<properties>
138+
<property name="key_for_utility_int" value="1"/>
139+
</properties>
140+
</testcase>
141+
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" time="*" classname="NoFixtureTest">
142+
<properties>
143+
<property name="key_for_utility_string" value="1"/>
144+
</properties>
145+
</testcase>
116146
</testsuite>
117147
<testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" errors="0" time="*">
118148
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" time="*" classname="Single/ValueParamTest" />
@@ -149,7 +179,11 @@
149179
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
150180
</testsuite>
151181
<testsuite name="NoFixtureTest" tests="1" failures="0" disabled="0" errors="0" time="*">
152-
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest" key="1"/>
182+
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest">
183+
<properties>
184+
<property name="key" value="1"/>
185+
</properties>
186+
</testcase>
153187
</testsuite>
154188
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" errors="0" time="*">
155189
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />

googletest/test/gtest_xml_test_utils.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,22 @@ def AssertEquivalentNodes(self, expected_node, actual_node):
101101
self.AssertEquivalentNodes(child, actual_children[child_id])
102102

103103
identifying_attribute = {
104-
'testsuites': 'name',
105-
'testsuite': 'name',
106-
'testcase': 'name',
107-
'failure': 'message',
108-
}
104+
'testsuites': 'name',
105+
'testsuite': 'name',
106+
'testcase': 'name',
107+
'failure': 'message',
108+
'property': 'name',
109+
}
109110

110111
def _GetChildren(self, element):
111112
"""
112113
Fetches all of the child nodes of element, a DOM Element object.
113114
Returns them as the values of a dictionary keyed by the IDs of the
114-
children. For <testsuites>, <testsuite> and <testcase> elements, the ID
115-
is the value of their "name" attribute; for <failure> elements, it is
116-
the value of the "message" attribute; CDATA sections and non-whitespace
115+
children. For <testsuites>, <testsuite>, <testcase>, and <property>
116+
elements, the ID is the value of their "name" attribute; for <failure>
117+
elements, it is the value of the "message" attribute; for <properties>
118+
elements, it is the value of their parent's "name" attribute plus the
119+
literal string "properties"; CDATA sections and non-whitespace
117120
text nodes are concatenated into a single CDATA section with ID
118121
"detail". An exception is raised if any element other than the above
119122
four is encountered, if two child elements with the same identifying
@@ -123,11 +126,17 @@ def _GetChildren(self, element):
123126
children = {}
124127
for child in element.childNodes:
125128
if child.nodeType == Node.ELEMENT_NODE:
126-
self.assert_(child.tagName in self.identifying_attribute,
127-
'Encountered unknown element <%s>' % child.tagName)
128-
childID = child.getAttribute(self.identifying_attribute[child.tagName])
129-
self.assert_(childID not in children)
130-
children[childID] = child
129+
if child.tagName == 'properties':
130+
self.assert_(child.parentNode is not None,
131+
'Encountered <properties> element without a parent')
132+
child_id = child.parentNode.getAttribute('name') + '-properties'
133+
else:
134+
self.assert_(child.tagName in self.identifying_attribute,
135+
'Encountered unknown element <%s>' % child.tagName)
136+
child_id = child.getAttribute(
137+
self.identifying_attribute[child.tagName])
138+
self.assert_(child_id not in children)
139+
children[child_id] = child
131140
elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
132141
if 'detail' not in children:
133142
if (child.nodeType == Node.CDATA_SECTION_NODE or

0 commit comments

Comments
 (0)