Prints an XML representation of a TestInfo object.
| 5232 | |
| 5233 | // Prints an XML representation of a TestInfo object. |
| 5234 | void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, |
| 5235 | const char* test_suite_name, |
| 5236 | const TestInfo& test_info) { |
| 5237 | const TestResult& result = *test_info.result(); |
| 5238 | const std::string kTestsuite = "testcase"; |
| 5239 | |
| 5240 | if (test_info.is_in_another_shard()) { |
| 5241 | return; |
| 5242 | } |
| 5243 | |
| 5244 | *stream << " <testcase"; |
| 5245 | OutputXmlAttribute(stream, kTestsuite, "name", test_info.name()); |
| 5246 | |
| 5247 | if (test_info.value_param() != nullptr) { |
| 5248 | OutputXmlAttribute(stream, kTestsuite, "value_param", |
| 5249 | test_info.value_param()); |
| 5250 | } |
| 5251 | if (test_info.type_param() != nullptr) { |
| 5252 | OutputXmlAttribute(stream, kTestsuite, "type_param", |
| 5253 | test_info.type_param()); |
| 5254 | } |
| 5255 | if (GTEST_FLAG(list_tests)) { |
| 5256 | OutputXmlAttribute(stream, kTestsuite, "file", test_info.file()); |
| 5257 | OutputXmlAttribute(stream, kTestsuite, "line", |
| 5258 | StreamableToString(test_info.line())); |
| 5259 | *stream << " />\n"; |
| 5260 | return; |
| 5261 | } |
| 5262 | |
| 5263 | OutputXmlAttribute(stream, kTestsuite, "status", |
| 5264 | test_info.should_run() ? "run" : "notrun"); |
| 5265 | OutputXmlAttribute(stream, kTestsuite, "result", |
| 5266 | test_info.should_run() |
| 5267 | ? (result.Skipped() ? "skipped" : "completed") |
| 5268 | : "suppressed"); |
| 5269 | OutputXmlAttribute(stream, kTestsuite, "time", |
| 5270 | FormatTimeInMillisAsSeconds(result.elapsed_time())); |
| 5271 | OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name); |
| 5272 | |
| 5273 | int failures = 0; |
| 5274 | for (int i = 0; i < result.total_part_count(); ++i) { |
| 5275 | const TestPartResult& part = result.GetTestPartResult(i); |
| 5276 | if (part.failed()) { |
| 5277 | if (++failures == 1) { |
| 5278 | *stream << ">\n"; |
| 5279 | } |
| 5280 | const std::string location = |
| 5281 | internal::FormatCompilerIndependentFileLocation(part.file_name(), |
| 5282 | part.line_number()); |
| 5283 | const std::string summary = location + "\n" + part.summary(); |
| 5284 | *stream << " <failure message=\"" |
| 5285 | << EscapeXmlAttribute(summary.c_str()) |
| 5286 | << "\" type=\"\">"; |
| 5287 | const std::string detail = location + "\n" + part.message(); |
| 5288 | OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); |
| 5289 | *stream << "</failure>\n"; |
| 5290 | } |
| 5291 | } |
nothing calls this directly
no test coverage detected