Enumerating unittests

Atila Neves atila.neves at gmail.com
Sat Nov 18 10:09:55 UTC 2017


On Saturday, 18 November 2017 at 07:35:11 UTC, Shachar Shemesh 
wrote:
> On 17/11/17 10:32, Michael V. Franklin wrote:
>> On Friday, 17 November 2017 at 08:12:13 UTC, Shachar Shemesh 
>> wrote:
>> 
>>> Is there a way to enumerate all the unittests in a specific 
>>> module?
>> 
>> Try this: https://dlang.org/spec/traits.html#getUnitTests
>> 
>> Mike
>> 
>
> This is precisely what I asked for, but not what I need :-\
>
> The problem is that it needs a module name to enumerate. I'm 
> not aware of a way to enumerate all modules at compile time. 
> Essentially, I can enumerate all modules at run time, but to 
> get the list of unittests in them, I need to know them at 
> compile time.
>
> Am I missing something?
>
> Shachar

No, you're not.

Unfortunately this is how compile-time reflection works in D: at 
the module level (or lower). If you want to reflect on all 
modules in a project, then the build system has to generate the 
file that does the reflection for you. There is currently no way 
to reflect on a package. This is why unit-threaded has a dub 
configuration to generate the file that drives the reflection, by 
looking at the file system and writing out something that looks 
like this:

import unit_threaded;

int main(string[] args) {
     return args.runTests!("module1", "module2", ...);
}

You'd have to do something similar.

Alternatively, just use unit-threaded. ;)

Atila


More information about the Digitalmars-d mailing list