diff options
author | Abseil Team <absl-team@google.com> | 2021-03-08 21:48:15 +0300 |
---|---|---|
committer | Dino Radaković <dinor@google.com> | 2021-03-09 21:59:28 +0300 |
commit | bb4f87e6c6699507608042554ddce896ba751643 (patch) | |
tree | 8ecbd09d826daecf0cb038d7b36dcb73fa471b75 | |
parent | bf465ff05d74ca6829c49c321069a34f21b97f5d (diff) |
Googletest export
gtest.cc: Split out functions for printing `TestResult` objects
This will make it possible to reuse this code for outputting the "ad_hoc" `TestResult` objects in structured form in XML/JSON.
PiperOrigin-RevId: 361604860
-rw-r--r-- | googletest/src/gtest.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d659e7d3..e52dda65 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3909,6 +3909,10 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { // Streams an XML CDATA section, escaping invalid CDATA sequences as needed. static void OutputXmlCDataSection(::std::ostream* stream, const char* data); + // Streams an XML representation of a TestResult object. + static void OutputXmlTestResult(::std::ostream* stream, + const TestResult& result); + // Streams an XML representation of a TestInfo object. static void OutputXmlTestInfo(::std::ostream* stream, const char* test_suite_name, @@ -4167,6 +4171,11 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, FormatEpochTimeInMillisAsIso8601(result.start_timestamp())); OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name); + OutputXmlTestResult(stream, result); +} + +void XmlUnitTestResultPrinter::OutputXmlTestResult(::std::ostream* stream, + const TestResult& result) { int failures = 0; int skips = 0; for (int i = 0; i < result.total_part_count(); ++i) { @@ -4371,6 +4380,10 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener { const std::string& indent, bool comma = true); + // Streams a JSON representation of a TestResult object. + static void OutputJsonTestResult(::std::ostream* stream, + const TestResult& result); + // Streams a JSON representation of a TestInfo object. static void OutputJsonTestInfo(::std::ostream* stream, const char* test_suite_name, @@ -4563,6 +4576,13 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, false); *stream << TestPropertiesAsJson(result, kIndent); + OutputJsonTestResult(stream, result); +} + +void JsonUnitTestResultPrinter::OutputJsonTestResult(::std::ostream* stream, + const TestResult& result) { + const std::string kIndent = Indent(10); + int failures = 0; for (int i = 0; i < result.total_part_count(); ++i) { const TestPartResult& part = result.GetTestPartResult(i); |