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: Mark H Weaver
Subject: Re: Python-style doctests in Guile (implemented, please comment)
Date: Mon, 31 Jul 2017 08:51:27 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

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?

    Regards,
      Mark



reply via email to

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