-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Many test cases are just a series of calls to a procedure that check what values are returned, or check that a certain exception is raised, or check that a contract or arity violation occurred. Something like this might make that more pleasant:
(test-case/procedure foo
[(1 2 3) 'some-return-value]
[(#:kw 1) 'some-other-return-value]
[(1 2 3 4 5) #:raise #rx"something went wrong"]
[(1 2 'not-a-number) #:contract-exn 'not-a-number #:expected number?]
[() #:raise exn:fail:contract:arity]) ;; as a convenience, struct identifiers become predicate testsExpressed without expectations, the above would be:
(test-case "foo"
(check-equal? (foo 1 2 3) 'some-return-value)
(check-equal? (foo #;kw 1) 'some-other-return-value)
(check-exn #rx"something went wrong" (thunk (f 1 2 3 4 5)))
;; we need two checks for the contract exception to assert the expected part with a regexp
(let ([call (thunk (f 1 2 'not-a-number))])
(check-exn exn:fail:contract? call)
(check-exn #rx"expeced: number?" call))
(check-exn exn:fail:contract:arity? f))However, the expectation tests can use expect-call to get much better error messages that include what the argument expressions evaluated to, and expectations allow much more complex assertions than just equal?, predicate, or regular expression assertions. A generic #:call keyword could act as a hook for using more general expectations that operate on the thunk representing the call.
Reactions are currently unavailable