Skip to content

Commit 9803e2c

Browse files
authored
check-exn: stop ignoring the message argument (#65)
* check-info: add check-info-ref helpers Add `check-info-ref` and `check-info-contains-key?`, similar to `hash-ref`, but you can omit the "hashtable" argument --- by default its `(current-check-info)` * check-exn: only update check-info message when user did not supply one
1 parent d691872 commit 9803e2c

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

rackunit-lib/rackunit/private/check-info.rkt

+20
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@
2121
[struct dynamic-info ([proc (-> any/c)])]
2222
[info-value->string (-> any/c string?)]
2323
[current-check-info (parameter/c (listof check-info?))]
24+
[check-info-contains-key? (check-info-> symbol? boolean?)]
25+
[check-info-ref (check-info-> symbol? (or/c check-info? #f))]
2426
[with-check-info* ((listof check-info?) (-> any) . -> . any)])
2527
with-check-info)
2628

2729
(module+ for-test
2830
(provide trim-current-directory))
2931

32+
(define (check-info-> dom cod)
33+
(case-> (-> dom cod)
34+
(-> (listof check-info?) dom cod)))
35+
3036
;; Structures --------------------------------------------------
3137

3238
(struct check-info (name value)
@@ -96,3 +102,17 @@
96102
(define-check-type message any/c)
97103
(define-check-type actual any/c #:wrapper pretty-info)
98104
(define-check-type expected any/c #:wrapper pretty-info)
105+
106+
(define check-info-ref
107+
(case-lambda
108+
[(k)
109+
(check-info-ref (current-check-info) k)]
110+
[(info k)
111+
(findf (λ (i) (eq? k (check-info-name i))) info)]))
112+
113+
(define check-info-contains-key?
114+
(case-lambda
115+
[(k)
116+
(check-info-contains-key? (current-check-info) k)]
117+
[(info k)
118+
(and (check-info-ref info k) #t)]))

rackunit-lib/rackunit/private/check.rkt

+9-5
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@
164164
[exn:fail?
165165
(lambda (exn)
166166
(with-check-info*
167-
(list
168-
(make-check-message "Wrong exception raised")
167+
(list/if
168+
(and (not (check-info-contains-key? 'message))
169+
(make-check-message "Wrong exception raised"))
169170
(make-check-info 'exn-message (exn-message exn))
170171
(make-check-info 'exn exn))
171172
(lambda () (fail-check))))])
172173
(thunk))
173174
(with-check-info*
174-
(list (make-check-message "No exception raised"))
175+
(list/if
176+
(and (not (check-info-contains-key? 'message))
177+
(make-check-message "No exception raised")))
175178
(lambda () (fail-check))))))
176179

177180
(define-check (check-not-exn thunk)
@@ -181,8 +184,9 @@
181184
[exn?
182185
(lambda (exn)
183186
(with-check-info*
184-
(list
185-
(make-check-message "Exception raised")
187+
(list/if
188+
(and (not (check-info-contains-key? 'message))
189+
(make-check-message "Exception raised"))
186190
(make-check-info 'exception-message (exn-message exn))
187191
(make-check-info 'exception exn))
188192
(lambda () (fail-check))))])

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

+16
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@
116116
(check-equal? (call/info-box call-check-foo/extra-infos)
117117
(list 'name 'location 'expression 'params 'custom)))
118118

119+
(test-case "check-info-ref / check-info-contains-key"
120+
(define info0 (list (make-check-name 'my-name)))
121+
(define info1 (list (make-check-message 'my-message)))
122+
123+
(parameterize ([current-check-info info0])
124+
(check-not-false (check-info-ref 'name))
125+
(check-false (check-info-ref 'message))
126+
127+
(check-not-false (check-info-ref info1 'message))
128+
(check-false (check-info-ref info1 'name))
129+
130+
(check-true (check-info-contains-key? 'name))
131+
(check-false (check-info-contains-key? 'message))
132+
(check-true (check-info-contains-key? info1 'message))
133+
(check-false (check-info-contains-key? info1 'name))))
134+
119135
(test-case "All tests for trim-current-directory"
120136
(test-case "trim-current-directory leaves directories outside the current directory alone"
121137
(check-equal? (trim-current-directory "/foo/bar/") "/foo/bar/"))

0 commit comments

Comments
 (0)