Skip to content

Commit 8df7c6e

Browse files
committed
Allow TestOnly attribute on multiple tests. Fix test filtration
1 parent 42fecf7 commit 8df7c6e

File tree

3 files changed

+27
-46
lines changed

3 files changed

+27
-46
lines changed

source/vox/tests/infra/runner.d

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,21 @@ import vox.tests.tests;
1313
@nogc nothrow:
1414

1515
i32 runTests(ref TestSuite suite) {
16-
u32 numTests;
17-
if (suite.filter.enabled) {
18-
foreach(ref test; suite.tests) {
19-
if (suite.filter.shouldRun(test)) {
20-
++numTests;
21-
}
22-
}
23-
24-
writefln("Selected %s of %s tests to run", numTests, suite.tests.length);
16+
if (suite.isFilterEnabled) {
17+
writefln("Selected %s of %s tests to run", suite.numTestsToRun, suite.tests.length);
2518
} else {
26-
numTests = cast(u32)suite.tests.length;
27-
writefln("Running %s tests", suite.tests.length);
19+
writefln("Running all %s tests", suite.numTestsToRun);
2820
}
2921

30-
// Warmup (first run does all the allocations and memory faults)
31-
//if (suite.filter.disabled && suite.tests.length) {
32-
// context.runTest(suite.tests[0]);
33-
// context.runTest(suite.tests[0]);
34-
// context.runTest(suite.tests[0]);
35-
//}
36-
// End warmup
37-
3822
MonoTime start = currTime;
3923
foreach(ref test; suite.tests) {
40-
auto context = suite.contexts[test.contextIndex];
41-
context.runTest(test);
24+
if (!suite.isFilterEnabled || test.onlyThis) {
25+
auto context = suite.contexts[test.contextIndex];
26+
context.runTest(test);
27+
}
4228
}
4329
MonoTime end = currTime;
44-
writefln("Done %s tests in %s", suite.tests.length, end - start);
30+
writefln("Done %s tests in %s", suite.numTestsToRun, end - start);
4531

4632
return 0;
4733
}

source/vox/tests/infra/test.d

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ struct TestSuite {
1717
Array!TestDefinition definitions;
1818
// test permutations
1919
Array!TestInstance tests;
20-
TestFilter filter;
20+
u32 numOnlyInstances;
21+
22+
bool isFilterEnabled() => numOnlyInstances != 0;
23+
24+
u32 numTestsToRun() {
25+
if (isFilterEnabled) {
26+
return numOnlyInstances;
27+
} else {
28+
return tests.length;
29+
}
30+
}
2131

2232
u8 registerContext(ref VoxAllocator allocator, ITestContext context) {
2333
foreach(i, c; contexts) {
@@ -76,6 +86,8 @@ struct TestInstance {
7686
u32 index;
7787
// Index into TestSuite.contexts
7888
u8 contextIndex;
89+
// @TestOnly
90+
bool onlyThis;
7991

8092
PtrSize ptrSize() {
8193
return cast(PtrSize)getParam(TestParamId.ptr_size);
@@ -93,15 +105,3 @@ struct TestInstance {
93105
u32 value;
94106
}
95107
}
96-
97-
struct TestFilter {
98-
@nogc nothrow:
99-
100-
bool enabled = false;
101-
bool disabled() => !enabled;
102-
bool shouldRun(ref TestInstance test) {
103-
return definition == test.definition;
104-
}
105-
106-
u32 definition;
107-
}

source/vox/tests/infra/test_maker.d

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@ static struct MakerParam {
6666
void instantiateTest(ref VoxAllocator allocator, ref TestSuite suite, TestDefinition def) {
6767
if (def.ignore) return;
6868

69-
if (def.onlyThis) {
70-
if (suite.filter.enabled) {
71-
auto otherDef = suite.definitions[suite.filter.definition];
72-
panic("TestOnly attribute found in multiple places:\n %s at %s:%s\n %s at %s:%s\n",
73-
otherDef.name, otherDef.file, otherDef.line,
74-
def.name, def.file, def.line);
75-
}
76-
suite.filter.definition = def.index;
77-
suite.filter.enabled = true;
78-
}
79-
8069
ITestContext context = suite.contexts[def.contextIndex];
8170

8271
u32 numPermutations = 1;
@@ -128,9 +117,15 @@ void instantiateTest(ref VoxAllocator allocator, ref TestSuite suite, TestDefini
128117
test_handler : def.test_handler,
129118
parameters : testParameters,
130119
contextIndex : def.contextIndex,
120+
onlyThis : def.onlyThis,
131121
};
132122
suite.tests.put(allocator, t);
133123

124+
// How many filtered tests should run
125+
if (def.onlyThis) {
126+
++suite.numOnlyInstances;
127+
}
128+
134129
// increment
135130
foreach(ref param; parameters) {
136131
// treat each parameter as a digit in a number

0 commit comments

Comments
 (0)