5 Daily Workflow and Options🔗ℹ

Verbose mode can be enabled by setting RECSPECS_VERBOSE or by parameterizing recspecs-verbose?. When enabled, captured output is echoed to the real output port as it is produced:

RECSPECS_VERBOSE=1 raco test my-test.rkt

For Emacs users, the accompanying "emacs/recspecs.el" file provides recspecs-update-at-point, which runs the current file under racket-test with the update environment variables set for the expectation at the cursor position. After the test finishes the buffer is automatically reverted so that any updated expectations are reloaded from disk.

Use #:port 'stderr with expect, expect-file, or capture-output to record output written to the current error port instead of the output port. Pass 'both to capture from both ports simultaneously:

#:lang at-exp racket
(require recspecs)
 
(expect (display "oops" (current-error-port))
        #:port 'stderr
"oops")

Output can be transformed before it is compared by parameterizing recspecs-output-filter. The parameter holds a procedure that receives the captured string and returns a new string used for comparison and updating. For example, trim incidental surrounding whitespace:

(parameterize ([recspecs-output-filter string-trim])
  (expect (display "  hi  ") "hi"))

The thunk that performs the test is executed via the procedure stored in recspecs-runner. The default simply calls the thunk, but advanced tests can replace it to control the runtime context. For example, you can limit memory usage with a new custodian and redirect the error port:

(parameterize ([recspecs-runner
                (lambda (th)
                  (call-in-nested-thread
                   (lambda ()
                     (custodian-limit-memory (current-custodian) (* 1024 1024))
                     (parameterize ([current-error-port (current-output-port)])
                       (th)))))])
  (expect (begin
            (display "oops" (current-error-port))
            (make-bytes (* 2 1024 1024)))
          "oops"))