2015-08-24 21:38:09 -04:00
|
|
|
#include "make_unique.h"
|
2015-05-04 03:04:36 -04:00
|
|
|
#include "JUnitTestReportWriter.h"
|
|
|
|
#include "StdStreamUtils.h"
|
|
|
|
#include "xml/Writer.h"
|
|
|
|
#include "string_format.h"
|
|
|
|
|
2015-05-05 00:12:39 -04:00
|
|
|
CJUnitTestReportWriter::CJUnitTestReportWriter()
|
2015-05-04 03:04:36 -04:00
|
|
|
{
|
|
|
|
m_reportNode = std::make_unique<Framework::Xml::CNode>("", true);
|
2023-11-15 10:19:11 -05:00
|
|
|
auto testSuitesNode = m_reportNode->InsertNode(std::make_unique<Framework::Xml::CNode>("testsuites", true));
|
|
|
|
m_testSuiteNode = testSuitesNode->InsertNode(std::make_unique<Framework::Xml::CNode>("testsuite", true));
|
2015-05-04 03:04:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CJUnitTestReportWriter::~CJUnitTestReportWriter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-03 03:21:48 -04:00
|
|
|
void CJUnitTestReportWriter::ReportTestEntry(const std::string& testName, const TESTRESULT& result)
|
2015-05-04 03:04:36 -04:00
|
|
|
{
|
2023-11-15 10:19:11 -05:00
|
|
|
auto testCaseNode = std::make_unique<Framework::Xml::CNode>("testcase", true);
|
2015-05-04 03:04:36 -04:00
|
|
|
testCaseNode->InsertAttribute("name", testName.c_str());
|
|
|
|
|
2015-07-03 03:21:48 -04:00
|
|
|
if(!result.succeeded)
|
2015-05-04 03:04:36 -04:00
|
|
|
{
|
2015-07-03 03:21:48 -04:00
|
|
|
std::string failureDetails;
|
|
|
|
for(const auto& lineDiff : result.lineDiffs)
|
|
|
|
{
|
|
|
|
auto failureLine = string_format(
|
2018-04-30 21:01:23 +01:00
|
|
|
"result : %s\r\n"
|
|
|
|
"expected : %s\r\n"
|
|
|
|
"\r\n",
|
|
|
|
lineDiff.result.c_str(), lineDiff.expected.c_str());
|
2015-07-03 03:21:48 -04:00
|
|
|
failureDetails += failureLine;
|
|
|
|
}
|
2023-11-15 10:19:11 -05:00
|
|
|
auto resultNode = std::make_unique<Framework::Xml::CNode>("failure", true);
|
2015-07-03 03:21:48 -04:00
|
|
|
resultNode->InsertTextNode(failureDetails.c_str());
|
2023-11-15 10:19:11 -05:00
|
|
|
testCaseNode->InsertNode(std::move(resultNode));
|
2015-05-04 03:04:36 -04:00
|
|
|
}
|
|
|
|
|
2023-11-15 10:19:11 -05:00
|
|
|
m_testSuiteNode->InsertNode(std::move(testCaseNode));
|
2015-05-04 03:04:36 -04:00
|
|
|
|
|
|
|
m_testCount++;
|
|
|
|
}
|
2015-05-05 00:12:39 -04:00
|
|
|
|
2019-10-17 12:23:26 -04:00
|
|
|
void CJUnitTestReportWriter::Write(const fs::path& reportPath)
|
2015-05-05 00:12:39 -04:00
|
|
|
{
|
|
|
|
m_testSuiteNode->InsertAttribute("tests", string_format("%d", m_testCount).c_str());
|
|
|
|
auto testOutputFileStream = Framework::CreateOutputStdStream(reportPath.native());
|
|
|
|
Framework::Xml::CWriter::WriteDocument(testOutputFileStream, m_reportNode.get());
|
|
|
|
}
|