Phobos runnable examples - ideas request

Timothee Cour thelastmammoth at gmail.com
Thu Mar 28 00:46:48 PDT 2013


I think it's too fragile to require examples inside docs to be
runnable. A better way would be to expose those examples in the code
(ie outside of comments). That way, they'll be guaranteed to have
correct syntax, be properly syntax highlighted, and stay in sync with
code.

here's a simple possibility:

----
/**
Here's a comment before
*/
version(ddocs_example) @runnable unittest{
    assert (rootName("foo") is null);
    assert (rootName("/foo") == "/");
}
version(ddocs_example) @notrunnable unittest{
    //do something not meant to be runnable here
    assert (rootName("/foo") == "/");
}
/**
Here's a comment after
*/
----

This way, DDOC can easily extract version(ddocs_example) unittest
blocks and present them as runnable examples (for the ones marked with
@runnable). dmd's unittesting would run unittest on those.

On Thu, Mar 28, 2013 at 12:18 AM, Jacob Carlborg <doob at me.com> wrote:
> On 2013-03-27 22:54, nazriel wrote:
>
>> Requesting user to edit code first, add main(){} block or fix invalid D
>> code and then run example itself is unacceptable.
>
>
> RDMD already has a --main flag and DMD will soon too.
>
> --
> /Jacob Carlborg


More information about the Digitalmars-d mailing list