From: Arne Babenhauserheide <arne_bab@web.de>
To: "Vítor De Araújo" <vbuaraujo@sapo.pt>
Cc: guile-user@gnu.org
Subject: Re: Python-style doctests in Guile (implemented, please comment)
Date: Tue, 10 Oct 2017 20:21:00 +0200 [thread overview]
Message-ID: <871smaq2l0.fsf@web.de> (raw)
In-Reply-To: <5980FAF1.8080806@sapo.pt>
[-- Attachment #1: Type: text/plain, Size: 2317 bytes --]
Hi Vitor,
I’m sorry for answering so late; your suggestion stuck to my mind as a
clean and schemish solution for my usecase (thank you!) but it took me
quite a while to realize it.
Vítor De Araújo <vbuaraujo@sapo.pt> writes:
> (define (double x)
> "Returns twice the value of a given number."
> #((examples [(double 5) 10]
> [(double 0) 0]))
> (* 2 x))
I now implemented this for tests based on srfi-64:
https://bitbucket.org/ArneBab/wisp/src/299795dbb3fecea91dcdde480817b36fc45ccc5f/examples/doctests.scm
Here’s the documentation:
;;; doctests --- simple testing by adding procedure-properties with tests.
;;; Usage
;; Add a tests property to a procedure to have simple unit tests.
;; Simple tests:
;;
;; (define (A)
;; #((tests (test-eqv 'A (A))
;; (test-assert #t)))
;; 'A)
;;
;; Named tests:
;;
;; (define (A)
;; #((tests ('test1 (test-eqv 'A (A))
;; (test-assert #t))
;; ('test2 (test-assert #t))))
;; 'A)
;;
;; Allows for docstrings:
;;
;; (define (A)
;; "returns 'A"
;; #((tests (test-eqv 'A (A))
;; (test-assert #t)))
;; 'A)
;; For writing the test before the implementation, start with the test and #f:
;; (define (A)
;; #((tests (test-eqv 'A (A))))
;; #f)
This is what was missing for me to get an elegance in test-driven design
which I had been missing till now. And it really feels much more elegant
than the stringly doctesting in Python.
The output looks like this:
%%%% Starting test examples-doctests.scm--doctests-testmod--mytest (Writing full log to "examples-doctests.scm--doctests-testmod--mytest.log")
# of expected passes 3
%%%% Starting test examples-doctests.scm--doctests-testmod--mytest2 (Writing full log to "examples-doctests.scm--doctests-testmod--mytest2.log")
# of expected passes 4
%%%% Starting test examples-doctests.scm--subtract (Writing full log to "examples-doctests.scm--subtract.log")
# of expected passes 5
Now there’s one first question: How should I call it? :-)
Currently the modules is (examples doctests). Do you have a better idea
than "doctests"?
Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein
ohne es zu merken
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2017-10-10 18:21 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
2017-07-31 17:23 ` Arne Babenhauserheide
2017-08-01 22:04 ` Vítor De Araújo
2017-10-10 18:21 ` Arne Babenhauserheide [this message]
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=871smaq2l0.fsf@web.de \
--to=arne_bab@web.de \
--cc=guile-user@gnu.org \
--cc=vbuaraujo@sapo.pt \
/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).