Phobos runnable examples - ideas request

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 28 11:36:39 PDT 2013


On Thu, Mar 28, 2013 at 07:25:07PM +0100, Johannes Pfau wrote:
> Am Wed, 27 Mar 2013 22:54:21 +0100
> schrieb "nazriel" <spam at dzfl.pl>:
> 
> > Greetings.
> > 
> > I would like to finish Phobos runnable examples case. But I need 
> > help in picking one strategy for implementation details.
> > 
> 
> With the recent unittest-as-example changes I'd say make runnable
> examples work with those and promote writing examples as unittests. This
> way you know for sure that examples compile. AFAIK there's currently
> no way to disambiguate such an example from a handwritten one, but you
> could file an enhancement request for that. I'm sure Andrej Mitrovic
> would implement that quickly. (We'd just need a DDOC_CHECKED_EXAMPLE
> macro to wrap the example).

The unittest examples are already running; so all we need to do to make
it independently compilable is to wrap the code inside a unittest block,
insert an empty main, and it should work.

Imports may be handled by including code from version(unittest) blocks.
I'm not so sure about this, though. IMO, other than the implicit import
of the current module, all code examples should always display all
imports explicitly so that copy-n-pasting the code into a unittest block
will automatically work, no matter what.


T

-- 
There are two ways to write error-free programs; only the third one works.


More information about the Digitalmars-d mailing list