"Try it now"

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Apr 14 10:16:33 PDT 2011


On 4/14/11 12:00 PM, Steven Schveighoffer wrote:
> On Thu, 14 Apr 2011 12:48:26 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> On 4/14/11 9:03 AM, Steven Schveighoffer wrote:
>>> Sometimes, I worry that my unit tests or asserts aren't running. Every
>>> once in a while, I have to change one to fail to make sure that code is
>>> compiling (this is especially true when I'm doing version statements or
>>> templates). It would be nice if there was a -assertprint mode which
>>> showed asserts actually running (only for the module compiled with that
>>> switch, of course).
>>
>> Could this be achieved within the language?
>
> I think you need to do it at the compiler level to make it useful. For
> example, an assert like:
>
> assert(container.length == 5);
>
> To print this out properly, I'd want to see that the assert passed, but
> also what the test was.

What's needed here is a "text of expression" feature similar to C's "#". 
That would help enforce and other artifacts too. I'm thinking along the 
lines of:

void myassert(string expr = __traits(text, condition))(bool condition) {
   ...
}

with, of course, a simpler syntax.

> I think this would be an awesome feature. One of the cool things about
> the new way phobos runs unit tests (one module at a time) is that if a
> particular test fails, I can just build/run it over and over again until
> it passes. This is huge since to run the full phobos unit tests can take
> a while.

That's exactly how Phobos unittest work on Linux, and that was the 
motivation behind making it work that way.


Andrei


More information about the Digitalmars-d mailing list