SchemeUnit 2.0rc1: difficulty defining new assertions
Richard Cobbe <[email protected]> Fri, 31 Dec 2004 16:02:14 -0500
| Newsgroups | gmane.lisp.scheme.plt.schematics.general |
|---|---|
| Message-ID | <[email protected]> |
Greetings, all.
I'm having a little difficulty defining a custom assertion in SchemeUnit
2.0r1, DrScheme 208.1-cvs31dec2004.
I've got a custom exception type, exn:cj:parse, which is a subtype of
exn:application; it does not define any new fields.
I want to write something like this:
(assert-parse-exn MSG VAL EXPR)
where EXPR is an arbitrary expression. The assertion should pass if
evaluating EXPR throws an exn:cj:parse with a message of MSG and a value
that is equal? to VAL; the assertion should fail otherwise.
I've tried the four following possibilities, and only the fourth works.
The rest signal an uncaught exception of type exn:cj:parse when I try to
run the test case.
(define-simple-assertion (assert-parse-exn msg val expr)
(with-handlers ([exn:cj:parse?
(lambda (exn)
(and (string=? msg (exn-message exn))
(equal? val (exn:application-value exn))))]
[(lambda _ #t) (lambda _ #f)])
(begin expr #f)))
(define-assertion (assert-parse-exn msg val expr)
(assert-exn (lambda (exn)
(and (exn:cj:parse? exn)
(string=? msg (exn-message exn))
(equal? val (exn:application-value exn))))
(lambda () expr)))
(define-simple-assertion (assert-parse-exn msg val expr)
(assert-exn (lambda (exn)
(and (exn:cj:parse? exn)
(string=? msg (exn-message exn))
(equal? val (exn:application-value exn))))
(lambda () expr)))
;; This works.
(define-syntax assert-parse-exn
(syntax-rules ()
[(_ msg value expr)
(assert-exn (lambda (exn)
(and (exn:cj:parse? exn)
(string=? msg (exn:message exn))
(equal? val (exn:application-value exn))))
(lambda () expr))]))
Now, I got something that works, and it's not really that unpleasant.
I'm just a little bit confused about why none of the other three
attempts worked---and why they failed in the way they did.
Is there something weird going on with exception handlers inside
assertions? Are assertions not composable in the way I've tried to do
above? What's going on?
Thanks,
Richard
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt