Allow internal definitions in custom checks
This commit is contained in:
parent
b4b8027267
commit
0957188c09
|
@ -354,12 +354,12 @@ information by default: the name of the checks and the values of the
|
||||||
parameters. Additionally the macro forms of checks grab location
|
parameters. Additionally the macro forms of checks grab location
|
||||||
information and the expressions passed as parameters.
|
information and the expressions passed as parameters.
|
||||||
|
|
||||||
@defform[(define-simple-check (name param ...) expr ...)]{
|
@defform[(define-simple-check (name param ...) body ...)]{
|
||||||
|
|
||||||
The @racket[define-simple-check] macro constructs a check
|
The @racket[define-simple-check] macro constructs a check
|
||||||
called @racket[name] that takes the params and an optional
|
called @racket[name] that takes the params and an optional
|
||||||
message as arguments and evaluates the @racket[expr]s. The
|
message as arguments and evaluates the @racket[body]s. The
|
||||||
check fails if the result of the @racket[expr]s is
|
check fails if the result of the last @racket[body] is
|
||||||
@racket[#f]. Otherwise the check succeeds. Note that
|
@racket[#f]. Otherwise the check succeeds. Note that
|
||||||
simple checks cannot report extra information using
|
simple checks cannot report extra information using
|
||||||
@racket[with-check-info].}
|
@racket[with-check-info].}
|
||||||
|
@ -379,14 +379,15 @@ We can use these checks in the usual way:
|
||||||
]
|
]
|
||||||
|
|
||||||
@defform*[[(define-binary-check (name pred actual expected))
|
@defform*[[(define-binary-check (name pred actual expected))
|
||||||
(define-binary-check (name actual expected) expr ...)]]{
|
(define-binary-check (name actual expected) body ...)]]{
|
||||||
|
|
||||||
The @racket[define-binary-check] macro constructs a check
|
The @racket[define-binary-check] macro constructs a check
|
||||||
that tests a binary predicate. It's benefit over
|
that tests a binary predicate. It's benefit over
|
||||||
@racket[define-simple-check] is in better reporting on check
|
@racket[define-simple-check] is in better reporting on check
|
||||||
failure. The first form of the macro accepts a binary
|
failure. The first form of the macro accepts a binary
|
||||||
predicate and tests if the predicate holds for the given
|
predicate and tests if the predicate holds for the given
|
||||||
values. The second form tests if @racket[expr] non-false.
|
values. The second form tests if the last @racket[body]
|
||||||
|
evaluates to a non-false value.
|
||||||
}
|
}
|
||||||
|
|
||||||
Here's the first form, where we use a predefined predicate
|
Here's the first form, where we use a predefined predicate
|
||||||
|
@ -411,7 +412,7 @@ tests a number if within 0.01 of the expected value:
|
||||||
(< (abs (- actual expected)) 0.01))
|
(< (abs (- actual expected)) 0.01))
|
||||||
]
|
]
|
||||||
|
|
||||||
@defform[(define-check (name param ...) expr ...)]{
|
@defform[(define-check (name param ...) body ...)]{
|
||||||
|
|
||||||
The @racket[define-check] macro acts in exactly the same way
|
The @racket[define-check] macro acts in exactly the same way
|
||||||
as @racket[define-simple-check], except the check only fails
|
as @racket[define-simple-check], except the check only fails
|
||||||
|
|
|
@ -109,7 +109,7 @@
|
||||||
|
|
||||||
(define-syntax (define-check stx)
|
(define-syntax (define-check stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
((define-check (name formal ...) expr ...)
|
((define-check (name formal ...) body ...)
|
||||||
(with-syntax ([reported-name
|
(with-syntax ([reported-name
|
||||||
(symbol->string (syntax->datum (syntax name)))]
|
(symbol->string (syntax->datum (syntax name)))]
|
||||||
[(actual ...)
|
[(actual ...)
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
(if message
|
(if message
|
||||||
(list (make-check-message message))
|
(list (make-check-message message))
|
||||||
null))
|
null))
|
||||||
(lambda () (begin0 (begin expr ...) (test-log! #t))))))
|
(lambda () (begin0 (let () body ...) (test-log! #t))))))
|
||||||
|
|
||||||
;; All checks should return (void).
|
;; All checks should return (void).
|
||||||
(void)))]
|
(void)))]
|
||||||
|
@ -176,22 +176,22 @@
|
||||||
|
|
||||||
(define-syntax define-simple-check
|
(define-syntax define-simple-check
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_ (name param ...) expr ...)
|
((_ (name param ...) body ...)
|
||||||
(define-check (name param ...)
|
(define-check (name param ...)
|
||||||
(let ((result (begin expr ...)))
|
(let ((result (let () body ...)))
|
||||||
(if result
|
(if result
|
||||||
result
|
result
|
||||||
(fail-check)))))))
|
(fail-check)))))))
|
||||||
|
|
||||||
(define-syntax define-binary-check
|
(define-syntax define-binary-check
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ (name expr1 expr2) expr ...)
|
[(_ (name expr1 expr2) body ...)
|
||||||
(define-check (name expr1 expr2)
|
(define-check (name expr1 expr2)
|
||||||
(with-check-info*
|
(with-check-info*
|
||||||
(list (make-check-actual expr1)
|
(list (make-check-actual expr1)
|
||||||
(make-check-expected expr2))
|
(make-check-expected expr2))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ((result (begin expr ...)))
|
(let ((result (let () body ...)))
|
||||||
(if result
|
(if result
|
||||||
result
|
result
|
||||||
(fail-check))))))]
|
(fail-check))))))]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user