automatically verifying code samples in phobos docs

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 19 23:28:55 PDT 2015


On 2015-08-20 01:41, Laeeth Isharc wrote:
> Should this be done?  How?

Just use a documented unit tests block:

///
unittest
{
     // code goes here
}

It will be run as part of the unit tests and it will be included when 
generating the documentation.

Although I don't have a good solution for the code in dlang.org that's 
not part of the Phobos/druntime documentation.

> I sent a pull request for the std.net.curl docs.  They all talk about
> assigning the results of web requests to strings, but at least on my
> setup this does not work (cannot assign char[] to string).  I was trying
> to walk someone else through using this and it was confusing.
>
>   Error: cannot implicitly convert expression (get("http.dlang.org",
> AutoProtocol())) of type char[] to string
>
> BTW I don't know why you can't convert a char[] to string - seems
> harmless enough conversion that way around.

char[] is mutable while string is not. Someone else can have a reference 
to the same data and change it will it's typed as "string", breaking the 
type system.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list