@@ -3989,6 +3989,12 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
39893989 static void OutputXmlTestSuiteForTestResult (::std::ostream* stream,
39903990 const TestResult& result);
39913991
3992+ // Streams a test case XML stanza containing the given test result.
3993+ //
3994+ // Requires: result.Failed()
3995+ static void OutputXmlTestCaseForTestResult (::std::ostream* stream,
3996+ const TestResult& result);
3997+
39923998 // Streams an XML representation of a TestResult object.
39933999 static void OutputXmlTestResult (::std::ostream* stream,
39944000 const TestResult& result);
@@ -4236,6 +4242,15 @@ void XmlUnitTestResultPrinter::OutputXmlTestSuiteForTestResult(
42364242 FormatEpochTimeInMillisAsIso8601 (result.start_timestamp ()));
42374243 *stream << " >" ;
42384244
4245+ OutputXmlTestCaseForTestResult (stream, result);
4246+
4247+ // Complete the test suite.
4248+ *stream << " </testsuite>\n " ;
4249+ }
4250+
4251+ // Streams a test case XML stanza containing the given test result.
4252+ void XmlUnitTestResultPrinter::OutputXmlTestCaseForTestResult (
4253+ ::std::ostream* stream, const TestResult& result) {
42394254 // Output the boilerplate for a minimal test case with a single test.
42404255 *stream << " <testcase" ;
42414256 OutputXmlAttribute (stream, " testcase" , " name" , " " );
@@ -4250,9 +4265,6 @@ void XmlUnitTestResultPrinter::OutputXmlTestSuiteForTestResult(
42504265
42514266 // Output the actual test result.
42524267 OutputXmlTestResult (stream, result);
4253-
4254- // Complete the test suite.
4255- *stream << " </testsuite>\n " ;
42564268}
42574269
42584270// Prints an XML representation of a TestInfo object.
@@ -4379,6 +4391,10 @@ void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream,
43794391 if (test_suite.GetTestInfo (i)->is_reportable ())
43804392 OutputXmlTestInfo (stream, test_suite.name (), *test_suite.GetTestInfo (i));
43814393 }
4394+ if (test_suite.ad_hoc_test_result ().Failed ()) {
4395+ OutputXmlTestCaseForTestResult (stream, test_suite.ad_hoc_test_result ());
4396+ }
4397+
43824398 *stream << " </" << kTestsuite << " >\n " ;
43834399}
43844400
@@ -4518,6 +4534,12 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener {
45184534 static void OutputJsonTestSuiteForTestResult (::std::ostream* stream,
45194535 const TestResult& result);
45204536
4537+ // Streams a test case JSON stanza containing the given test result.
4538+ //
4539+ // Requires: result.Failed()
4540+ static void OutputJsonTestCaseForTestResult (::std::ostream* stream,
4541+ const TestResult& result);
4542+
45214543 // Streams a JSON representation of a TestResult object.
45224544 static void OutputJsonTestResult (::std::ostream* stream,
45234545 const TestResult& result);
@@ -4688,6 +4710,15 @@ void JsonUnitTestResultPrinter::OutputJsonTestSuiteForTestResult(
46884710 }
46894711 *stream << Indent (6 ) << " \" testsuite\" : [\n " ;
46904712
4713+ OutputJsonTestCaseForTestResult (stream, result);
4714+
4715+ // Finish the test suite.
4716+ *stream << " \n " << Indent (6 ) << " ]\n " << Indent (4 ) << " }" ;
4717+ }
4718+
4719+ // Streams a test case JSON stanza containing the given test result.
4720+ void JsonUnitTestResultPrinter::OutputJsonTestCaseForTestResult (
4721+ ::std::ostream* stream, const TestResult& result) {
46914722 // Output the boilerplate for a new test case.
46924723 *stream << Indent (8 ) << " {\n " ;
46934724 OutputJsonKey (stream, " testcase" , " name" , " " , Indent (10 ));
@@ -4704,9 +4735,6 @@ void JsonUnitTestResultPrinter::OutputJsonTestSuiteForTestResult(
47044735
47054736 // Output the actual test result.
47064737 OutputJsonTestResult (stream, result);
4707-
4708- // Finish the test suite.
4709- *stream << " \n " << Indent (6 ) << " ]\n " << Indent (4 ) << " }" ;
47104738}
47114739
47124740// Prints a JSON representation of a TestInfo object.
@@ -4851,6 +4879,16 @@ void JsonUnitTestResultPrinter::PrintJsonTestSuite(
48514879 OutputJsonTestInfo (stream, test_suite.name (), *test_suite.GetTestInfo (i));
48524880 }
48534881 }
4882+
4883+ // If there was a failure in the test suite setup or teardown include that in
4884+ // the output.
4885+ if (test_suite.ad_hoc_test_result ().Failed ()) {
4886+ if (comma) {
4887+ *stream << " ,\n " ;
4888+ }
4889+ OutputJsonTestCaseForTestResult (stream, test_suite.ad_hoc_test_result ());
4890+ }
4891+
48544892 *stream << " \n " << kIndent << " ]\n " << Indent (4 ) << " }" ;
48554893}
48564894
0 commit comments