Running unittests in a D library

Jonathan M Davis jmdavisProg at gmx.com
Wed Sep 19 16:56:12 PDT 2012


On Wednesday, September 19, 2012 21:49:19 Jacob Carlborg wrote:
> On 2012-09-19 21:34, Jonathan M Davis wrote:
> > You don't build it as a library when your unit testing it. You create an
> > empty main, compile it all as an executable, and run it. I believe that
> > rdmd --main will do this for you (rdmd comes with dmd), but I haven't
> > really used rdmd, so I'm not 100% certain.
> 
> The problem in that bug report is you can't first compile your library
> as a library and then compile an executable using the library. According
> to the bug report it won't run the unittest blocks from the library.

Yes. But the solution then is to not unit test your library that way. You 
build it as a binary with an empty main and run that. It may be that compiling 
it as a library and then linking should work, but unless you want to have the 
unit test stuff compiled into your library normally (I wouldn't think so), 
you'll have to compile it separately for unit testing anyhow, so I don't think 
that it's really a big issue. You just have to realize that you need to not 
compile your library as a library when compiling your -unittest build.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list