assert(condition[, message]) patch
BCS
BCS_member at pathlink.com
Wed May 31 10:35:29 PDT 2006
In article <e5ki8s$jfc$1 at digitaldaemon.com>, Walter Bright says...
>
>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?
a little run time info could be realy helpfull.
# assert(str.length < 5, `the string "` ~ str ~ `" is more than 5 char long`);
or in the case someone was talking about (MMX stuff)
..
char[] assertMsg
assert(compArray(c,d,assertMsg), assertMsg);
..
bool compArray(int[] a, int[] b, inout char[] msg)
{
if(a==b) return true;
if(a.length != b.length)
{
msg = "Unequal length";
return false;
}
foreach(int i, int j; a)
if(a[i] != b[i])
{
msg = "element #" ~ toString(i) ~ " unequal";
return false;
}
msg = "somthings wrong";
return false;
}
More information about the Digitalmars-d
mailing list