octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @example's as doctests


From: Colin Macdonald
Subject: Re: @example's as doctests
Date: Fri, 27 Mar 2015 09:39:39 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

Oliver (and octave-maintainers),

I've hacked doctest-for-matlab enough [1] to run it on the infsup class from your Interval package. Interval uses the standard Octave @result{} convention: in my patched version, I split on @result{} and some other heuristics. It could be improved, see last bullet below.

[1] https://github.com/catch22/doctest-for-matlab/pull/10

I attach a log: most tests pass.  Oliver: I'm impressed!

I noticed:
  * there are a few actual errors.
  * there are some cases of @example used as a LaTeX alternative
    (is there an @verbatim instead?)
  * there a few minor (cosmetic?) errors: [-1, 5] to [-1, +5]
  * there are a couple cases were my current splitting
    input/output based on @result{} fails.  (Personally I prefer
    marking input with ">>" but the doctest code could instead be
    refactored further.)

Finally. I checked several functions in core: spdiags and svd are fairly close to testable. qr, chol not really written with this sort of tool in mind. IIRC, others warned me this was true of core Octave.

Colin

On 02/02/15 18:23, Oliver Heimlich wrote:
Am 02.02.2015 um 18:42 schrieb Colin Macdonald:
I've recently learned how to use address@hidden to put the expected result
into the texinfo docs of my functions.  (Thanks to "interval" pkg dev!)

Is there any existing way to run these as tests?  Like doctest in
Python?  I.e., extract them, run them, make sure the output matches the
address@hidden  The documentation refers to "example" but that seems to
pull in `%!demo` blocks instead.

The @result{} is just a macro that produces the ⇒ symbol in the
documentation. I find it useful for short examples in the documentation.
I copy the console output into the @example, replacing “$variable = ”
with the macro.

As a package maintainer I prefer to have these examples as test cases,
just to make sure that the documentation is correct. That's why I like
your proposal. The simplest solution IMHO is to add a %!test block for
examples used in the documentation manually.

It is complicated to check the @examples automatically, you must consider:
 - The @example blocks must not follow any particular syntax, nor must
they contain useful code,
 - the author of the example blocks may have abreviated commands or
console output,
 - if you wanted to check the console output of the examples, you would
have to intercept the stdout,
 - some results may be system-dependent,
 - …

I expect the answer will be "no, but please write such a thing"... :(

I'd find it useful to code simple %!test blocks, which will be used to
generate additional @example blocks at the end of the documentation.
Perhaps introduce a new %!example block?! However, automating this is
probably not worth it, since this only makes sense for short code
snippets and the examples in the documentation usually do not change often.


Attachment: infsup_doctests.log
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]