1 Introduction
1.1 Example
1.2 Shorthand
1.3 Embedding
2 Interface
testeez
3 History
4 Legal
Version: 0.4

Testeez: Lightweight Unit Test Mechanism for R5RS Scheme

Neil Van Dyke

License: LGPL 3   Web: http://www.neilvandyke.org/testeez/

 (require (planet neil/testeez:1:2))

1 Introduction

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.

1.1 Example

A series of Testeez tests is listed within the testeez syntax. For example:

  (testeez
   "Foo Station"
  
   (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/eqv    "Full circle" (* (bar -21) 2) 42)
  
   (test/eqv    "Multiple"
                (values (+ 2 2) (string #\h #\i) (char-upcase #\p))
                (values 4 "hi" #\P)))

When evaluated, output like the following (which looks prettier fontified in Emacs’s *scheme* buffer) is printed:

;;; BEGIN "Foo Station" 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 Station" TESTS: FAILED
;;;     (Total: 4  Passed: 3  Failed: 1)

1.2 Shorthand

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.

1.3 Embedding

By following a simple convention, Testeez tests can be embedded in a Scheme source file with the code that is tested, while permitting the tests to 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 Station"
      ....))

2 Interface

The interface consists of the testeez syntax.

(testeez title form ...)

The testeez syntax contains a short string title and one or more forms, of the following syntaxes, which are evaluated in order.

3 History

4 Legal

Copyright (c) 2005–2009 Neil Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License (LGPL 3), or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.