Test Utilities

_Test Utilities_

This collection provides one file:

 _test.ss_: utilities for unit testing


> (in-new-directory dir e1 e2 ...) :: syntax

A special form that creates a new directory with the path specified by `dir' and
evaluates the subexpressions with the value of the _current-directory_ parameter
set to the new directory for the duration of the evaluation. After evaluation
terminates, either by completing normally, raising an exception, or invoking a
continuation, if the value of the `keep-new-directories?' is #f, the temporary
directory is deleted.

Temporary directories created by further invocations of `in-new-directory'
during the extent of the evaluation are *not* deleted, so that they may be
accessed during the test.

You can prevent any directories from being deleted by wrapping a top-level
instance of `in-new-directory' with

    (parameterize ([keep-new-directories #t])

> keep-new-directories? :: (parameterof boolean)

When the evaluation of an instance of the `in-new-directory' form terminates, it
checks the current value of this parameter to determine whether to delete the
temporary directory it created.

This parameter is initially set to #f, so that at the top level of any
particular test, the entire directory tree created by `in-new-directory' will be
deleted. It is set to #t for all subsequent tests nested within an initial

WARNING --------------------------------------------------------------

Note that if you capture the continuation during the extent of an
`in-new-directory' and reinvoke it after its initial evaluation has terminated,
all bets are off. In particular, the directory will have already been deleted.

EXAMPLE --------------------------------------------------------------

(in-new-directory "sandbox"
  (in-new-directory "subdir-1"
    ;; make a bunch of files ...
  (in-new-directory "subdir-2"
    ;; make a bunch more files ...
  ... (directory-list "subdir-1") ...
  ... (directory-list "subdir-1") ...

(directory-exists? "sandbox")