1. Rationale
    1. API
      1. verbose?
      2. writeln
      3. and?
      4. pe
      5. xpr:val
      6. ppp
      7. ppp*
      8. xpr:val*
      9. ppp**
      10. define-test
      11. compound-test
      12. ==
      13. check
      14. define-checks
      15. do-checks
      16. define-tester
      17. test-all
      18. check-all
      19. simple-tests
    2. Examples
  2. Requirements
  3. Last update
  4. Author
  5. Repository
  6. License
  7. Version history

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?

[parameter] (verbose? ..)

gets or sets the value of the parameter verbose?

writeln

[procedure] (writeln xpr ...)

write analog of print, expressions separated by whitespace

and?

[procedure] (and? . xprs)

non-short-circuited and which executes all side-effects

pe

[syntax] (pe macro-code)

composes pretty-print and expand with additional information

xpr:val

[syntax] (xpr:val xpr ...)

Deprecated! Print each xpr quoted in a headline and pretty-print xpr's computed value.

ppp

[syntax] (ppp xpr ...)

print each xpr quoted in a headline and pretty-print xpr's computed value. Alias to xpr:val.

ppp*

[syntax] (ppp* {xpr ypr} ...)

Deprecated! Print each xpr quoted in a headline and pretty-print xpr's computed and expected value, ypr.

xpr:val*

[syntax] (xpr:val* {xpr ypr} ...)

Deprecated! Print each xpr quoted in a headline and pretty-print xpr's computed and expected value, ypr. Alias to ppp*

ppp**

[syntax] (ppp** ((var val) ...) xpr ypr . other-xpr-ypr-pairs)

Deprecated! ppp* wrapped into a let

define-test

[syntax] (define-test (name . parameters) form . forms)

Deprecated! Creates a test function

compound-test

[syntax] (compound-test (name) test . tests)

Deprecated! Invokes all tests and reports a summary

==

[procedure] (==)
[procedure] (== x)
[procedure] (== type? type-equal?)

Deprecated! Generic type equality as curried procedure

check

[syntax] (check ((var val) ...) xpr ypr . xpr-yprs)

Compare xpr and ypr .... in sequence with equal? in the environment defined by var val ...

define-checks

[syntax] (define-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs)

Deprecated! Returns a unary predicate, name?, comparing xpr with ypr .... and using var val ... within this checks, verbose? controls the reported summary.

do-checks

[syntax] (do-checks (name? verbose? . var-val-pairs) xpr ypr . xpr-yprs)

Deprecated! Returns a unary predicate, name?, comparing xpr with ypr .... and using var val ... within this checks, alias to define-checks

define-tester

[syntax] (define-tester (name? . var-vals) xpr ypr . xpr-yprs)

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

[syntax] (test-all Name tester ....)

invokes all testers defined with define-tester producing a list of failures and exiting with 0 or 1

check-all

[syntax] (check-all Name check-xpr ....)

Deprecated! checks all check-expressions defined with define-checks producing a list of failures and exiting with 0 or 1

simple-tests

[procedure] (simple-tests)
[procedure] (simple-tests sym)

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