How to iterate through all modules for use with the new getUnitTests trait?

Sönke Ludwig sludwig at outerproduct.org
Thu Nov 7 02:04:52 PST 2013


Am 07.11.2013 09:37, schrieb Jacob Carlborg:
> On 2013-11-06 22:26, Dicebot wrote:
>
>> You need only symbol name of your root compiled module which imports all
>> others. All imported ones will be available in its member list, exactly
>> what this snippet shows.
>
> That is the problem. One needs to import all other modules. That's not a
> good solution when creating a unit test framework. One would basically
> have to scan a directory for all D files. Then generate a new file that
> imports all these files, with a main function that runs all tests.
>
> Alternatively have something like RTInfo but for modules:
>
> Bugzilla: https://d.puremagic.com/issues/show_bug.cgi?id=10023
> Pull request DMD: https://github.com/D-Programming-Language/dmd/pull/2271
> Pull request druntime:
> https://github.com/D-Programming-Language/druntime/pull/534
>
> Unfortunately my solution has the same problem as RTInfo, one needs to
> modify object.d. I had an idea that would solve this both for RTInfo and
> the new RMInfo, but that would most likely require building an
> associative array at runtime. That was not liked. See the comments in
> the pull requests and this:
>
> https://d.puremagic.com/issues/show_bug.cgi?id=10023#c3
>

Can't you do something like this? Or is the unit test framework supposed 
to provide its own "root"/main module?

---
module unittestframework;

void runTests(string root_module = __MODULE__)()
{
    // start recursion from root_module
}
---

---
module appmain;
import unittestframework;

void main()
{
	runTests();
}
---


More information about the Digitalmars-d-learn mailing list