diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index ba6e2956..5a8999f6 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2194,7 +2194,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; } @@ -2273,7 +2275,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[] = { @@ -3115,7 +3118,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"; @@ -4187,10 +4190,11 @@ 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()) { - if (++failures == 1) { + if (++failures == 1 && skips == 0) { *stream << ">\n"; } const std::string location = @@ -4203,13 +4207,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 && failures == 0) { + *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); @@ -4231,7 +4248,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( diff --git a/googletest/test/googletest-json-output-unittest.py b/googletest/test/googletest-json-output-unittest.py index 15861f75..e799d473 100644 --- a/googletest/test/googletest-json-output-unittest.py +++ b/googletest/test/googletest-json-output-unittest.py @@ -58,9 +58,9 @@ else: EXPECTED_NON_EMPTY = { u'tests': - 24, + 26, u'failures': - 4, + 5, u'disabled': 2, u'errors': @@ -158,9 +158,9 @@ EXPECTED_NON_EMPTY = { u'name': u'SkippedTest', u'tests': - 1, + 3, u'failures': - 0, + 1, u'disabled': 0, u'errors': @@ -176,6 +176,32 @@ EXPECTED_NON_EMPTY = { 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 e093f6f0..ac66feb6 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -42,7 +42,7 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" EXPECTED_XML_1 = """ - + @@ -56,7 +56,7 @@ EXPECTED_XML_1 = """ EXPECTED_XML_2 = """ - + diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 63b1af0b..de8b8c75 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -65,11 +65,11 @@ else: sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG) EXPECTED_NON_EMPTY_XML = """ - - + + - + - + - + ]]>%(stack)s]]> - + - + - - + + + + + + + + + + + + - + @@ -135,7 +151,7 @@ Invalid characters in brackets []%(stack)s]]> - + @@ -152,22 +168,22 @@ Invalid characters in brackets []%(stack)s]]> - + - + - + - + - + """ % { @@ -177,7 +193,7 @@ Invalid characters in brackets []%(stack)s]]> EXPECTED_FILTERED_TEST_XML = """ - @@ -185,18 +201,18 @@ EXPECTED_FILTERED_TEST_XML = """ EXPECTED_SHARDED_TEST_XML = """ - + - - + + - + - - + + """ diff --git a/googletest/test/gtest_xml_output_unittest_.cc b/googletest/test/gtest_xml_output_unittest_.cc index c95fd66c..2b6634b5 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 9914a49e..cae0bc0b 100755 --- a/googletest/test/gtest_xml_test_utils.py +++ b/googletest/test/gtest_xml_test_utils.py @@ -105,6 +105,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): 'testsuite': 'name', 'testcase': 'name', 'failure': 'message', + 'skipped': 'message', 'property': 'name', } @@ -179,7 +180,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): 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')