Get UDA of unit tests during Runtime.moduleUnitTester

Matthew Remmel via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 25 20:27:30 PDT 2017


I'd like to print out the name given to a unit test via a UDA, as 
the tests are being ran by the Runtime.moduleUnitTester. I'm 
working on writing a custom unit test runner. It would seem that 
the ModuleInfo.unitTest property is an aggregated function of all 
the individual unit test blocks in a module, and therefore the 
UDA value is lost.

I've been attempting to use the __traits(getUnitTests, m) 
function, but that doesn't seem to work with ModuleInfo because 
it is a variable and not a symbol. Additionally, if you run 
__traits(getUnitTests, m) against a module, that doesn't retrieve 
any unit tests that are nested inside classes or structs. So even 
if it did work with ModuleInfo, there may still be problems.

What I would like is to have a module like:
___
module app;

int square(int x) { return x*x; }

@name("square test 1")
unittest {
     assert(square(10) == 100);
}

@name("square test 2")
unittest {
     assert(square(5) == 25);
}

class Foo {
     void someFunc() { return; }

     @name("Foo test")
     unittest {
         assert(someFunc() == something);
     }
}
___

So as mentioned above, the first problem is that using 
ModuleInfo.unitTest returns an aggregated function of all 3 unit 
tests for that module, instead of each one individually, so the 
UDA information is lost. The second problem is that running 
__traits(getUnitTests, app) only returns the 2 tests at module 
scope, and not the one nested inside Foo. Even then, I haven't 
been able to figure out how to dynamically get the module symbol 
to pass to __traits inside of the Runtime.moduleUnitTester 
function.

Its possible that I've got some of this backwards and there is an 
easy solution. Its also possible that what i'm trying to do isn't 
currently possible.

Thanks in advance for any help.
--Matt


More information about the Digitalmars-d-learn mailing list