Prints a JSON summary of unit_test to output stream out.
| 4775 | |
| 4776 | // Prints a JSON summary of unit_test to output stream out. |
| 4777 | void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, |
| 4778 | const UnitTest& unit_test) { |
| 4779 | const std::string kTestsuites = "testsuites"; |
| 4780 | const std::string kIndent = Indent(2); |
| 4781 | *stream << "{\n"; |
| 4782 | |
| 4783 | OutputJsonKey(stream, kTestsuites, "tests", unit_test.reportable_test_count(), |
| 4784 | kIndent); |
| 4785 | OutputJsonKey(stream, kTestsuites, "failures", unit_test.failed_test_count(), |
| 4786 | kIndent); |
| 4787 | OutputJsonKey(stream, kTestsuites, "disabled", |
| 4788 | unit_test.reportable_disabled_test_count(), kIndent); |
| 4789 | OutputJsonKey(stream, kTestsuites, "errors", 0, kIndent); |
| 4790 | if (GTEST_FLAG_GET(shuffle)) { |
| 4791 | OutputJsonKey(stream, kTestsuites, "random_seed", unit_test.random_seed(), |
| 4792 | kIndent); |
| 4793 | } |
| 4794 | OutputJsonKey(stream, kTestsuites, "timestamp", |
| 4795 | FormatEpochTimeInMillisAsRFC3339(unit_test.start_timestamp()), |
| 4796 | kIndent); |
| 4797 | OutputJsonKey(stream, kTestsuites, "time", |
| 4798 | FormatTimeInMillisAsDuration(unit_test.elapsed_time()), kIndent, |
| 4799 | false); |
| 4800 | |
| 4801 | *stream << TestPropertiesAsJson(unit_test.ad_hoc_test_result(), kIndent) |
| 4802 | << ",\n"; |
| 4803 | |
| 4804 | OutputJsonKey(stream, kTestsuites, "name", "AllTests", kIndent); |
| 4805 | *stream << kIndent << "\"" << kTestsuites << "\": [\n"; |
| 4806 | |
| 4807 | bool comma = false; |
| 4808 | for (int i = 0; i < unit_test.total_test_suite_count(); ++i) { |
| 4809 | if (unit_test.GetTestSuite(i)->reportable_test_count() > 0) { |
| 4810 | if (comma) { |
| 4811 | *stream << ",\n"; |
| 4812 | } else { |
| 4813 | comma = true; |
| 4814 | } |
| 4815 | PrintJsonTestSuite(stream, *unit_test.GetTestSuite(i)); |
| 4816 | } |
| 4817 | } |
| 4818 | |
| 4819 | // If there was a test failure outside of one of the test suites (like in a |
| 4820 | // test environment) include that in the output. |
| 4821 | if (unit_test.ad_hoc_test_result().Failed()) { |
| 4822 | if (comma) { |
| 4823 | *stream << ",\n"; |
| 4824 | } |
| 4825 | OutputJsonTestSuiteForTestResult(stream, unit_test.ad_hoc_test_result()); |
| 4826 | } |
| 4827 | |
| 4828 | *stream << "\n" |
| 4829 | << kIndent << "]\n" |
| 4830 | << "}\n"; |
| 4831 | } |
| 4832 | |
| 4833 | void JsonUnitTestResultPrinter::PrintJsonTestList( |
| 4834 | std::ostream* stream, const std::vector<TestSuite*>& test_suites) { |
nothing calls this directly
no test coverage detected