-better JUnit generation
-testing unittest failure
This commit is contained in:
parent
09633d1056
commit
d485824ab5
1 changed files with 80 additions and 4 deletions
|
|
@ -6,8 +6,14 @@ import core.stdc.string;
|
||||||
import core.sys.posix.setjmp;
|
import core.sys.posix.setjmp;
|
||||||
|
|
||||||
import ecs.vector;
|
import ecs.vector;
|
||||||
|
import ecs.simple_vector;
|
||||||
import ecs.std;
|
import ecs.std;
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
assert(0,"This will fail!");
|
||||||
|
}
|
||||||
|
|
||||||
enum int ASSERTED = 123;
|
enum int ASSERTED = 123;
|
||||||
enum string OUT_FILE = "test_report.xml";
|
enum string OUT_FILE = "test_report.xml";
|
||||||
|
|
||||||
|
|
@ -33,9 +39,10 @@ struct Test
|
||||||
string msg;
|
string msg;
|
||||||
int fileLine;
|
int fileLine;
|
||||||
string name;
|
string name;
|
||||||
|
//string classname;
|
||||||
int time;
|
int time;
|
||||||
bool passed;
|
bool passed;
|
||||||
bool executed;
|
//bool executed;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestSuite
|
struct TestSuite
|
||||||
|
|
@ -87,8 +94,8 @@ void writeResult(ref TestSuite suite, ref Test result)
|
||||||
writeToFile("\" time=\"");
|
writeToFile("\" time=\"");
|
||||||
writeToFile(result.time);
|
writeToFile(result.time);
|
||||||
writeToFile("\" ");
|
writeToFile("\" ");
|
||||||
writeToFile(" executed=\"");
|
//writeToFile(" executed=\"");
|
||||||
writeToFile(cast(int) result.executed);
|
//writeToFile(cast(int) result.executed);
|
||||||
writeToFile("\" ");
|
writeToFile("\" ");
|
||||||
|
|
||||||
if (result.passed)
|
if (result.passed)
|
||||||
|
|
@ -147,6 +154,71 @@ struct TestRunner(Args...)
|
||||||
uint passed = 0;
|
uint passed = 0;
|
||||||
uint failed = 0;
|
uint failed = 0;
|
||||||
|
|
||||||
|
SimpleVector junit;
|
||||||
|
|
||||||
|
void write(string txt)
|
||||||
|
{
|
||||||
|
junit.add(cast(ubyte[]) txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(uint num)
|
||||||
|
{
|
||||||
|
ubyte[20] buffer;
|
||||||
|
int len;
|
||||||
|
len = sprintf(cast(char*)buffer.ptr, "%u", num);
|
||||||
|
junit.add(buffer[0..len]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateJUnit()
|
||||||
|
{
|
||||||
|
write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
|
||||||
|
|
||||||
|
write("<testsuites tests=\"");
|
||||||
|
write(passed + failed);
|
||||||
|
write("\" failures=\"");
|
||||||
|
write(failed);
|
||||||
|
write("\">\n");
|
||||||
|
|
||||||
|
foreach(ref TestSuite suite; suites)
|
||||||
|
{
|
||||||
|
write("\t<testsuite name=\"");
|
||||||
|
write(suite.name);
|
||||||
|
write("\" tests=\"");
|
||||||
|
write(suite.passed + suite.failed);
|
||||||
|
write("\" failures=\"");
|
||||||
|
write(suite.failed);
|
||||||
|
write("\">\n");
|
||||||
|
|
||||||
|
foreach(ref Test test; suite.tests)
|
||||||
|
{
|
||||||
|
write("\t\t<testcase name=\"");
|
||||||
|
write(test.name);
|
||||||
|
write("\" classname=\"");
|
||||||
|
write(suite.name);
|
||||||
|
write("\">\n");
|
||||||
|
if(test.msg)
|
||||||
|
{
|
||||||
|
write("\t\t\t<failure type=\"Fail\" message=\"");
|
||||||
|
write(test.msg[0 .. $ - 1]);
|
||||||
|
write("\">\n");
|
||||||
|
write("\t\t\t\tAssert! File: ");
|
||||||
|
write(test.file[0 .. $ - 1]);
|
||||||
|
write(":");
|
||||||
|
write(test.fileLine);
|
||||||
|
write(" Message: ");
|
||||||
|
write(test.msg[0 .. $ - 1]);
|
||||||
|
write("\n");
|
||||||
|
write("\t\t\t</failure>\n");
|
||||||
|
}
|
||||||
|
write("\t\t</testcase>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
write("\t</testsuite>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
write("</testsuites>");
|
||||||
|
}
|
||||||
|
|
||||||
void runTests()
|
void runTests()
|
||||||
{
|
{
|
||||||
foreach(i, module_; Args)
|
foreach(i, module_; Args)
|
||||||
|
|
@ -189,7 +261,11 @@ struct TestRunner(Args...)
|
||||||
|
|
||||||
void writeFile()
|
void writeFile()
|
||||||
{
|
{
|
||||||
writeTests(suites);
|
if(junit.length == 0)generateJUnit();
|
||||||
|
auto file = fopen(OUT_FILE, "w");
|
||||||
|
fwrite(junit.data.ptr,junit.length,1,file);
|
||||||
|
fclose(file);
|
||||||
|
//writeTests(suites);
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeOutput()
|
void writeOutput()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue