documented unit tests as examples

Andrej Mitrovic via Digitalmars-d digitalmars-d at puremagic.com
Sat May 14 10:48:48 PDT 2016


On 5/14/16, H. S. Teoh via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> I like this idea. But wouldn't it be too verbose?

Hmm good point. Alternatively we could perhaps make ddoc inject
writeln calls, something like:

----
auto sum (a, b) => a + b;

///
unittest { assert(sum(2, 2) == 4); }
----

Turns into ddoc output:

----
writeln(sum(2, 2));
assert(sum(2, 2) == 4);
----

> How would the assert implementation in druntime access the expression
> being tested? I.e., in a way that it can be printed out in
> human-readable form.

Ah I was remembering wrong here. The compiler turns the assert
expression into something like "cast(bool)expression || __assert".

So anyway, I think perhaps the simplest solution is to make ddoc
inject the writeln calls (or possibly replace assertions altogether in
the output).


More information about the Digitalmars-d mailing list