Skip to content

Commit 314ce34

Browse files
committed
Fix #321 - don't pick up tests from other modules via aliases
1 parent 2509a5f commit 314ce34

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

subpackages/runner/source/unit_threaded/runner/reflection.d

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ private TestData[] moduleUnitTests_(alias module_)() {
263263

264264
void addUnitTestsRecursively(alias composite)() pure nothrow {
265265

266+
import std.traits: moduleName;
267+
266268
if (composite.mangleof in visitedMembers)
267269
return;
268270

@@ -272,25 +274,30 @@ private TestData[] moduleUnitTests_(alias module_)() {
272274
foreach(member; __traits(allMembers, composite)) {
273275

274276
static if (
275-
// If visibility of the member is deprecated, the next line still returns true
276-
// and yet spills deprecation warning. If deprecation is turned into error,
277-
// all works as intended.
277+
// If visibility of the member is deprecated, the next
278+
// line still returns true and yet spills deprecation
279+
// warning. If deprecation is turned into error, all
280+
// works as intended.
278281
__traits(compiles, __traits(getMember, composite, member)) &&
279282
__traits(compiles, __traits(allMembers, __traits(getMember, composite, member))) &&
280-
__traits(compiles, recurse!(__traits(getMember, composite, member)))
283+
__traits(compiles, recurse!(__traits(getMember, composite, member))) &&
284+
moduleName!composite == moduleName!(__traits(getMember, composite, member))
285+
281286
) {
282287
recurse!(__traits(getMember, composite, member));
283288
}
284289
}
285290
}
286291

292+
287293
void recurse(child)() pure nothrow {
288294
static if (is(child == class) || is(child == struct) || is(child == union)) {
289295
addUnitTestsRecursively!child;
290296
}
291297
}
292298

293299
addUnitTestsRecursively!module_();
300+
294301
return testData;
295302
}
296303

tests/unit_threaded/ut/issues.d

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,26 @@ else {
414414
nested().length.should == 0;
415415
}
416416
}
417+
418+
419+
version(unitThreadedLight) {}
420+
else {
421+
@("321")
422+
@system unittest {
423+
424+
import unit_threaded.runner.factory: createTestCases;
425+
import std.algorithm: find, canFind;
426+
import std.array: front;
427+
428+
enum testModule = "unit_threaded.ut.modules.issue321_helper";
429+
430+
const testData = allTestData!(
431+
"unit_threaded.ut.modules.issue321",
432+
"unit_threaded.ut.modules.issue321_helper",
433+
);
434+
auto tests = createTestCases(testData);
435+
// there's only one unittest, and the bug was that it was
436+
// being picked up twice due to an alias.
437+
tests.length.should == 1;
438+
}
439+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module unit_threaded.ut.modules.issue321;
2+
3+
4+
struct Foo {
5+
unittest {}
6+
}
7+
8+
alias Zoo = Foo;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module unit_threaded.ut.modules.issue321_helper;
2+
3+
import unit_threaded.ut.modules.issue321;
4+
5+
struct Bar {
6+
alias Bell = Foo;
7+
}
8+
9+
alias Other = Foo;

0 commit comments

Comments
 (0)