[racket] Price of RackUnit

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Thu Jul 7 05:35:02 EDT 2011


On 2011 Jul 7, at 02:01, Neil Van Dyke wrote:

> For the example module you gave, I believe that any time that module is 
> loaded by "require" or similar, those tests will be evaluated.
> There is a recent discussion thread that's relevant to wanting to embed 
> tests in modules this way:
> http://lists.racket-lang.org/dev/archive/2011-June/006815.html

I have in the past used a slightly hacky way of approaching this.

;; implementation module
(define-syntax expect                   ;ignore (expect) forms -- tested elsewhere
  (syntax-rules ()
    ((_ form ...) (void))))
(expect expected actual)

And then in a separate module:

;; test module
(define (test-a-module test-file)
  (let ((ns (make-base-namespace)))
    (parameterize ((current-namespace ns))
      (namespace-require '(prefix srfi19: srfi/19))
      (namespace-require '(prefix rdf: rdf/rdf))
      (namespace-require test-file)
;; read the module forms one by one, spotting (expect) forms and evaluating them.

It's obviously not very generic, as it stands, and it still can only test procedures exported from the module, but it does keep the test cases with the code, with minimal penalty at loading time.

That said, it's a pattern which doesn't appear to have been mentioned in this thread or last month's one.

Best wishes,


Norman Gray  :  http://nxg.me.uk
School of Physics and Astronomy, University of Glasgow, UK

Posted on the users mailing list.