8 Procedure Expectations
procedure
(expect-call args call-exp) → expectation?
args : arguments? call-exp : expectation?
> (define exp-addition (expect-call (arguments 3 8) (expect-return 11))) > (expect! + exp-addition) > (expect! - exp-addition) expected a different value
subject: #<procedure:->
in: call with (arguments 3 8)
in: the return value
expected: equal? to 11
actual: -5
> (expect! (thunk 'wrong-arity) exp-addition) expected a more inclusive arity
subject: #<procedure>
in: the procedure's arity
expected: arity accepting 2 arguments
actual: 0
> (expect! (thunk* (raise 'error)) exp-addition) expected no value raised
subject: #<procedure:eval:5:0>
in: call with (arguments 3 8)
in: the raised value
expected: nothing
actual: 'error
procedure
(expect-apply f call-exp) → expectation?
f : procedure? call-exp : expectation?
> (define exp-add1=10 (expect-apply add1 (expect-return 10))) > (expect! (arguments 9) exp-add1=10) > (expect! (arguments 2) exp-add1=10) expected a different value
subject: (arguments 2)
in: application to #<procedure:add1>
in: the return value
expected: equal? to 10
actual: 3
procedure
(expect-return value-exp ...) → expectation?
value-exp : any/c
> (expect! (thunk 'foo) (expect-return 'foo)) > (expect! (thunk 'bar) (expect-return 'foo)) expected a different value
subject: #<procedure>
in: the return value
expected: equal? to 'foo
actual: 'bar
> (expect! (thunk (raise 'error)) (expect-return 'foo)) expected no value raised
subject: #<procedure>
in: the raised value
expected: nothing
actual: 'error
> (expect! (thunk (values 'foo 'bar)) (expect-return 'foo 'bar))
procedure
(expect-return* values-exp) → expectation?
values-exp : (or/c list? expectation?)
> (define expect-even-values (expect-return* (expect-list-length (expect-pred even?)))) > (expect! (thunk (values)) expect-even-values) > (expect! (thunk (values 'foo 'bar)) expect-even-values) > (expect! (thunk 'foo) expect-even-values) expected a different kind of value
subject: #<procedure>
in: the return values list
in: the number of items
expected: even?
actual: 1
procedure
(expect-raise [raise-exp]) → expectation?
raise-exp : any/c = expect-any
> (define (raise-foo) (raise 'foo)) > (expect! raise-foo (expect-raise 'foo)) > (define (success) 'success) > (expect! success (expect-raise 'foo)) expected any value raised
subject: #<procedure:success>
in: the raised value
expected: anything
actual: nothing
> (define (raise-bar) (raise 'bar)) > (expect! raise-bar (expect-raise 'foo)) expected a different value
subject: #<procedure:raise-bar>
in: the raised value
expected: equal? to 'foo
actual: 'bar
value
> (expect! (thunk 'success) expect-not-raise) > (expect! (thunk (raise 'failure)) expect-not-raise) expected no value raised
subject: #<procedure>
in: the raised value
expected: nothing
actual: 'failure
> (define (not-a-thunk unexpected-arg) 'foo) > (expect! not-a-thunk expect-not-raise) expected a more inclusive arity
subject: #<procedure:not-a-thunk>
in: the procedure's arity
expected: arity accepting 0 arguments
actual: 1
procedure
(expect-exn [msg-exp]) → expectation?
msg-exp : (or/c string? regexp? expectation?) = expect-any
> (define foo-exn (make-exn "foo exception" (current-continuation-marks))) > (expect! foo-exn (expect-exn #rx"foo")) > (expect! foo-exn (expect-exn "foo exception")) > (expect! foo-exn (expect-exn "foo")) expected a different value
subject: (exn "foo exception" #<continuation-mark-set>)
in: the exn-message struct field
expected: equal? to "foo"
actual: "foo exception"
> (expect! 'not-an-exn (expect-exn)) expected a different kind of value
subject: 'not-an-exn
expected: exn?
actual: 'not-an-exn
procedure
(expect-call-exn args [msg-exp]) → expectation?
args : arguments? msg-exp : (or/c string? regexp? expectation?) = expect-any
procedure
(expect-apply-exn f [msg-exp]) → expectation?
f : procedure? msg-exp : (or/c string? regexp? expectation?) = expect-any
8.1 Procedure Context Structures
value
value
value
struct
(struct call-context context (args) #:transparent) args : arguments?
procedure
(make-call-context args) → call-context?
args : arguments?
struct
(struct apply-context context (proc) #:transparent) proc : procedure?
procedure
(make-apply-context proc) → apply-context?
proc : procedure?
value
8.2 Procedure Attribute Structures
struct
(struct arity-includes-attribute attribute (value) #:transparent) value : procedure-arity?
procedure
(make-arity-includes-attribute arity)
→ arity-includes-attribute? arity : procedure-arity?