MCPcopy Create free account
hub / github.com/Compaile/ctrack / XmlReporter

Class XmlReporter

test/doctest.h:5440–5673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5438 // clang-format on
5439
5440 struct XmlReporter : public IReporter
5441 {
5442 XmlWriter xml;
5443 DOCTEST_DECLARE_MUTEX(mutex)
5444
5445 // caching pointers/references to objects of these types - safe to do
5446 const ContextOptions& opt;
5447 const TestCaseData* tc = nullptr;
5448
5449 XmlReporter(const ContextOptions& co)
5450 : xml(*co.cout)
5451 , opt(co) {}
5452
5453 void log_contexts() {
5454 int num_contexts = get_num_active_contexts();
5455 if(num_contexts) {
5456 auto contexts = get_active_contexts();
5457 std::stringstream ss;
5458 for(int i = 0; i < num_contexts; ++i) {
5459 contexts[i]->stringify(&ss);
5460 xml.scopedElement("Info").writeText(ss.str());
5461 ss.str("");
5462 }
5463 }
5464 }
5465
5466 unsigned line(unsigned l) const { return opt.no_line_numbers ? 0 : l; }
5467
5468 void test_case_start_impl(const TestCaseData& in) {
5469 bool open_ts_tag = false;
5470 if(tc != nullptr) { // we have already opened a test suite
5471 if(std::strcmp(tc->m_test_suite, in.m_test_suite) != 0) {
5472 xml.endElement();
5473 open_ts_tag = true;
5474 }
5475 }
5476 else {
5477 open_ts_tag = true; // first test case ==> first test suite
5478 }
5479
5480 if(open_ts_tag) {
5481 xml.startElement("TestSuite");
5482 xml.writeAttribute("name", in.m_test_suite);
5483 }
5484
5485 tc = &in;
5486 xml.startElement("TestCase")
5487 .writeAttribute("name", in.m_name)
5488 .writeAttribute("filename", skipPathFromFilename(in.m_file.c_str()))
5489 .writeAttribute("line", line(in.m_line))
5490 .writeAttribute("description", in.m_description);
5491
5492 if(Approx(in.m_timeout) != 0)
5493 xml.writeAttribute("timeout", in.m_timeout);
5494 if(in.m_may_fail)
5495 xml.writeAttribute("may_fail", true);
5496 if(in.m_should_fail)
5497 xml.writeAttribute("should_fail", true);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected