15 Macro Testing
(require syntax/macro-testing) | package: base |
syntax
(phase1-eval ct-expr maybe-quote maybe-catch?)
maybe-quote =
| #:quote quote-id maybe-catch? =
| #:catch? catch?
If catch? is #t, then if the evaluation of ct-expr raises a compile-time exception, it is caught and converted to a run-time exception.
> (struct point (x y)) > (phase1-eval (extract-struct-info (syntax-local-value #'point))) '(struct:point point point? (point-y point-x) (#f #f) #t)
> (phase1-eval (extract-struct-info (syntax-local-value #'point)) #:quote quote-syntax) #<syntax (struct:point point point? (p...>
Added in version 6.3 of package base.
syntax
(convert-compile-time-error expr)
Use convert-compile-time-error to write tests for compile-time error checking like syntax errors:
> (check-exn #rx"missing an \"else\" expression" (lambda () (convert-compile-time-error (if 1 2))))
> (check-exn #rx"missing formals and body" (lambda () (convert-compile-time-error (lambda))))
--------------------
FAILURE
message: "Wrong exception raised"
exn-message: "eval:6:0: lambda: bad syntax\n in: (lambda)"
exn: #(struct:exn:fail:syntax "eval:6:0: lambda: bad syntax\n in: (lambda)" #<continuation-mark-set> (#<syntax:6:0 (lambda)>))
name: check-exn
location: (eval 6 0 6 1)
expression: (check-exn #rx"missing formals and body" (lambda () (convert-compile-time-error (lambda))))
params: (#rx"missing formals and body" #<procedure:temp10>)
Check failure
--------------------
Without the use of convert-compile-time-error, the checks above would not be executed because the test program would not compile.
Added in version 6.3 of package base.
syntax
(convert-syntax-error expr)
> (check-exn #rx"^lambda: bad syntax$" (lambda () (convert-syntax-error (lambda))))
Added in version 6.3 of package base.