From 4dcb99d7acb0a551b7122f68a4d15d993f748c9d Mon Sep 17 00:00:00 2001 From: "jgm@google.com" 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. git-svn-id: http://googletest.googlecode.com/svn/trunk@609 861a406c-534a-0410-8894-cb66d6ee9925 --- src/gtest-internal-inl.h | 2 +- src/gtest.cc | 15 ++++++++------- test/gtest_xml_output_unittest.py | 10 +++++----- test/gtest_xml_test_utils.py | 13 +++++++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index 4e9805d..350ade0 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -620,7 +620,7 @@ class GTEST_API_ UnitTestImpl { // For example, if Foo() calls Bar(), which in turn calls // CurrentOsStackTraceExceptTop(1), Foo() will be included in the // trace but Bar() and CurrentOsStackTraceExceptTop() won't. - String CurrentOsStackTraceExceptTop(int skip_count); + String CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_; // Finds and returns a TestCase with the given name. If one doesn't // exist, creates one and returns it. diff --git a/src/gtest.cc b/src/gtest.cc index f2e84af..56af646 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -3271,16 +3271,17 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, for (int i = 0; i < result.total_part_count(); ++i) { const TestPartResult& part = result.GetTestPartResult(i); if (part.failed()) { - if (++failures == 1) + if (++failures == 1) { *stream << ">\n"; - *stream << " "; + } const string location = internal::FormatCompilerIndependentFileLocation( part.file_name(), part.line_number()); - const string message = location + "\n" + part.message(); - OutputXmlCDataSection(stream, - RemoveInvalidXmlCharacters(message).c_str()); + const string summary = location + "\n" + part.summary(); + *stream << " "; + const string detail = location + "\n" + part.message(); + OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); *stream << "\n"; } } diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 8390300..1bcd418 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]]> - diff --git a/test/gtest_xml_test_utils.py b/test/gtest_xml_test_utils.py index f94d634..0e5a108 100755 --- a/test/gtest_xml_test_utils.py +++ b/test/gtest_xml_test_utils.py @@ -156,8 +156,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): * The "type_param" attribute of elements is replaced with a single asterisk (if it sn non-empty) as it is the type name returned by the compiler and is platform dependent. - * The line number reported in the first line of the "message" - attribute of elements is replaced with a single asterisk. + * The line info reported in the first line of the "message" + attribute and CDATA section of elements is replaced with the + file's basename and a single asterisk for the line number. * The directory names in file paths are removed. * The stack traces are removed. """ @@ -173,10 +174,14 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): if type_param and type_param.value: type_param.value = '*' elif element.tagName == 'failure': + source_line_pat = r'^.*[/\\](.*:)\d+\n' + # Replaces the source line information with a normalized form. + message = element.getAttributeNode('message') + message.value = re.sub(source_line_pat, '\\1*\n', message.value) for child in element.childNodes: if child.nodeType == Node.CDATA_SECTION_NODE: - # Removes the source line number. - cdata = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', child.nodeValue) + # Replaces the source line information with a normalized form. + cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue) # Removes the actual stack trace. child.nodeValue = re.sub(r'\nStack trace:\n(.|\n)*', '', cdata) -- cgit v1.2.1