"Try it now"

Jonathan M Davis jmdavisProg at gmx.com
Fri Apr 15 22:34:58 PDT 2011


> == Quote from Jacob Carlborg (doob at me.com)'s article
> 
> > On 2011-04-14 18:48, Andrei Alexandrescu wrote:
> > > On 4/14/11 9:03 AM, Steven Schveighoffer wrote:
> > >> Sometimes, I worry that my unit tests or asserts aren't running. Every
> > >> once in a while, I have to change one to fail to make sure that code
> > >> is compiling (this is especially true when I'm doing version
> > >> statements or templates). It would be nice if there was a
> > >> -assertprint mode which showed asserts actually running (only for the
> > >> module compiled with that switch, of course).
> > > 
> > > Could this be achieved within the language?
> > > 
> > > Andrei
> > 
> > Don't know exactly how he wants it to behave but I have have a look one
> 
> > of my earlier posts:
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group
> =digitalmars.D&artnum=134796
> 
> I'm somewhat shifting the topic, but it seems strange that unit tests are
> run when you run an executable. Wouldn't it make sense to run them
> immediately after compilation? I mean, what would be the use case where
> you would want to re-run a unit test on the code that's already compiled
> and tested? This could also solve the problem with messages on success,
> since you can output a success message after compilation.
> 
> Sorry if I'm missing some obvious issue with this suggestion.

You essentially need an executable to run the unit tests. It doesn't 
technically have to be an altered version of the normal executable, but you 
need an executable. It was probably just simplest to alter the normal 
executable so that it included the unit tests. Code coverage works the same 
way. Also, it could be desirable to build the unit tests without actually 
running them, at least some of the time, so separating the unit test build 
from actually running the unit tests can be beneficial.

Regardless, the way it works works quite well overall. What is typically done, 
I believe is create a module with an empty main specifically for running the 
unit tests. So, building with -unittest isn't usually done with the normal 
executable, and you don't typically run your normal executable with the unit 
tests included in it.

And as for the lack of messages on success, the whole idea is that there be no 
messages on success. You don't normally care about the unit tests unless they 
fail, so messages on success are just useless cruft in most cases, and it's 
_much_ easier to verify that the unit tests past programmatically if the 
output on success is nothing. Besides, if you really want to output success 
for each unit test, all you have to do is add writeln calls to the end of all 
your tests (annoying perhaps, but not hard). It would certainly be possible to 
add a flag to dmd that made it so that each test printed out on success for 
those who wanted it, but the value is questionable, and Walter and the other 
compiler devs have much more critical issues to work on.

- Jonathan M Davis


More information about the Digitalmars-d mailing list