Skip to content

Commit 4dcb99d

Browse files
Adds file and line information to the "message", which is used as the summary
of a failure. git-svn-id: http://googletest.googlecode.com/svn/trunk@609 861a406c-534a-0410-8894-cb66d6ee9925
1 parent 580d3fc commit 4dcb99d

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/gtest-internal-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class GTEST_API_ UnitTestImpl {
620620
// For example, if Foo() calls Bar(), which in turn calls
621621
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
622622
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
623-
String CurrentOsStackTraceExceptTop(int skip_count);
623+
String CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
624624

625625
// Finds and returns a TestCase with the given name. If one doesn't
626626
// exist, creates one and returns it.

src/gtest.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,16 +3271,17 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
32713271
for (int i = 0; i < result.total_part_count(); ++i) {
32723272
const TestPartResult& part = result.GetTestPartResult(i);
32733273
if (part.failed()) {
3274-
if (++failures == 1)
3274+
if (++failures == 1) {
32753275
*stream << ">\n";
3276-
*stream << " <failure message=\""
3277-
<< EscapeXmlAttribute(part.summary()).c_str()
3278-
<< "\" type=\"\">";
3276+
}
32793277
const string location = internal::FormatCompilerIndependentFileLocation(
32803278
part.file_name(), part.line_number());
3281-
const string message = location + "\n" + part.message();
3282-
OutputXmlCDataSection(stream,
3283-
RemoveInvalidXmlCharacters(message).c_str());
3279+
const string summary = location + "\n" + part.summary();
3280+
*stream << " <failure message=\""
3281+
<< EscapeXmlAttribute(summary.c_str())
3282+
<< "\" type=\"\">";
3283+
const string detail = location + "\n" + part.message();
3284+
OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str());
32843285
*stream << "</failure>\n";
32853286
}
32863287
}

test/gtest_xml_output_unittest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,33 @@
6363
</testsuite>
6464
<testsuite name="FailedTest" tests="1" failures="1" disabled="0" errors="0" time="*">
6565
<testcase name="Fails" status="run" time="*" classname="FailedTest">
66-
<failure message="Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
66+
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
6767
Value of: 2
6868
Expected: 1%(stack)s]]></failure>
6969
</testcase>
7070
</testsuite>
7171
<testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" errors="0" time="*">
7272
<testcase name="Succeeds" status="run" time="*" classname="MixedResultTest"/>
7373
<testcase name="Fails" status="run" time="*" classname="MixedResultTest">
74-
<failure message="Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
74+
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
7575
Value of: 2
7676
Expected: 1%(stack)s]]></failure>
77-
<failure message="Value of: 3&#x0A;Expected: 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
77+
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Value of: 3&#x0A;Expected: 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
7878
Value of: 3
7979
Expected: 2%(stack)s]]></failure>
8080
</testcase>
8181
<testcase name="DISABLED_test" status="notrun" time="*" classname="MixedResultTest"/>
8282
</testsuite>
8383
<testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" errors="0" time="*">
8484
<testcase name="OutputsCData" status="run" time="*" classname="XmlQuotingTest">
85-
<failure message="Failed&#x0A;XML output: &lt;?xml encoding=&quot;utf-8&quot;&gt;&lt;top&gt;&lt;![CDATA[cdata text]]&gt;&lt;/top&gt;" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
85+
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Failed&#x0A;XML output: &lt;?xml encoding=&quot;utf-8&quot;&gt;&lt;top&gt;&lt;![CDATA[cdata text]]&gt;&lt;/top&gt;" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
8686
Failed
8787
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]&gt;<![CDATA[</top>%(stack)s]]></failure>
8888
</testcase>
8989
</testsuite>
9090
<testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" errors="0" time="*">
9191
<testcase name="InvalidCharactersInMessage" status="run" time="*" classname="InvalidCharactersTest">
92-
<failure message="Failed&#x0A;Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
92+
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Failed&#x0A;Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
9393
Failed
9494
Invalid characters in brackets []%(stack)s]]></failure>
9595
</testcase>

test/gtest_xml_test_utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ def NormalizeXml(self, element):
156156
* The "type_param" attribute of <testcase> elements is replaced with a
157157
single asterisk (if it sn non-empty) as it is the type name returned
158158
by the compiler and is platform dependent.
159-
* The line number reported in the first line of the "message"
160-
attribute of <failure> elements is replaced with a single asterisk.
159+
* The line info reported in the first line of the "message"
160+
attribute and CDATA section of <failure> elements is replaced with the
161+
file's basename and a single asterisk for the line number.
161162
* The directory names in file paths are removed.
162163
* The stack traces are removed.
163164
"""
@@ -173,10 +174,14 @@ def NormalizeXml(self, element):
173174
if type_param and type_param.value:
174175
type_param.value = '*'
175176
elif element.tagName == 'failure':
177+
source_line_pat = r'^.*[/\\](.*:)\d+\n'
178+
# Replaces the source line information with a normalized form.
179+
message = element.getAttributeNode('message')
180+
message.value = re.sub(source_line_pat, '\\1*\n', message.value)
176181
for child in element.childNodes:
177182
if child.nodeType == Node.CDATA_SECTION_NODE:
178-
# Removes the source line number.
179-
cdata = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', child.nodeValue)
183+
# Replaces the source line information with a normalized form.
184+
cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue)
180185
# Removes the actual stack trace.
181186
child.nodeValue = re.sub(r'\nStack trace:\n(.|\n)*',
182187
'', cdata)

0 commit comments

Comments
 (0)