MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / OutputJsonTestInfo

Method OutputJsonTestInfo

tests/gtest/gtest-all.cc:5607–5667  ·  view source on GitHub ↗

Prints a JSON representation of a TestInfo object.

Source from the content-addressed store, hash-verified

5605
5606// Prints a JSON representation of a TestInfo object.
5607void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
5608 const char* test_suite_name,
5609 const TestInfo& test_info) {
5610 const TestResult& result = *test_info.result();
5611 const std::string kTestsuite = "testcase";
5612 const std::string kIndent = Indent(10);
5613
5614 *stream << Indent(8) << "{\n";
5615 OutputJsonKey(stream, kTestsuite, "name", test_info.name(), kIndent);
5616
5617 if (test_info.value_param() != nullptr) {
5618 OutputJsonKey(stream, kTestsuite, "value_param", test_info.value_param(),
5619 kIndent);
5620 }
5621 if (test_info.type_param() != nullptr) {
5622 OutputJsonKey(stream, kTestsuite, "type_param", test_info.type_param(),
5623 kIndent);
5624 }
5625 if (GTEST_FLAG(list_tests)) {
5626 OutputJsonKey(stream, kTestsuite, "file", test_info.file(), kIndent);
5627 OutputJsonKey(stream, kTestsuite, "line", test_info.line(), kIndent, false);
5628 *stream << "\n" << Indent(8) << "}";
5629 return;
5630 }
5631
5632 OutputJsonKey(stream, kTestsuite, "status",
5633 test_info.should_run() ? "RUN" : "NOTRUN", kIndent);
5634 OutputJsonKey(stream, kTestsuite, "result",
5635 test_info.should_run()
5636 ? (result.Skipped() ? "SKIPPED" : "COMPLETED")
5637 : "SUPPRESSED",
5638 kIndent);
5639 OutputJsonKey(stream, kTestsuite, "time",
5640 FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
5641 OutputJsonKey(stream, kTestsuite, "classname", test_suite_name, kIndent,
5642 false);
5643 *stream << TestPropertiesAsJson(result, kIndent);
5644
5645 int failures = 0;
5646 for (int i = 0; i < result.total_part_count(); ++i) {
5647 const TestPartResult& part = result.GetTestPartResult(i);
5648 if (part.failed()) {
5649 *stream << ",\n";
5650 if (++failures == 1) {
5651 *stream << kIndent << "\"" << "failures" << "\": [\n";
5652 }
5653 const std::string location =
5654 internal::FormatCompilerIndependentFileLocation(part.file_name(),
5655 part.line_number());
5656 const std::string message = EscapeJson(location + "\n" + part.message());
5657 *stream << kIndent << " {\n"
5658 << kIndent << " \"failure\": \"" << message << "\",\n"
5659 << kIndent << " \"type\": \"\"\n"
5660 << kIndent << " }";
5661 }
5662 }
5663
5664 if (failures > 0)

Callers

nothing calls this directly

Calls 7

IndentFunction · 0.85
lineMethod · 0.80
SkippedMethod · 0.80
elapsed_timeMethod · 0.80
total_part_countMethod · 0.80

Tested by

no test coverage detected