From 59e5b401a512a453204b9059c6a75e199a8dd8be Mon Sep 17 00:00:00 2001 From: Mario Voorsluys Date: Thu, 26 Mar 2020 13:56:05 +0100 Subject: [PATCH 1/5] Output skipped information in the xml file. --- googletest/src/gtest.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 4c8b42f91c..58da0f1f0d 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2270,7 +2270,8 @@ static const char* const kReservedTestSuitesAttributes[] = { // The list of reserved attributes used in the element of XML // output. static const char* const kReservedTestSuiteAttributes[] = { - "disabled", "errors", "failures", "name", "tests", "time", "timestamp"}; + "disabled", "errors", "failures", "name", + "tests", "time", "timestamp", "skipped"}; // The list of reserved attributes used in the element of XML output. static const char* const kReservedTestCaseAttributes[] = { @@ -4080,6 +4081,7 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name); int failures = 0; + int skips = 0; for (int i = 0; i < result.total_part_count(); ++i) { const TestPartResult& part = result.GetTestPartResult(i); if (part.failed()) { @@ -4096,13 +4098,26 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, const std::string detail = location + "\n" + part.message(); OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); *stream << "\n"; + } else if (part.skipped()) { + if (++skips == 1) { + *stream << ">\n"; + } + const std::string location = + internal::FormatCompilerIndependentFileLocation(part.file_name(), + part.line_number()); + const std::string summary = location + "\n" + part.summary(); + *stream << " "; + const std::string detail = location + "\n" + part.message(); + OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); + *stream << "\n"; } } - if (failures == 0 && result.test_property_count() == 0) { + if (failures == 0 && skips == 0 && result.test_property_count() == 0) { *stream << " />\n"; } else { - if (failures == 0) { + if (failures == 0 && skips == 0) { *stream << ">\n"; } OutputXmlTestProperties(stream, result); @@ -4124,7 +4139,11 @@ void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream, OutputXmlAttribute( stream, kTestsuite, "disabled", StreamableToString(test_suite.reportable_disabled_test_count())); + OutputXmlAttribute(stream, kTestsuite, "skipped", + StreamableToString(test_suite.skipped_test_count())); + OutputXmlAttribute(stream, kTestsuite, "errors", "0"); + OutputXmlAttribute(stream, kTestsuite, "time", FormatTimeInMillisAsSeconds(test_suite.elapsed_time())); OutputXmlAttribute( From d28d05cc6473fd2f4a96ce0fd1cba4dd63102649 Mon Sep 17 00:00:00 2001 From: Mario Voorsluys Date: Thu, 26 Mar 2020 15:03:32 +0100 Subject: [PATCH 2/5] Only write ">\n" once when there is failure and skipped tests. --- googletest/src/gtest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 58da0f1f0d..d6aef6ad2e 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4085,7 +4085,7 @@ 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 && skips == 0) { *stream << ">\n"; } const std::string location = @@ -4099,7 +4099,7 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); *stream << "\n"; } else if (part.skipped()) { - if (++skips == 1) { + if (++skips == 1 && failures == 0) { *stream << ">\n"; } const std::string location = From 23dadb8472d9a124394d9d77a659d565e5ea2d93 Mon Sep 17 00:00:00 2001 From: Mario Voorsluys Date: Thu, 26 Mar 2020 19:14:32 +0100 Subject: [PATCH 3/5] Fix multiple \n characters in xml file when using GTEST_SKIP. --- googletest/src/gtest.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d6aef6ad2e..75d80153b3 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2191,7 +2191,9 @@ std::string AppendUserMessage(const std::string& gtest_msg, if (user_msg_string.empty()) { return gtest_msg; } - + if (gtest_msg.empty()) { + return user_msg_string; + } return gtest_msg + "\n" + user_msg_string; } @@ -3113,7 +3115,7 @@ static std::string FormatTestSuiteCount(int test_suite_count) { static const char * TestPartResultTypeToString(TestPartResult::Type type) { switch (type) { case TestPartResult::kSkip: - return "Skipped"; + return "Skipped\n"; case TestPartResult::kSuccess: return "Success"; From c447b2166b6f72af037cad2113f5bd489f52db53 Mon Sep 17 00:00:00 2001 From: Mario Voorsluys Date: Thu, 26 Mar 2020 19:16:43 +0100 Subject: [PATCH 4/5] Fixed xml unit-tests and added extra tests The extra tests check that the xml output is correct when a failure occurs before skipping, and that the right skip message is added to the file. The json file had to be fixed because it's the same executable. --- .../test/googletest-json-output-unittest.py | 28 +++++++-- googletest/test/gtest_xml_outfiles_test.py | 4 +- googletest/test/gtest_xml_output_unittest.py | 62 ++++++++++++------- googletest/test/gtest_xml_output_unittest_.cc | 9 +++ googletest/test/gtest_xml_test_utils.py | 3 +- 5 files changed, 76 insertions(+), 30 deletions(-) diff --git a/googletest/test/googletest-json-output-unittest.py b/googletest/test/googletest-json-output-unittest.py index 15861f75cb..036b5b13ed 100644 --- a/googletest/test/googletest-json-output-unittest.py +++ b/googletest/test/googletest-json-output-unittest.py @@ -58,9 +58,9 @@ EXPECTED_NON_EMPTY = { u'tests': - 24, + 26, u'failures': - 4, + 5, u'disabled': 2, u'errors': @@ -158,9 +158,9 @@ u'name': u'SkippedTest', u'tests': - 1, + 3, u'failures': - 0, + 1, u'disabled': 0, u'errors': @@ -176,6 +176,26 @@ u'time': u'*', u'timestamp': u'*', u'classname': u'SkippedTest' + }, { + u'name': u'SkippedWithMessage', + u'status': u'RUN', + u'result': u'SKIPPED', + u'time': u'*', + u'timestamp': u'*', + u'classname': u'SkippedTest' + }, { + u'name': u'SkippedAfterFailure', + u'status': u'RUN', + u'result': u'COMPLETED', + u'time': u'*', + u'timestamp': u'*', + u'classname': u'SkippedTest', + u'failures': [{ + u'failure': u'gtest_xml_output_unittest_.cc:*\n' + u'Expected equality of these values:\n' + u' 1\n 2' + STACK_TRACE_TEMPLATE, + u'type': u'' + }] }] }, { u'name': diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index e093f6f05e..ac66feb667 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -42,7 +42,7 @@ EXPECTED_XML_1 = """ - + @@ -56,7 +56,7 @@ EXPECTED_XML_2 = """ - + diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 63b1af0b6c..32b6fdf272 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -65,11 +65,11 @@ sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG) EXPECTED_NON_EMPTY_XML = """ - - + + - + - + - + ]]>%(stack)s]]> - + - + - - + + + + + + + + + + + + - + @@ -135,7 +151,7 @@ - + @@ -152,22 +168,22 @@ - + - + - + - + - + """ % { @@ -177,7 +193,7 @@ EXPECTED_FILTERED_TEST_XML = """ - @@ -185,18 +201,18 @@ EXPECTED_SHARDED_TEST_XML = """ - + - - + + - + - - + + """ diff --git a/googletest/test/gtest_xml_output_unittest_.cc b/googletest/test/gtest_xml_output_unittest_.cc index c95fd66cfa..2b6634b5c6 100644 --- a/googletest/test/gtest_xml_output_unittest_.cc +++ b/googletest/test/gtest_xml_output_unittest_.cc @@ -74,6 +74,15 @@ TEST_F(SkippedTest, Skipped) { GTEST_SKIP(); } +TEST_F(SkippedTest, SkippedWithMessage) { + GTEST_SKIP() << "It is good practice to tell why you skip a test."; +} + +TEST_F(SkippedTest, SkippedAfterFailure) { + EXPECT_EQ(1, 2); + GTEST_SKIP() << "It is good practice to tell why you skip a test."; +} + TEST(MixedResultTest, Succeeds) { EXPECT_EQ(1, 1); ASSERT_EQ(1, 1); diff --git a/googletest/test/gtest_xml_test_utils.py b/googletest/test/gtest_xml_test_utils.py index 9914a49ec1..cae0bc0b9a 100755 --- a/googletest/test/gtest_xml_test_utils.py +++ b/googletest/test/gtest_xml_test_utils.py @@ -105,6 +105,7 @@ def AssertEquivalentNodes(self, expected_node, actual_node): 'testsuite': 'name', 'testcase': 'name', 'failure': 'message', + 'skipped': 'message', 'property': 'name', } @@ -179,7 +180,7 @@ def NormalizeXml(self, element): type_param = element.getAttributeNode('type_param') if type_param and type_param.value: type_param.value = '*' - elif element.tagName == 'failure': + elif element.tagName == 'failure' or element.tagName == 'skipped': source_line_pat = r'^.*[/\\](.*:)\d+\n' # Replaces the source line information with a normalized form. message = element.getAttributeNode('message') From 7c8ab528b716a519278765dc0ddc6c6b5627804f Mon Sep 17 00:00:00 2001 From: Mario Voorsluys Date: Thu, 26 Mar 2020 21:28:35 +0100 Subject: [PATCH 5/5] Fix test with stack. --- googletest/test/gtest_xml_output_unittest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 32b6fdf272..de8b8c751a 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -111,11 +111,11 @@ +%(stack)s]]> +It is good practice to tell why you skip a test.%(stack)s]]> +It is good practice to tell why you skip a test.%(stack)s]]>