Get UDA of unit tests during Runtime.moduleUnitTester

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 25 23:47:20 PDT 2017


On 2017-07-26 05:27, Matthew Remmel wrote:

> 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.

Unless you want to go with the approach Seb suggested, using 
unit-threaded, you need to recursively iterate the module to get all 
aggregates using __traits(allMembers) then use __traits(getUnitTests) 
for each aggregate to get all unit tests.

> 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.

That's not possible, the UDAs are lost after compile time. Also, all the 
unit tests block are combined into one function per module, which is 
what Runtime.moduleUnitTester is running. The separate unit test blocks 
are gone at runtime so there's nothing to connect the UDAs to.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list