[Snow-users-list] Unit Tests

Marc Feeley feeley at iro.umontreal.ca
Sun Aug 12 17:34:32 EDT 2007

On 12-Aug-07, at 11:55 AM, andrew cooke wrote:

> I can't seem to find a Snow library for unit tests.

The test framework is integrated into Snow.  It is not a separate  
package.  You need to use the test* and expect* forms.  Here is the  
documentation from the Snow documentation page:
test* and expect* forms

The test* form can be used to include self test code within the  
package body. The definitions and expressions inside test* forms are  
normally ignored. However, test* forms are transformed into begin  
forms when they are activated in a Snow framework implementation  
specific way (for example the SNOW_TEST environment variable of the  
generic Snow framework implementation).

The expect* form can only appear inside test* forms. The expect* form  
takes a single argument, an expression whose value is expected to be  
non-false. The test is said to have failed when the expression  
evaluates to #f or an exception is raised. The result of the self  
tests (number of failed tests, etc) is reported in a system dependent  

For example:

   (package* math/v1.0.0
    (provide: (define (square x))))

   (define (square x) (* x x))

    (define (dec n) (- n 1))
    (expect* (= 100 (square 10)))
    (expect* (= 81 (square (dec 10)))))

Script syntax

The generic Snow can be used to write scripts. A script has the same  
syntax as a package, except the first line is a shell command which  
executes the program "snow". Here's the source code of a minimal  
script, which is stored in the file "go.scm":

   ":";exec snow -- "$0" "$@"

   (package* go/v1.0.0
    (require: hostos/v1)
    (require: fixnum/v1))

   (define (double x)
     (snow-fxarithmetic-shift-left x 1))

   (test* (expect* (= 8 (double 4))))

   (write (double (string->number (cadr (snow-command-line)))))
Scripts are normally executed with the host Scheme system which was  
configured when the generic Snow implementation was installed. This  
can be changed by setting the SNOW_HOST environment variable to the  
name of the required host Scheme system (i.e. bigloo, chez, chicken,  
gambit, etc). The special name all will execute the script with all  
the installed Scheme systems. This is useful for testing the  
portability of a package. The environment variable SNOW_TEST can be  
set to the name(s) of the package(s) whose self tests must be  
executed. The environment variable SNOW_DEBUG when set to 1 will  
cause some debugging information to be output. For example:

   % chmod +x go.scm
   % ./go.scm 500
   % SNOW_HOST=mzscheme ./go.scm 500
   % SNOW_HOST=all ./go.scm 500
   ------------------------------------------------------------ bigloo
   ------------------------------------------------------------ chicken
   ------------------------------------------------------------ gambit
   ------------------------------------------------------------ mzscheme
   ------------------------------------------------------------ petite
   ------------------------------------------------------------ scm
   ------------------------------------------------------------ scsh
   ------------------------------------------------------------ stklos
   % SNOW_TEST="fixnum go" SNOW_HOST=mzscheme ./go.scm 500
   *** SNOW TESTS: passed all 7 tests.


More information about the Snow-users-list mailing list