Testeez is a simple lightweight unit test mechanism for R5RS Scheme. It was written to support regression test suites embedded within the source code files of the author's portable Scheme libraries.
A series of Testeez tests is listed within the testeez
syntax. By following a simple convention, these tests can be disabled and the
dependency on Testeez removed for production code. For example, to use Testeez
in a "Foo" library, one can first add a syntax wrapper around
testeez like so:
(define-syntax %foo:testeez
(syntax-rules ()
((_ X ...)
;; Note: Comment-out exactly one of the following two lines.
;; (error "Tests disabled.")
(testeez X ...)
)))
Then, this wrapper %foo:testeez can be used in a
procedure that executes the test suite of the "Foo" library:
(define (%foo:test)
(%foo:testeez
"Foo Enterprise"
(test/equal "Put two and two together" (+ 2 2) 4)
(test-define "Bar function" bar (lambda (x) (+ x 42)))
(test/equal "Bar scene" (bar 69) 0)
(test/equal "Full circle" (* (bar -21) 2) 42)
(test/eqv "Multiple"
(values (+ 2 2) (string #\h #\i) (char-upcase #\p))
(values 4 "hi" #\P))))
When the tests are enabled and (%foo:test) is
evaluated, output like the following (which looks prettier fontified in Emacs's
*scheme* buffer) is printed:
;;; BEGIN "Foo Enterprise" TESTS ;; 1. Put two and two together (+ 2 2) ;; ==> 4 ;; Passed. ;; DEFINE: Bar function (define bar (lambda (x) (+ x 42))) ;; 2. Bar scene (bar 69) ;; ==> 111 ;; FAILED! Expected: ;; 0 ;; 3. Full circle (* (bar -21) 2) ;; ==> 42 ;; Passed. ;; 4. Multiple (values (+ 2 2) (string #\h #\i) (char-upcase #\p)) ;; ==> 4 ;; "hi" ;; #\P ;; Passed. ;;; END "Foo Enterprise" TESTS: FAILED ;;; (Total: 4 Passed: 3 Failed: 1)
The testeez syntax also supports shorthand or abbreviated
forms, for quick interactive use, such as in an editor buffer while
rapid-prototyping a function, and in a REPL while debugging. For an example of
shorthand, the Scheme expression:
(testeez ((+ 1 2) 3) ((* 6 7) 42))
is equivalent to:
(testeez ""
(test/equal "" (+ 1 2) 3)
(test/equal "" (* 6 7) 42))
Future versions of Testeez will add additional features, such as custom predicates and handling of errors.
See documentation more info...
To be added to the moderated scheme-announce email
list, ask neil@neilvandyke.org .
The current version of Testeez is 0.3 (2005-05-30).
You can download file testeez.scm, Scheme source code.
You can download file testeez.html, documentation in HTML format.
You can download file testeez.pdf, documentation in PDF format.
You can download file testeez.plt, a packaging for PLT Scheme.
Site © 1994-2008 Neil Van Dyke neil@neilvandyke.org XHTML 1.0 Strict CSS2 Legal