Skip to content

Commit 5ffb7ce

Browse files
committed
Move check infos added by define-check outside scope of current-check-around
1 parent 3b68bcd commit 5ffb7ce

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

rackunit-lib/rackunit/private/check.rkt

+9-9
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@
8888
(define (name formal ... [message #f]
8989
#:location [location (list 'unknown #f #f #f #f)]
9090
#:expression [expression 'unknown])
91-
((current-check-around)
92-
(lambda ()
93-
(with-check-info*
94-
(list/if (make-check-name 'pub)
95-
(make-check-location location)
96-
(make-check-expression expression)
97-
(make-check-params (list formal ...))
98-
(and message (make-check-message message)))
99-
(lambda () (begin0 (let () body ...) (test-log! #t))))))
91+
(with-check-info*
92+
(list/if (make-check-name 'pub)
93+
(make-check-location location)
94+
(make-check-expression expression)
95+
(make-check-params (list formal ...))
96+
(and message (make-check-message message)))
97+
(λ ()
98+
((current-check-around)
99+
(λ () (begin0 (let () body ...) (test-log! #t))))))
100100
;; All checks should return (void)
101101
(void)))
102102

rackunit-test/tests/rackunit/check-info-test.rkt

+38-17
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
#lang racket/base
2929

30-
(require rackunit
30+
(require racket/function
31+
rackunit
3132
rackunit/private/check-info
3233
(submod rackunit/private/check-info for-test))
3334

@@ -70,30 +71,50 @@
7071
(check-equal? (check-info-value (make-check-actual 1)) (pretty-info 1))
7172
(check-equal? (check-info-value (make-check-expected 2)) (pretty-info 2)))
7273

74+
;; Utilities for collecting the info present in a check
75+
76+
(define current-info-box (make-parameter #f))
77+
78+
(define-check (check-foo arg1 arg2 arg3)
79+
(set-box! (current-info-box) (current-check-info)))
80+
81+
(define (call/info-box thnk)
82+
(parameterize ([current-info-box (box 'uninitialized)])
83+
(thnk)
84+
(map check-info-name (unbox (current-info-box)))))
85+
7386
(test-case "define-check adds certain infos automatically in a specific order"
74-
(define current-info-box (make-parameter #f))
75-
(define-check (check-foo arg1 arg2 arg3)
76-
(set-box! (current-info-box) (current-check-info)))
77-
(define (get-foo-info-names)
78-
(parameterize ([current-info-box (box 'uninitialized)])
79-
(check-foo 'arg1 'arg2 'arg3)
80-
(map check-info-name (unbox (current-info-box)))))
81-
(define expected-info-names
82-
(list 'name 'location 'expression 'params))
83-
(check-equal? (get-foo-info-names) expected-info-names))
87+
(define expected-info-names (list 'name 'location 'expression 'params))
88+
(check-equal? (call/info-box (thunk (check-foo 'arg1 'arg2 'arg3)))
89+
expected-info-names))
8490

8591
(test-case "define-check infos are added before custom infos"
86-
(define current-info-box (make-parameter #f))
8792
(define-check (check-foo/custom-info arg1 arg2 arg3)
8893
(with-check-info (['custom1 'foo] ['custom2 'bar])
8994
(set-box! (current-info-box) (current-check-info))))
90-
(define (get-foo-info-names)
91-
(parameterize ([current-info-box (box 'uninitialized)])
92-
(check-foo/custom-info 'arg1 'arg2 'arg3)
93-
(map check-info-name (unbox (current-info-box)))))
9495
(define expected-info-names
9596
(list 'name 'location 'expression 'params 'custom1 'custom2))
96-
(check-equal? (get-foo-info-names) expected-info-names))
97+
(check-equal? (call/info-box
98+
(thunk (check-foo/custom-info 'arg1 'arg2 'arg3)))
99+
expected-info-names))
100+
101+
(test-case "define-check infos are added before calling current-check-around"
102+
;; The check infos added by define-check are not considered part of the
103+
;; "check body": the expressions given to define-check that implement the
104+
;; check. The current-check-around param is called with the check body only,
105+
;; not the info-adding expressions. This lets rackunit clients use
106+
;; current-check-around to automatically add infos to certain uses of checks
107+
;; that appear after the default infos, or even override them while still
108+
;; preserving their position in the stack (the way a nested use of
109+
;; with-check-info would).
110+
(define (call-check-foo/extra-infos)
111+
(define old-around (current-check-around))
112+
(define (new-around chk)
113+
(with-check-info (['custom 'custom]) (old-around chk)))
114+
(parameterize ([current-check-around new-around])
115+
(check-foo 'arg1 'arg2 'arg3)))
116+
(check-equal? (call/info-box call-check-foo/extra-infos)
117+
(list 'name 'location 'expression 'params 'custom)))
97118

98119
(test-case "All tests for trim-current-directory"
99120
(test-case "trim-current-directory leaves directories outside the current directory alone"

0 commit comments

Comments
 (0)