Web assembly #6
1 changed files with 80 additions and 4 deletions
|
|
@ -6,8 +6,14 @@ import core.stdc.string;
|
|||
import core.sys.posix.setjmp;
|
||||
|
||||
import ecs.vector;
|
||||
import ecs.simple_vector;
|
||||
import ecs.std;
|
||||
|
||||
unittest
|
||||
{
|
||||
assert(0,"This will fail!");
|
||||
}
|
||||
|
||||
enum int ASSERTED = 123;
|
||||
enum string OUT_FILE = "test_report.xml";
|
||||
|
||||
|
|
@ -33,9 +39,10 @@ struct Test
|
|||
string msg;
|
||||
int fileLine;
|
||||
string name;
|
||||
//string classname;
|
||||
int time;
|
||||
bool passed;
|
||||
bool executed;
|
||||
//bool executed;
|
||||
}
|
||||
|
||||
struct TestSuite
|
||||
|
|
@ -87,8 +94,8 @@ void writeResult(ref TestSuite suite, ref Test result)
|
|||
writeToFile("\" time=\"");
|
||||
writeToFile(result.time);
|
||||
writeToFile("\" ");
|
||||
writeToFile(" executed=\"");
|
||||
writeToFile(cast(int) result.executed);
|
||||
//writeToFile(" executed=\"");
|
||||
//writeToFile(cast(int) result.executed);
|
||||
writeToFile("\" ");
|
||||
|
||||
if (result.passed)
|
||||
|
|
@ -147,6 +154,71 @@ struct TestRunner(Args...)
|
|||
uint passed = 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()
|
||||
{
|
||||
foreach(i, module_; Args)
|
||||
|
|
@ -189,7 +261,11 @@ struct TestRunner(Args...)
|
|||
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue