Bug 10990 – Passing in a module as a mixin to __traits(getUnitTests) behaves differently than passing in the module directly.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-07T19:49:00Z
Last change time
2013-09-12T15:56:20Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
opantm2+dbugs
Comments
Comment #0 by opantm2+dbugs — 2013-09-07T19:49:06Z
I don't know if this is specific to __traits(getUnitTests), though I doubt it is. When passing in a module directly, such as through __traits(getUnitTests, ptest2), a compiler error is raised saying that a module/aggregate is expected instead of an import. Passing the module in as a mixin, through __traits(getUnitTests, mixin("ptest2")) however works as expected. I tried with __traits(allMembers) and __traits(derivedMembers) which both seem to work fine, but I don't know of any other traits I could test with modules.
Sample code passing in as module:
import std.stdio;
import ptest2;
void main() {
writeln(__traits(getUnitTests, ptest2).length);
}
Results in the following errors:
ptest.d(6): Error: argument ptest2 to __traits(getUnitTests) must be a module or aggregate, not a import
ptest.d(6): Error: no property 'length' for type 'bool'
Passing in as mixin results in no errors and works as expected:
import std.stdio;
import ptest2;
void main() {
writeln(__traits(getUnitTests, mixin("ptest2")).length);
}
Code for ptest2.d:
module ptest2;
import std.stdio;
unittest {
writeln("First unittest.");
}
Comment #1 by andrej.mitrovich — 2013-09-07T20:14:01Z