rackunit: fix require/expose to work on variable-like macros
(eg struct names, names w/ contracts, etc)
This commit is contained in:
parent
9bee07b7c0
commit
3b707c1e54
|
@ -29,7 +29,7 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require (for-syntax racket/base)
|
(require (for-syntax racket/base)
|
||||||
mzlib/etc
|
racket/runtime-path
|
||||||
"check.rkt"
|
"check.rkt"
|
||||||
"test-suite.rkt"
|
"test-suite.rkt"
|
||||||
"test-case.rkt")
|
"test-case.rkt")
|
||||||
|
@ -38,30 +38,28 @@
|
||||||
test-suite*
|
test-suite*
|
||||||
check-regexp-match)
|
check-regexp-match)
|
||||||
|
|
||||||
;; Requires a module and exposes some of its unprovided
|
(define-namespace-anchor this-ns)
|
||||||
;; (non-syntax!) identifiers.
|
|
||||||
|
;; Requires a module and exposes some of its unprovided identifiers.
|
||||||
;; USAGE: (require/expose MODULE-NAME (IDS ...))
|
;; USAGE: (require/expose MODULE-NAME (IDS ...))
|
||||||
;; where MODULE-NAME is as in the MzRacket manual (i.e.,
|
;; where MODULE-NAME is as in the MzRacket manual (i.e.,
|
||||||
;; a standard module spec) and IDS are the un-provided
|
;; a standard module spec) and IDS are the un-provided
|
||||||
;; identifiers that you wish to expose in the current
|
;; identifiers that you wish to expose in the current
|
||||||
;; module.
|
;; module.
|
||||||
(define-syntax (require/expose stx)
|
(define-syntax require/expose
|
||||||
(syntax-case stx ()
|
(syntax-rules ()
|
||||||
[(_ mod (ids ...))
|
[(_ mod (id ...))
|
||||||
(quasisyntax/loc stx
|
(begin
|
||||||
(begin
|
(require (only-in mod))
|
||||||
(require (only-in mod))
|
(define-runtime-module-path the-resolved-mod mod)
|
||||||
(define-values (ids ...)
|
(define-values (id ...)
|
||||||
(parameterize
|
(let ([the-mod (resolved-module-path-name the-resolved-mod)])
|
||||||
([current-load-relative-directory
|
;; Use the correct module-registry:
|
||||||
#,(datum->syntax
|
(parameterize ((current-namespace (namespace-anchor->namespace this-ns)))
|
||||||
stx
|
;; Get the module namespace:
|
||||||
`(,#'this-expression-source-directory)
|
(parameterize ((current-namespace (module->namespace the-mod)))
|
||||||
stx)])
|
;; Use eval so id-macros (eg struct constructors, names w/ contracts) work:
|
||||||
(let ([ns (module->namespace 'mod)])
|
(values (eval 'id) ...))))))]))
|
||||||
(parameterize ([current-namespace ns])
|
|
||||||
(values
|
|
||||||
(namespace-variable-value 'ids)...)))))))]))
|
|
||||||
|
|
||||||
(define-syntax test-suite*
|
(define-syntax test-suite*
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user