unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Python-style doctests in Guile (implemented, please comment)
Date: Mon, 31 Jul 2017 15:04:08 +0200	[thread overview]
Message-ID: <CAMFYt2a3JO1BjkHH6ObszOHgU1cyY6Msbw+fdE+EQxQ5FNBnYQ@mail.gmail.com> (raw)
In-Reply-To: <87ini8zs4w.fsf@netris.org>

2017-07-31 14:51 GMT+02:00 Mark H Weaver <mhw@netris.org>:

> Hi Arne,
>
> Arne Babenhauserheide <arne_bab@web.de> 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	other threads:[~2017-07-31 13:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-30 18:54 Python-style doctests in Guile (implemented, please comment) Arne Babenhauserheide
2017-07-31  8:22 ` Chaos Eternal
2017-07-31 17:44   ` Arne Babenhauserheide
2017-08-01  1:36     ` Chaos Eternal
2017-07-31 12:51 ` Mark H Weaver
2017-07-31 13:04   ` Panicz Maciej Godek [this message]
2017-07-31 17:23   ` Arne Babenhauserheide
2017-08-01 22:04     ` Vítor De Araújo
2017-10-10 18:21       ` Arne Babenhauserheide
2017-10-10 22:40         ` Vítor De Araújo
2017-10-14 13:05           ` Arne Babenhauserheide

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMFYt2a3JO1BjkHH6ObszOHgU1cyY6Msbw+fdE+EQxQ5FNBnYQ@mail.gmail.com \
    --to=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).