TOC »
Rationale
This is a simple Unit Test Framework inspired by Peter Seibel's "Practical Common Lisp" together with some routines which might be useful for debugging. It underwent several changes in the maintenance process, most of them are now marked deprecated but are still there in favor of backwards compatibility.
For the future, it's sufficient to use only the following six routines, the parameter verbose? and the macros pe, ppp, check, make-tester and test-all.
pe, ppp and check are mostly used in the development phase, make-tester and test-all are the actual test routines to go into tests/run.scm.
A tester is a nullary predicate which produces a lot of information as side-effects provided the parameter verbose? is true. These testers are invoked in test-all.
pe is a combination of pretty-print and expand enhanced with additional text; ppp pretty-prints a list of expressions and its values, while check does the same but accompanies these computed values with expected ones, allowing for local variables in the checks.
API
verbose?
- verbose? ..parameter
gets or sets the value of the parameter verbose?
writeln
- writeln xpr ...procedure
write analog of print, expressions separated by whitespace
and?
- and? #!rest xprsprocedure
non-short-circuited and which executes all side-effects
pe
- (pe macro-code)syntax
composes pretty-print and expand with additional information
xpr:val
- (xpr:val xpr ...)syntax
Deprecated! Print each xpr quoted in a headline and pretty-print xpr's computed value.
ppp
- (ppp xpr ...)syntax
print each xpr quoted in a headline and pretty-print xpr's computed value. Alias to xpr:val.
ppp*
- (ppp* {xpr ypr} ...)syntax
Deprecated! Print each xpr quoted in a headline and pretty-print xpr's computed and expected value, ypr.
xpr:val*
- (xpr:val* {xpr ypr} ...)syntax
Deprecated! Print each xpr quoted in a headline and pretty-print xpr's computed and expected value, ypr. Alias to ppp*
ppp**
- (ppp** ((var val) ...) xpr ypr . other-xpr-ypr-pairs)syntax
Deprecated! ppp* wrapped into a let
define-test
- (define-test (name . parameters) form . forms)syntax
Deprecated! Creates a test function
compound-test
- (compound-test (name) test . tests)syntax
Deprecated! Invokes all tests and reports a summary
==
- ==procedure
- == xprocedure
- == type? type-equal?procedure
Deprecated! Generic type equality as curried procedure
check
- (check ((var val) ...) xpr ypr . xpr-yprs)syntax
Compare xpr and ypr .... in sequence with equal? in the environment defined by var val ...
define-checks
- (define-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs)syntax
Deprecated! Returns a unary predicate, name?, comparing xpr with ypr .... and using var val ... within this checks, verbose? controls the reported summary.
do-checks
- (do-checks (name? verbose? . var-val-pairs) xpr ypr . xpr-yprs)syntax
Deprecated! Returns a unary predicate, name?, comparing xpr with ypr .... and using var val ... within this checks, alias to define-checks
define-tester
- (define-tester (name? . var-vals) xpr ypr . xpr-yprs)syntax
Returns a thunk predicate, name?, comparing xpr with ypr .... and using var val ... within this tests. The parameter verbose? controls the reported summary, i. e. the side effects.
test-all
- (test-all Name tester ....)syntax
invokes all testers defined with define-tester producing a list of failures and exiting with 0 or 1
check-all
- (check-all Name check-xpr ....)syntax
Deprecated! checks all check-expressions defined with define-checks producing a list of failures and exiting with 0 or 1
simple-tests
- simple-testsprocedure
- simple-tests symprocedure
with sym: documentation of exported symbol without sym: list of exported symbols
Examples
(import simple-tests) (newline) (define-test (bar n) (positive? n) (even? n)) (bar 5) (define-test (foo x y) (< x y) "COMMENT" (bar 4) (odd? 3) (positive? 3)) (foo 1 2) (define-test (++) (= (+ 1 2) 3) (= (+ 1 2 3) 6)) (++) (define-test (**) (= (* 1 2) 2) (= (* 1 2 3) 6)) (**) (define-test (arithmetic) (++) (**)) (arithmetic) (define-test (baz) (and? #t #t #t) (and?) (not (and? #t #f #t))) (baz) '(compound-test (OLD) (bar 5) (foo 1 2) (++) (**) (arithmetic) (baz)) (newline) (positive? n) ;-> #t (even? n) ;-> #f (bar?) (+ 1 2) ;-> 3 (+ 1 2 3) ;-> 6 (+?) (* 1 2) ;-> 2 (* 1 2 3) ;-> 6 (*?) (+? #f) ;-> #t (*? #f) ;-> #t (arithmetic?) (and? #t #t #t) ;-> #t (and?) ;-> #t (and? #t #f #t) ;-> #f (baz?) ((== "x") "y") ;-> #f ((== "x") "x") ;-> #t ((== baz?) baz?) ;-> #t ((== baz?) bar?) ;-> #f ((== '()) '()) ;-> #t ((== 'x) 'y) ;-> #f ((== 'x) 'x) ;-> #t ((== #(0 1 2)) #(0 1 2)) ;-> #t ((== #(0 1 2)) '(0 1 2)) ;-> #f (qux?) (define counter (let ((n 0)) (case-lambda (() (set! n (add1 n)) n) ((k) (set! n k) n)))) (counter 0) ;-> 0 (counter) ;-> 1 (counter) ;-> 2 (counter) ;-> 3 (counter) ;-> 4 (counter?) '(check-all NEW (bar?) (*?) (+?) (arithmetic?) (baz?) (qux?) (counter?)) (positive? n) ;-> #t (even? n) ;-> #f (+ 1 2) ;-> 3 (+ 1 2 3) ;-> 6 (* 1 2) ;-> 2 (* 1 2 3) ;-> 6 (parameterize ((verbose? #f)) (Plus?)) ;-> #t (parameterize ((verbose? #f)) (Times?)) ;-> #t (define Counter (let ((n 0)) (case-lambda (() (set! n (add1 n)) n) ((k) (set! n k) n)))) (Counter 0) ;-> 0 (Counter) ;-> 1 (Counter) ;-> 2 (Counter) ;-> 3 (Counter) ;-> 4 (Counter 0) ;-> 0 '(test-all SIMPLE-TESTS Bar? Times? Plus? Arithmetic? Counter?)
Requirements
None
Last update
Feb 8, 2021
Author
Juergen Lorenz
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/simple-tests
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
License
Copyright (c) 2013-2021 , Juergen Lorenz, ju (at) jugilo (dot) de All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version history
- 3.1
- pe bug corrected
- 3.0
- support for define-tester and test-all, deprecated routines marked
- 2.3.2
- locals in checks with letrec
- 2.3.1
- aesthetic changes
- 2.3
- check added
- 2.2
- ppp** added
- 2.1
- do-checks as an alias to define-checks added
- 2.0.3
- bugfix: protect state changing functions
- 2.0.1
- test-predicates without verbose? argument are verbose by default
- 2.0
- added a second testing interface
- 1.1
- ppp* added
- 1.0
- port with modifications from chicken-4, version 2.6, to chicken-5