Re: DMD unittest fail reporting…

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sun Dec 6 03:14:27 PST 2015


On 2015-12-06 00:09, Chris Wright wrote:

> But there are problems with saying that the builtin assert function
> should show the entire expression with operand values, nicely formatted.
>
> assert has to serve both unittesting and contract programming. When
> dealing with contract programming and failed contracts, you risk objects
> being in invalid states. Trying to call methods on such objects in order
> to provide descriptive error messages is risky. A helpful stacktrace
> might be transformed into a segmentation fault, for instance. Or an
> assert error might be raised while attempting to report an assert error.
>
> assert is a builtin function. It's part of the runtime. That puts rather
> strict constraints on how much it can do. The runtime can't depend on the
> standard library, for instance, so if you want assert() to include the
> values that were problematic, the runtime has to include that formatting
> code. That doesn't seem like a lot on its own, but std.format is probably
> a couple thousand lines of code. (About 3,000 semicolons, including
> unittests.)
>
> I would like these nicely formatted messages. I don't think it's
> reasonably practical to add them to assert. I'll spend some thought on
> how to implement them outside the runtime, for a testing framework,
> though I'm not optimistic on a nice API. Catch does it with macros and by
> parsing C++, and the nearest equivalent in D is string mixins, which are
> syntactically more complex. Spock does it with a compiler plugin. I know
> I can do it with strings and string mixins, but that's not exactly going
> to be a clean API.

Another good use case for AST macros.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list