Should unittests run as logical part of compilation?

Knud Soerensen 4tuu4k002 at sneakemail.com
Sun Jan 26 23:53:27 PST 2014


I am already doing something very similar.

When I make a module I add this to the top.
#!/usr/bin/rdmd --shebang -unittest --main
(I would like to add -cov=100 but I can't get it to work)
Then I just run the module to compile and run unit tests.

My programs with main is always very small,
typical calling a module function with the arguments.

Doing the unit testing in the end of the compile would
mean that we could ensure that dependencies  was unit testing before
use. That would be nice.

Another thing I find really tedious about D unit testing can you read
about here.

http://forum.dlang.org/post/lc514a$sd7$1@digitalmars.com

Knud



On 2014-01-25 23:55, Andrei Alexandrescu wrote:
> There's this simple realization that unittests could (should?) be
> considered an intrinsic part of the build process. In order for an
> executable to be worth running, it should pass the regular semantic
> checks and also the unittests, which in a sense are extended semantic
> checks that fall outside the traditional charter of the compiler.
> 
> In that view, asserts inside unittests should fail with the same message
> format as regular compilation errors, i.e.
> 
> ./modulename.d(103): Unittest failed: user-defined message
> 
> Stack traces and other artifacts printed by failing asserts should come
> after, indented. An IDE user should run unittest with the usual "build"
> command and be able to click on the unittest failures just the same as
> build errors.
> 
> 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()
> {
>     ...
> }
> 
> What do you think? Logistically it shouldn't be too hard to arrange
> things to cater to this approach.
> 
> 
> Andrei


-- 
Join me on
Skype	   knudhs
Facebook   http://www.facebook.com/profile.php?id=1198821880
Linkedin   http://www.linkedin.com/pub/0/117/a54
Twitter    http://twitter.com/knudsoerensen
bitcoin donations: 13ofyUKqFL43uRJHZtNozyMVP4qxKPsAR2


More information about the Digitalmars-d mailing list