assert(condition[, message]) patch

akcom CppCoder at gmail.com
Tue May 30 16:59:30 PDT 2006


braddr at puremagic.com wrote:
> In article <drrnko$2onm$1 at digitaldaemon.com>, braddr at puremagic.com says...
>> 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.  To simplify this,
>> I've created a patch for gdc/dmd to allow this syntax instead:
>>
>> assert(cond, "some optional debugging output to make my life easier");
>>
>> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff
>> http://www.puremagic.com/~braddr/d/assert-test.d
>>
>> I've run this through dstress with no regressions.
>>
>> Anyone wanna give it a whirl?
>>
>> Later,
>> Brad
> 
> I was just about to start bringing this patch up to work with current dmd and
> gdc but decided I should ask first:
> 
> Is anyone using it with gdc 0.17?
> Would anyone use it if I freshened it up?
> Walter, would you be interested / willing to incorporate the parser part into
> dmd and support the feature in dmd?
> 
> I've seen a couple alternatives suggested, but they've all been somewhat hacky,
> imho.
> 
> Later,
> Brad
> 
> 
Just my thoughts, I think it's definitely got some merits, although one 
must consider that the assert( statementToTest ) would give you the line 
that threw the assert, which makes a message a bit less important. 
Although, on the other hand, if someone (ie not someone who wrote the 
code) were to see the assert and check the given line, it probably 
wouldn't mean too much to them, whereas being able to see a message 
associated with it would be a bit more useful.  I'd definitely give the 
mod a whirl.



More information about the Digitalmars-d mailing list