assert(condition[, message]) patch

Chris Miller chris at dprogramming.com
Wed May 31 10:47:21 PDT 2006


On Wed, 31 May 2006 13:01:24 -0400, Walter Bright  
<newshound at digitalmars.com> wrote:

> braddr at puremagic.com wrote:
>> I have been toying with D to bring myself up to speed and I found  
>> myself writing
>> a lot of unit tests, always a good thing.  In those unit tests I found  
>> myself
>> writing a lot of blocks like:
>>  if (cond)
>> {
>> writefln("some debugging output to make my life easier");
>> assert(false);
>> }
>>  I know many don't like unit tests to have output, but I do.
>
> Why not:
>
> 	assert(!cond); // some debugging output to make my life easier
>
> ? You'll need to go look at the source anyway when the assert trips, so  
> what advantage is there to print the comment?

How about when you have many versions of the program and source. Sure if  
you backup regularly and save them all you can eventually figure out which  
assert, but a message usually lets you find it in seconds.

I'd also be satisfied if it only used the assert expression as this  
message (and a trick could be used if one really wants: assert(foo && "my  
message");).



More information about the Digitalmars-d mailing list