|
27 | 27 |
|
28 | 28 | #lang racket/base
|
29 | 29 |
|
30 |
| -(require rackunit |
| 30 | +(require racket/function |
| 31 | + rackunit |
31 | 32 | rackunit/private/check-info
|
32 | 33 | (submod rackunit/private/check-info for-test))
|
33 | 34 |
|
|
70 | 71 | (check-equal? (check-info-value (make-check-actual 1)) (pretty-info 1))
|
71 | 72 | (check-equal? (check-info-value (make-check-expected 2)) (pretty-info 2)))
|
72 | 73 |
|
| 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 | + |
73 | 86 | (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)) |
84 | 90 |
|
85 | 91 | (test-case "define-check infos are added before custom infos"
|
86 |
| - (define current-info-box (make-parameter #f)) |
87 | 92 | (define-check (check-foo/custom-info arg1 arg2 arg3)
|
88 | 93 | (with-check-info (['custom1 'foo] ['custom2 'bar])
|
89 | 94 | (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))))) |
94 | 95 | (define expected-info-names
|
95 | 96 | (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))) |
97 | 118 |
|
98 | 119 | (test-case "All tests for trim-current-directory"
|
99 | 120 | (test-case "trim-current-directory leaves directories outside the current directory alone"
|
|
0 commit comments