-added some tests
-improved test runner
This commit is contained in:
parent
19687b9f88
commit
c63f3a9727
6 changed files with 147 additions and 47 deletions
|
|
@ -16,9 +16,9 @@ unittest
|
|||
enum int ASSERTED = 123;
|
||||
enum string OUT_FILE = "test_report.xml";
|
||||
|
||||
__gshared jmp_buf gEnvBuffer;
|
||||
__gshared TestSuite[2] gSuites;
|
||||
__gshared AssertInfo gAssertInfo;
|
||||
static jmp_buf gEnvBuffer;
|
||||
//__gshared TestSuite[4] gSuites;
|
||||
static AssertInfo gAssertInfo;
|
||||
|
||||
struct AssertInfo
|
||||
{
|
||||
|
|
@ -47,6 +47,8 @@ struct Test
|
|||
struct TestSuite
|
||||
{
|
||||
string name;
|
||||
uint passed = 0;
|
||||
uint failed = 0;
|
||||
Vector!Test tests;
|
||||
}
|
||||
|
||||
|
|
@ -193,15 +195,89 @@ void addTestSuite(alias testModule)(ref TestSuite suite)
|
|||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
struct TestRunner(Args...)
|
||||
{
|
||||
addTestSuite!(tests.runner)(gSuites[0]);
|
||||
addTestSuite!(ecs.id_manager)(gSuites[1]);
|
||||
TestSuite[Args.length] suites;
|
||||
uint passed = 0;
|
||||
uint failed = 0;
|
||||
|
||||
writeTests(gSuites); // Save results in case that there are no tests
|
||||
void runTests()
|
||||
{
|
||||
foreach(i, module_; Args)
|
||||
{
|
||||
TestSuite* suite = &suites[i];
|
||||
suite.name = module_.stringof;
|
||||
foreach (index, unittest_; __traits(getUnitTests, module_))
|
||||
{
|
||||
enum attributes = __traits(getAttributes, unittest_);
|
||||
Test test;
|
||||
|
||||
runTestSuite!(tests.runner)(gSuites[0]);
|
||||
runTestSuite!(ecs.id_manager)(gSuites[1]);
|
||||
static if (attributes.length == 0)test.name = "None";
|
||||
else test.name = attributes[0];
|
||||
|
||||
writeTests(gSuites); // Save result of last test
|
||||
// Save calling environment for longjmp
|
||||
int jmpRet = setjmp(gEnvBuffer);
|
||||
|
||||
if (jmpRet == ASSERTED)
|
||||
{
|
||||
passed = false;
|
||||
test.passed = false;
|
||||
test.file = copyString(gAssertInfo.file);
|
||||
test.fileLine = gAssertInfo.line;
|
||||
test.msg = copyString(gAssertInfo.msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
unittest_();
|
||||
test.passed = true;
|
||||
}
|
||||
|
||||
if(test.passed)suite.passed++;
|
||||
else suite.failed++;
|
||||
suite.tests ~= test;
|
||||
}
|
||||
passed += suite.passed;
|
||||
failed += suite.failed;
|
||||
}
|
||||
}
|
||||
|
||||
void writeFile()
|
||||
{
|
||||
writeTests(suites);
|
||||
}
|
||||
|
||||
void writeOutput()
|
||||
{
|
||||
import core.stdc.stdio;
|
||||
foreach(ref TestSuite suite; suites)
|
||||
{
|
||||
printf("Suite: \"%s\" Passed: %u/%u\n", suite.name.ptr, suite.passed, suite.passed + suite.failed);
|
||||
foreach(ref Test test;suite.tests)
|
||||
{
|
||||
if(!test.passed)
|
||||
{
|
||||
printf("\tTest: \"%s\" Failed! Line: %u Message: %s\n",test.name.ptr, test.fileLine, test.msg.ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Passed: %u/%u tests.\n", passed, passed+failed);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
import tests.vector;
|
||||
import tests.id_manager;
|
||||
import tests.basic;
|
||||
|
||||
TestRunner!(tests.runner, tests.id_manager, tests.vector, tests.basic) runner;
|
||||
|
||||
runner.runTests();
|
||||
|
||||
runner.writeFile();
|
||||
|
||||
runner.writeOutput();
|
||||
|
||||
if(!runner.failed)return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue