Unittesting libraries

Jonathan M Davis jmdavisProg at gmx.com
Wed Aug 10 00:29:46 PDT 2011


On Wednesday, August 10, 2011 09:11:53 simendsjo wrote:
> On 08.08.2011 14:11, simendsjo wrote:
> > Is it possible to run unittests in libraries?
> > The following doesn't work:
> > 
> > l.d
> > ===
> > module l;
> > import std.stdio;
> > int f() { return 1; } // just to make sure it's actually compiled in
> > unittest {
> > writeln("Unittest from lib");
> > assert(false);
> > }
> > 
> > 
> > t.d
> > ===
> > import l;
> > import std.stdio;
> > void main() {
> > writeln(f());
> > }
> > 
> >  > dmd -unittest -lib l
> >  > dmd -unittest t l.lib
> >  > t.exe
> > 
> > 1
> 
> Anyone? Now I have to compile every source file from the library into
> t.d instead of compiling in the library.

I don't know exactly what the deal with unit tests and libraries is, but it 
wouldn't surprise me at all if you have to compile a module into a binary to 
run its unit tests. Phobos (on Linux at least) is set up to build each module 
separately to run its unit tests. I can see why you'd want to do this, so it 
may be worth creating a bug report or enhancement request for it, but I have 
no idea whether it's supposed to work or not.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list