guile-user
[Top][All Lists]
Advanced

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

Re: Python-style doctests in Guile (implemented, please comment)


From: Panicz Maciej Godek
Subject: Re: Python-style doctests in Guile (implemented, please comment)
Date: Mon, 31 Jul 2017 15:04:08 +0200

2017-07-31 14:51 GMT+02:00 Mark H Weaver <address@hidden>:

> Hi Arne,
>
> Arne Babenhauserheide <address@hidden> writes:
>
> > I implemented doctests in Guile which allow writing SRFI-64 tests
> > directly in the docstring. Here’s a minimal example:
> >
> >
> >     (import (examples doctests))
> >
> >     (define (one)
> >       "(test 'foo
> >          (test-equal 1 (one)))"
> >       1)
>
> I don't think that tests should go into doc strings, for a couple of
> reasons.  First, doc strings already have a purpose, and that's for
> documentation.  While it may sometimes be beneficial to include a few
> examples in the documentation, a full test suite does not, IMO, belong
> in the doc string.
>
> The other issue is that this would involve putting code directly into a
> quoted string literal, which causes several problems.  One has to do
> with editor support for S-expressions.  For users of Emacs Scheme mode
> and/or paredit, it would mean when writing the tests without the editor
> support that we are accustomed to.  Additionally, if the test code
> involve string constants, then the embedded quotes would need to be
> escaped with backslashes, and any escaped characters within the strings
> would need double-backslashes, etc.  Finally, putting code within a
> string literal entails a loss of the hygiene that has been so carefully
> developed in modern Scheme macro expanders.
>
> For these reasons, I'm strongly opposed to this style of testing.
>
> If you want to do something like this, I would suggest instead defining
> some macros like 'define-with-tests' that allow you to put the unit
> tests together with each definition.
>
> What do you think?
>

I agree with Mark, that putting tests inside a string in Lisp is a terrible
idea,
because Lisp doesn't have Python's shortcommings, i.e. you can quote
symbolic structures in Lisp, whereas you can't do that in Python

There is no point in trading something better for something worse merely
because people from Python (or elsewhere) can't afford this "better".

I usually interleave definitions with tests using the "e.g." form, as you
can see
here, for example:
https://github.com/plande/grand-scheme/blob/master/grand/combinatorics.scm

(I've recently found that SRFI-78 does a very similar thing, as SRFI-64 is
in my view unnecessarily complex, especially if you want your tests to serve
as examples)


reply via email to

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