Unittest compiling into file with main.

James Miller james at aatch.net
Sun Feb 26 18:43:19 PST 2012


On 27 February 2012 15:18, Kevin <kevincox.ca at gmail.com> wrote:
> I was playing arround with compiling and found that my unittest were getting
> compiled into the file that has main() rather than the file they were
> defined in.  Is this the intended result and, if so why?
>
> Example:
> unittest are in unit.d, main() is in main.d.
>
> $ dmd -c unit.d
> $ dmd -c -unittest main.d
> $ dmd main.o unit.o
> ./main
> --- unittest run ---
> $ dmd -c -unittest unit.d
> $ dmd -c main.d
> $ dmd main.o unit.o
> ./main
> --- unittest don't run ---
>
> Thats all, thanks.
>
>

I'm guessing that because unittests are run before main, the
compiler/linker needs to know where to put them. Since the compiler
doesn't know that unit.d and main.d are part of the same program, they
aren't compiled in unless the entry point has been compiled with
support for running unittests.

I'm just guessing here, but that seems the most likely way, basically,
any other way would cause even more unintuitive behavior...


More information about the Digitalmars-d mailing list