To do it _really_ nice, we would need some sort of ".codeof" feature. Possibly, with implicit returns in lambdas. For example:

void test(alias expr)
{
    if (!expr())
        throw new TestException(
            expr.codeof ~ " has failed,\n" ~
            /* investigate expr context pointer and grab a/b */
            "\ta = x\n" ~
            "\tb = y"
}

unittest
{
    int a, b;
    test!({ a == b; });
}

Of course, this is one of cases where AST macros would really shine. But I think it should be possible to provide necessary functionality subset in a much more simple and limited feature.

In absence of language changes, I don't see anything as clear and simple as operator mixins. Less magic in unittests -> better. Common misconception IMHO is that tests should look nice for library/app author, while, from the ecosystem PoV, they should look simple and predictable for contributors - and that is most important property.

Reply via email to