Make interactive tests faster and support fresh namespaces.
Cuts off about 5-10% of unit test time. Reuse existing module registry that is shared with all the other tests. Fresh namespaces means that changes in one test do not affect other tests. Only bring in typed/racket/base so that it loads faster.
This commit is contained in:
parent
07eeb9ace4
commit
7a1ca9f124
|
@ -14,45 +14,65 @@
|
|||
(provide tests)
|
||||
(gen-test-main)
|
||||
|
||||
(define promised-ns
|
||||
(define-namespace-anchor anchor)
|
||||
|
||||
(define base-ns
|
||||
(delay
|
||||
(define ns (make-base-namespace))
|
||||
(eval '(require typed/racket) ns)
|
||||
(define ns (namespace-anchor->empty-namespace anchor))
|
||||
(parameterize ([current-namespace ns])
|
||||
(namespace-require 'typed/racket/base))
|
||||
ns))
|
||||
|
||||
;; get-ns: boolean? -> namespace?
|
||||
;; Returns a namespace with the bindings of typed/racket/base.
|
||||
;; If the argument is true, then it is a new namespace. This is slower but allows for tests that need
|
||||
;; to mutate the namespace to not clash with each other.
|
||||
(define (get-ns fresh)
|
||||
(if fresh
|
||||
(let ([ns (variable-reference->empty-namespace
|
||||
(eval '(#%variable-reference) (force base-ns)))])
|
||||
(parameterize ([current-namespace ns])
|
||||
(namespace-require 'typed/racket/base)
|
||||
ns))
|
||||
(force base-ns)))
|
||||
|
||||
(begin-for-syntax
|
||||
(define-splicing-syntax-class fresh-kw
|
||||
(pattern (~seq) #:attr fresh #'#f)
|
||||
(pattern #:fresh #:attr fresh #'#t)))
|
||||
|
||||
(define-syntax (test-form-exn stx)
|
||||
(syntax-parse stx
|
||||
[(_ regexp:expr form:expr)
|
||||
[(_ f:fresh-kw regexp:expr form:expr)
|
||||
(quasisyntax/loc stx
|
||||
(test-case #,(~a (syntax->datum #'form))
|
||||
(check-exn
|
||||
regexp
|
||||
(lambda ()
|
||||
(eval `(#%top-interaction .
|
||||
,(syntax->datum #'form)) (force promised-ns))))))]))
|
||||
,(syntax->datum #'form)) (get-ns f.fresh))))))]))
|
||||
|
||||
(define-syntax (test-form stx)
|
||||
(syntax-parse stx
|
||||
[(_ regexp:expr form:expr)
|
||||
[(_ f:fresh-kw (~seq regexp:expr form:expr) ...)
|
||||
(quasisyntax/loc stx
|
||||
(test-case #,(~a (syntax->datum #'form))
|
||||
(test-case #,(~a (syntax->datum #'(form ...)))
|
||||
(define ns (get-ns f.fresh))
|
||||
(check-regexp-match
|
||||
regexp
|
||||
(with-output-to-string
|
||||
(lambda ()
|
||||
(eval `(#%top-interaction .
|
||||
,(syntax->datum #'form)) (force promised-ns)))))))]))
|
||||
,(syntax->datum #'form)) ns)))) ...))]))
|
||||
|
||||
;; Add 'only at the toplevel tests'
|
||||
(define tests
|
||||
(test-suite "Interactive tests"
|
||||
|
||||
(test-form #rx""
|
||||
(module test racket))
|
||||
(test-form #rx""
|
||||
(define module displayln))
|
||||
(test-form #rx"racket"
|
||||
(module 'racket))
|
||||
(test-form #:fresh
|
||||
#rx"" (module test racket)
|
||||
#rx"" (define module displayln)
|
||||
#rx"racket" (module 'racket))
|
||||
|
||||
(test-form #rx"1"
|
||||
(:type 1))
|
||||
|
|
Loading…
Reference in New Issue
Block a user