I'd like to turn some attention to unittests, which don't seem to work
with static libraries. Consider:

.\main.d:
import mylib.test;
void main()
{
    auto x = foo();
}

.\mylib\test.d
module mylib.test;
int foo() { return 1; }
unittest { assert(0); }

$ dmd -unittest main.d mylib\test.d && main.exe
core.exception.asserter...@mylib.test(5): unittest failure

So far so good. It even works if I don't reference foo() from within
main(), even though the "unittest.d" file in Phobos has this comment
about it:
"// Bring in unit test for module by referencing function in it"

I think that comment might be outdated.

But now try it with a static library:

$ cd mylib
$ dmd -unittest -lib test.d
$ cd..
$ dmd -unittest main.d mylib\test.lib && main.exe

The unittests from the library don't run.

There's a bug about this in bugzilla somewhere (I just can't seem to
find it now), but it doesn't seem to be getting much attention. Since
unittests are first-class citizens in D, I really hope we can get this
working soon. Cheers.

Reply via email to