-added some tests
-improved test runner
This commit is contained in:
parent
19687b9f88
commit
c63f3a9727
6 changed files with 147 additions and 47 deletions
10
dub.json
10
dub.json
|
|
@ -17,7 +17,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "tests",
|
"name" : "tests",
|
||||||
"sourcePaths" : ["source\/","tests\/"],
|
"sourceFiles" : ["tests/tests.d"],
|
||||||
"targetType" : "executable",
|
"targetType" : "executable",
|
||||||
"excludedSourceFiles":[
|
"excludedSourceFiles":[
|
||||||
"source\/win_dll.d"
|
"source\/win_dll.d"
|
||||||
|
|
@ -91,11 +91,11 @@
|
||||||
"dflags": [
|
"dflags": [
|
||||||
"-betterC"
|
"-betterC"
|
||||||
],
|
],
|
||||||
"sourceFiles":[
|
"sourcePaths": ["source/","tests/"],
|
||||||
"tests/runner.d"
|
"mainSourceFile":"tests/runner.d",
|
||||||
],
|
|
||||||
"excludedSourceFiles":[
|
"excludedSourceFiles":[
|
||||||
"source\/win_dll.d"
|
"source\/win_dll.d",
|
||||||
|
"tests/tests.d"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,35 +253,3 @@ private:
|
||||||
align(64) shared uint m_last_id = 0;
|
align(64) shared uint m_last_id = 0;
|
||||||
align(64) shared int m_stack_top = -1;
|
align(64) shared int m_stack_top = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
|
||||||
{
|
|
||||||
IDManager manager;
|
|
||||||
manager.initialize();
|
|
||||||
EntityID id1 = manager.getNewID();
|
|
||||||
EntityID id2 = manager.getNewID();
|
|
||||||
EntityID id3 = manager.getNewID();
|
|
||||||
|
|
||||||
assert(id1 == EntityID(1, 0));
|
|
||||||
assert(id2 == EntityID(2, 0));
|
|
||||||
assert(id3 == EntityID(3, 0));
|
|
||||||
|
|
||||||
manager.optimize();
|
|
||||||
manager.releaseID(id2);
|
|
||||||
manager.releaseID(id1);
|
|
||||||
|
|
||||||
id2 = manager.getNewID();
|
|
||||||
id1 = manager.getNewID();
|
|
||||||
|
|
||||||
Entity e;
|
|
||||||
e.id = id3;
|
|
||||||
manager.update(e);
|
|
||||||
|
|
||||||
assert(id1 == EntityID(2, 1));
|
|
||||||
assert(id2 == EntityID(1, 1));
|
|
||||||
assert(id3 == EntityID(3, 0));
|
|
||||||
assert(manager.isExist(id3));
|
|
||||||
assert(!manager.isExist(EntityID(1, 0)));
|
|
||||||
assert(!manager.isExist(EntityID(0, 0)));
|
|
||||||
manager.deinitialize();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
2
tests/basic.d
Normal file
2
tests/basic.d
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
module tests.basic;
|
||||||
|
|
||||||
36
tests/id_manager.d
Normal file
36
tests/id_manager.d
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
module tests.id_manager;
|
||||||
|
|
||||||
|
import ecs.id_manager;
|
||||||
|
import ecs.entity;
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
IDManager manager;
|
||||||
|
manager.initialize();
|
||||||
|
EntityID id1 = manager.getNewID();
|
||||||
|
EntityID id2 = manager.getNewID();
|
||||||
|
EntityID id3 = manager.getNewID();
|
||||||
|
|
||||||
|
assert(id1 == EntityID(1, 0));
|
||||||
|
assert(id2 == EntityID(2, 0));
|
||||||
|
assert(id3 == EntityID(3, 0));
|
||||||
|
|
||||||
|
manager.optimize();
|
||||||
|
manager.releaseID(id2);
|
||||||
|
manager.releaseID(id1);
|
||||||
|
|
||||||
|
id2 = manager.getNewID();
|
||||||
|
id1 = manager.getNewID();
|
||||||
|
|
||||||
|
Entity e;
|
||||||
|
e.id = id3;
|
||||||
|
manager.update(e);
|
||||||
|
|
||||||
|
assert(id1 == EntityID(2, 1));
|
||||||
|
assert(id2 == EntityID(1, 1));
|
||||||
|
assert(id3 == EntityID(3, 0));
|
||||||
|
assert(manager.isExist(id3));
|
||||||
|
assert(!manager.isExist(EntityID(1, 0)));
|
||||||
|
assert(!manager.isExist(EntityID(0, 0)));
|
||||||
|
manager.deinitialize();
|
||||||
|
}
|
||||||
|
|
@ -16,9 +16,9 @@ unittest
|
||||||
enum int ASSERTED = 123;
|
enum int ASSERTED = 123;
|
||||||
enum string OUT_FILE = "test_report.xml";
|
enum string OUT_FILE = "test_report.xml";
|
||||||
|
|
||||||
__gshared jmp_buf gEnvBuffer;
|
static jmp_buf gEnvBuffer;
|
||||||
__gshared TestSuite[2] gSuites;
|
//__gshared TestSuite[4] gSuites;
|
||||||
__gshared AssertInfo gAssertInfo;
|
static AssertInfo gAssertInfo;
|
||||||
|
|
||||||
struct AssertInfo
|
struct AssertInfo
|
||||||
{
|
{
|
||||||
|
|
@ -47,6 +47,8 @@ struct Test
|
||||||
struct TestSuite
|
struct TestSuite
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
|
uint passed = 0;
|
||||||
|
uint failed = 0;
|
||||||
Vector!Test tests;
|
Vector!Test tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,15 +195,89 @@ void addTestSuite(alias testModule)(ref TestSuite suite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
struct TestRunner(Args...)
|
||||||
{
|
{
|
||||||
addTestSuite!(tests.runner)(gSuites[0]);
|
TestSuite[Args.length] suites;
|
||||||
addTestSuite!(ecs.id_manager)(gSuites[1]);
|
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]);
|
static if (attributes.length == 0)test.name = "None";
|
||||||
runTestSuite!(ecs.id_manager)(gSuites[1]);
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
tests/vector.d
Normal file
18
tests/vector.d
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
module tests.vector;
|
||||||
|
|
||||||
|
import ecs.simple_vector;
|
||||||
|
//import ecs.vector;
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
SimpleVector vector;
|
||||||
|
vector.add(cast(ubyte[])"a");
|
||||||
|
vector.add(cast(ubyte[])"bsdf");
|
||||||
|
assert(vector[0..5] == cast(ubyte[])"absdf");
|
||||||
|
assert(vector[4] == 'f');
|
||||||
|
assert(vector[] == cast(ubyte[])"absdf");
|
||||||
|
assert(vector[$ - 1] == 'f');
|
||||||
|
|
||||||
|
vector.clear();
|
||||||
|
assert(vector.length == 0);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue