Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rackunit sugar for testing many different calls to a procedure #86

Open
jackfirth opened this issue Sep 14, 2017 · 0 comments
Open

Comments

@jackfirth
Copy link
Owner

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 tests

Expressed 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant