Should unittests run as logical part of compilation?

Jakob Ovrum jakobovrum at gmail.com
Sat Jan 25 15:06:32 PST 2014


On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu 
wrote:
> In particular, this view of unittests declares our current 
> stance on running unittests ("run unittests just before 
> main()") as meaningless. Indeed that has bothered me for quite 
> a while - unittests are part of the build/acceptance, not part 
> of every run. To wit, this is a growing idiom in D programs:
>
> version(unittest) void main() {}
> else void main()
> {
>     ...
> }

This idiom is probably mostly obsolete now that we have the -main 
flag. An IDE can build with -unittest -main -run and exclude the 
source file that normally defines `main`.

> What do you think? Logistically it shouldn't be too hard to 
> arrange things to cater to this approach.

I like it, as long as it doesn't mean unit tests are enabled by 
default, as that would probably be very surprising both for 
building release binaries and from a security perspective.



More information about the Digitalmars-d mailing list