File tree 3 files changed +45
-5
lines changed
rackunit-lib/rackunit/private
rackunit-test/tests/rackunit
3 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 21
21
[struct dynamic-info ([proc (-> any/c)])]
22
22
[info-value->string (-> any/c string?)]
23
23
[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 ))]
24
26
[with-check-info* ((listof check-info?) (-> any ) . -> . any )])
25
27
with-check-info)
26
28
27
29
(module+ for-test
28
30
(provide trim-current-directory))
29
31
32
+ (define (check-info-> dom cod)
33
+ (case-> (-> dom cod)
34
+ (-> (listof check-info?) dom cod)))
35
+
30
36
;; Structures --------------------------------------------------
31
37
32
38
(struct check-info (name value)
96
102
(define-check-type message any/c)
97
103
(define-check-type actual any/c #:wrapper pretty-info)
98
104
(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 )]))
Original file line number Diff line number Diff line change 164
164
[exn:fail?
165
165
(lambda (exn)
166
166
(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 " ))
169
170
(make-check-info 'exn-message (exn-message exn))
170
171
(make-check-info 'exn exn))
171
172
(lambda () (fail-check))))])
172
173
(thunk ))
173
174
(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 " )))
175
178
(lambda () (fail-check))))))
176
179
177
180
(define-check (check-not-exn thunk )
181
184
[exn?
182
185
(lambda (exn)
183
186
(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 " ))
186
190
(make-check-info 'exception-message (exn-message exn))
187
191
(make-check-info 'exception exn))
188
192
(lambda () (fail-check))))])
Original file line number Diff line number Diff line change 116
116
(check-equal? (call/info-box call-check-foo/extra-infos)
117
117
(list 'name 'location 'expression 'params 'custom )))
118
118
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
+
119
135
(test-case "All tests for trim-current-directory "
120
136
(test-case "trim-current-directory leaves directories outside the current directory alone "
121
137
(check-equal? (trim-current-directory "/foo/bar/ " ) "/foo/bar/ " ))
You can’t perform that action at this time.
0 commit comments