scribble/lp and test modules (redux)

57 views
Skip to first unread message

Tim Brown

unread,
Jul 2, 2015, 7:24:00 AM7/2/15
to Racket Users
I have the following scribble module (in /tmp/tim.rkt)

#lang scribble/lp
@(chunk
<*>
(module m racket
(provide x)
(define x 22))

(module test racket
(require rackunit)
(require (submod ".." m))
(check-equal? 32 x)))

When I run it in DrRacket (with require test module) or run
"raco test /tmp/tim.rkt" the unit test fails.

I can only import the functionality of this module, however with:
(require (submod (file "/tmp/tim.rkt") m))

If I pull the provide and define of x up into the top-level module:

#lang scribble/lp
@(chunk
<*>
(module m racket
(provide x)
(define x 22))

(module+ test
(require rackunit)
;(require (submod ".." m))
(check-equal? 32 x))

(module test2 racket
(require rackunit)
;(require (submod ".." m))
(check-equal? 32 x)))

Both both test and test2 complain about:

x: unbound identifier in module in: x

What is the correct pattern for writing unit tests in scribble/lp
modules (basically so I can "raco test" all my .rkt files)?

· Am I just /missing something/ as per usual?
· Should I use the first style, and re-export m through a second file?

Tim

--
Tim Brown CEng MBCS <tim....@cityc.co.uk>
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
City Computing Limited · www.cityc.co.uk
City House · Sutton Park Rd · Sutton · Surrey · SM1 2AE · GB
T:+44 20 8770 2110 · F:+44 20 8770 2130
────────────────────────────────────────────────────────────────────────
City Computing Limited registered in London No:1767817.
Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE
VAT No: GB 918 4680 96

Tim Brown

unread,
Jul 7, 2015, 5:15:18 AM7/7/15
to racket...@googlegroups.com, us...@racket-lang.org
Is there something wrong with this question? This issue has been bugging
me for a while :-/

Tim

Matthew Flatt

unread,
Jul 7, 2015, 9:24:28 PM7/7/15
to Tim Brown, racket...@googlegroups.com, us...@racket-lang.org
Sorry --- I lost track of this one.

The problem here is subtle: `scribble/lp` defines `#%module-begin`, and
a `module+` (or `module* test #f`) form picks up that `#%module-begin`
for the submodule body, where it isn't wanted and doesn't work.

The variant

#lang scribble/lp
@(chunk
<*>
(require (only-in racket/base #%module-begin))
(define x 22)
(module+ test
(require rackunit)
(check-equal? 32 'x)))

should work. This example uses `#%module-begin` from `scribble/lp` for
the outer module, but it shadows `#%module-begin` with the normal one
for submodules. You don't want that extra `require` line in your
program, though, so I'll have to think about a better solution.
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages