std.unittests [updated] for review
Jonathan M Davis
jmdavisProg at gmx.com
Tue Feb 1 09:29:26 PST 2011
On Tuesday 01 February 2011 09:12:16 Andrei Alexandrescu wrote:
> On 2/1/11 10:51 AM, Michel Fortin wrote:
> > On 2011-02-01 11:31:54 -0500, Andrei Alexandrescu
> > <SeeWebsiteForEmail at erdani.org> said:
> > TypeInfo holds a pointer to the toString function, so if the compiler
> > passes the two operands as D-style variadic arguments to the assert
> > handler, the assert handler can use toString to print them. The operator
> > should be passed as a string.
>
> In that case problem solved. Don, if you arrange things such that this
> user-level code:
>
> int a = 42;
> double b = 3.14;
> assert(a <= b, "Something odd happened");
>
> ultimately calls this runtime function:
>
> assertCmpFailed("<=", "42", "3.14", "Something odd happened");
>
> I promise I'll discuss with Sean and implement what it takes in druntime
> to get that completed.
>
> We need to finalize that before Feb 7 though because on that date the
> vote for Jonathan's library closes. If you do implement that, probably
> we'll need to reject the library in the current form and propose back an
> amended version.
You do need to remember to take into account though that expressions can be
quite a bit more complex than a <= b, and you still want to be able to print out
something useful.
It's been discussed a bit already, but IIRC what appeared to be the best
solution was that when an expression evaluated to false, you take the expression
to evaluated and stop evaluating it when all that was left is operators or
functions which resulted in bool. Then the value of those operands would be
printed. e.g.
assert(min(5 + 2, 4) < 2 && max(5, 7) < 10);
would print out the values
4, 2, 7, and 10.
and
assert(canFind("hello world", "goodbye"));
would print out the values
"hello world" and "goodbye".
Regardless, trying to do it in assert complicates things a fair bit. assertPred
gives you more control, because you can choose how to break up the expression
and arguments, and then those arguments are the ones which get printed. assert
has to be much smarter about figuring out what it should print. Done correctly,
it would be fantastic for assert to be that smart, but I wouldn't expect it to
be easy.
- Jonathan M davis
More information about the Digitalmars-d
mailing list