You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
[(123) 'some-return-value]
[(#:kw1) 'some-other-return-value]
[(12345) #:raise#rx"something went wrong"]
[(12'not-a-number) #:contract-exn'not-a-number#:expected number?]
[() #:raise exn:fail:contract:arity]) ;; as a convenience, struct identifiers become predicate tests
Expressed without expectations, the above would be:
(test-case "foo"
(check-equal? (foo 123) 'some-return-value)
(check-equal? (foo #;kw 1) 'some-other-return-value)
(check-exn #rx"something went wrong" (thunk (f 12345)))
;; we need two checks for the contract exception to assert the expected part with a regexp
(let ([call (thunk (f 12'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.
The text was updated successfully, but these errors were encountered:
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:
Expressed without expectations, the above would be:
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 justequal?
, 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.The text was updated successfully, but these errors were encountered: