mirror of
https://github.com/libretro/Play-.git
synced 2025-01-24 01:54:59 +00:00
Added more details to JUnit reports in AutoTest.
This commit is contained in:
parent
1109a1c28f
commit
a95be1ee5c
@ -18,14 +18,25 @@ CJUnitTestReportWriter::~CJUnitTestReportWriter()
|
||||
|
||||
}
|
||||
|
||||
void CJUnitTestReportWriter::ReportTestEntry(const std::string& testName, bool succeeded)
|
||||
void CJUnitTestReportWriter::ReportTestEntry(const std::string& testName, const TESTRESULT& result)
|
||||
{
|
||||
auto testCaseNode = new Framework::Xml::CNode("testcase", true);
|
||||
testCaseNode->InsertAttribute("name", testName.c_str());
|
||||
|
||||
if(!succeeded)
|
||||
if(!result.succeeded)
|
||||
{
|
||||
std::string failureDetails;
|
||||
for(const auto& lineDiff : result.lineDiffs)
|
||||
{
|
||||
auto failureLine = string_format(
|
||||
"result : %s\r\n"
|
||||
"expected : %s\r\n"
|
||||
"\r\n",
|
||||
lineDiff.result.c_str(), lineDiff.expected.c_str());
|
||||
failureDetails += failureLine;
|
||||
}
|
||||
auto resultNode = new Framework::Xml::CNode("failure", true);
|
||||
resultNode->InsertTextNode(failureDetails.c_str());
|
||||
testCaseNode->InsertNode(resultNode);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
CJUnitTestReportWriter();
|
||||
virtual ~CJUnitTestReportWriter();
|
||||
|
||||
void ReportTestEntry(const std::string&, bool) override;
|
||||
void ReportTestEntry(const std::string&, const TESTRESULT&) override;
|
||||
void Write(const boost::filesystem::path&) override;
|
||||
|
||||
private:
|
||||
|
@ -16,8 +16,10 @@ std::vector<std::string> ReadLines(Framework::CStream& inputStream)
|
||||
return lines;
|
||||
}
|
||||
|
||||
bool CompareResults(const boost::filesystem::path& testFilePath)
|
||||
TESTRESULT GetTestResult(const boost::filesystem::path& testFilePath)
|
||||
{
|
||||
TESTRESULT result;
|
||||
result.succeeded = false;
|
||||
try
|
||||
{
|
||||
auto resultFilePath = testFilePath;
|
||||
@ -30,19 +32,27 @@ bool CompareResults(const boost::filesystem::path& testFilePath)
|
||||
auto resultLines = ReadLines(resultStream);
|
||||
auto expectedLines = ReadLines(expectedStream);
|
||||
|
||||
if(resultLines.size() != expectedLines.size()) return false;
|
||||
if(resultLines.size() != expectedLines.size()) return result;
|
||||
|
||||
for(unsigned int i = 0; i < resultLines.size(); i++)
|
||||
{
|
||||
if(resultLines[i] != expectedLines[i]) return false;
|
||||
if(resultLines[i] != expectedLines[i])
|
||||
{
|
||||
LINEDIFF lineDiff;
|
||||
lineDiff.expected = expectedLines[i];
|
||||
lineDiff.result = resultLines[i];
|
||||
result.lineDiffs.push_back(lineDiff);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
result.succeeded = result.lineDiffs.empty();
|
||||
return result;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ExecuteTest(const boost::filesystem::path& testFilePath)
|
||||
@ -92,11 +102,11 @@ void ScanAndExecuteTests(const boost::filesystem::path& testDirPath, const TestR
|
||||
{
|
||||
printf("Testing '%s': ", testPath.string().c_str());
|
||||
ExecuteTest(testPath);
|
||||
bool succeeded = CompareResults(testPath);
|
||||
printf("%s.\r\n", succeeded ? "SUCCEEDED" : "FAILED");
|
||||
auto result = GetTestResult(testPath);
|
||||
printf("%s.\r\n", result.succeeded ? "SUCCEEDED" : "FAILED");
|
||||
if(testReportWriter)
|
||||
{
|
||||
testReportWriter->ReportTestEntry(testPath.string(), succeeded);
|
||||
testReportWriter->ReportTestEntry(testPath.string(), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,26 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
struct LINEDIFF
|
||||
{
|
||||
std::string expected;
|
||||
std::string result;
|
||||
};
|
||||
|
||||
struct TESTRESULT
|
||||
{
|
||||
typedef std::vector<LINEDIFF> LineDiffArray;
|
||||
|
||||
bool succeeded = false;
|
||||
LineDiffArray lineDiffs;
|
||||
};
|
||||
|
||||
class CTestReportWriter
|
||||
{
|
||||
public:
|
||||
virtual ~CTestReportWriter() {}
|
||||
|
||||
virtual void ReportTestEntry(const std::string& name, bool succeeded) = 0;
|
||||
virtual void ReportTestEntry(const std::string& name, const TESTRESULT&) = 0;
|
||||
virtual void Write(const boost::filesystem::path& reportPath) = 0;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user