www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Enumerating unittests

reply Shachar Shemesh <shachar weka.io> writes:
Hi all,

Is there a way to enumerate all the unittests in a specific module?

Thanks,
Shachar
Nov 17 2017
parent reply Michael V. Franklin <slavo5150 yahoo.com> writes:
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
Nov 17 2017
next sibling parent Atila Neves <atila.neves gmail.com> writes:
On Friday, 17 November 2017 at 08:32:23 UTC, 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
Note that before dmd 2.077.0 that trait only works when compiling all-at-once. Atila
Nov 17 2017
prev sibling parent reply Shachar Shemesh <shachar weka.io> writes:
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
Nov 17 2017
parent Atila Neves <atila.neves gmail.com> writes:
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
Nov 18 2017