[racket] module+ test... (require rackunit) results in unbound identifier when used in macro

From: Scott Klarenbach (scott at pointyhat.ca)
Date: Wed Jan 8 16:53:53 EST 2014

I have the following macro:

(define-syntax (define/test stx)
  (syntax-parse stx
[(_ (id arg ...) body ... #:test test-body ...)
 (with-syntax ([id-str (symbol->string (syntax->datum #'id))])
   #'(begin
   (define (id arg ...) body ...)
   (print id-str)
   (module+ test
 (require rackunit)
 (test-case id-str
   test-body ...))))]))

Which handles some testing boilerplate and allows me to use it like so:

(define/test (my-fn a b c)
  (print a)
  (print b)
  (print c)
  #:test
  (check-true #t)
  (check-false #t))

The problem is that the (require rackunit) expression inside of (module+
test) is not being picked up after macro expansion.  Running either the
code or the tests (via raco test) results in: unbound identifier check-true.

Adding (module+ (require rackunit)) to the top of the file solves the
problem and both the file and tests run as expected.

What am I missing?

Thanks.
-- 
Talk to you soon,

Scott Klarenbach

PointyHat Software Corp.
www.pointyhat.ca
p 604-568-4280
e scott at pointyhat.ca
200-1575 W. Georgia
Vancouver, BC V6G2V3

_______________________________________
To iterate is human; to recur, divine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140108/314fc766/attachment-0001.html>

Posted on the users mailing list.