[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Python-style doctests in Guile (implemented, please comment)
From: |
Arne Babenhauserheide |
Subject: |
Re: Python-style doctests in Guile (implemented, please comment) |
Date: |
Tue, 10 Oct 2017 20:21:00 +0200 |
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 <address@hidden> 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
signature.asc
Description: PGP signature
- Re: Python-style doctests in Guile (implemented, please comment),
Arne Babenhauserheide <=