std.unittests for (final?) review

Michel Fortin michel.fortin at michelf.com
Thu Jan 6 05:31:23 PST 2011


On 2011-01-06 06:45:41 -0500, Lutger Blijdestijn 
<lutger.blijdestijn at gmail.com> said:

> As you said, it is all about the error messages, not replacing assert perse.
> So this comparison would be more fair, using the syntax suggested by Andrei:
> 
> assertPred!">"(a, b);
> 
> vs
> 
> assert(a > b, format("a > b failed: [%s] is not > [%s]", a, b) );
> 
> If you really want the error message, regular asserts are a bit uglier and
> duplicate code.

The whole point of my proposal is to make the regular asserts print a 
message similar to yours *by default*, when you don't specify any 
message. This is possible because assert is not a function, it's a 
language construct handled by the compiler. The compiler has access to 
the whole expression tree, and it can rewrite the code to store 
intermediate results in variables it can later give to the assertion 
handler in case of failure.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list