Skip to content

Commit 740b3db

Browse files
wilbowmarfindler
authored andcommitted
Modified test-judgment-holds to report failing sub-derivations
When called on a modeless judgment, if the test fails, test-judgment-holds will isolate all failing sub-derivations and report them as part of the error message.
1 parent dce339c commit 740b3db

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

redex-lib/redex/private/reduction-semantics.rkt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@
30723072
"expected a modeless judgment-form"
30733073
#'jf))
30743074
#`(let ([derivation e])
3075-
(test-modeless-jf/proc 'jf derivation (judgment-holds jf derivation) #,(get-srcloc stx)))]
3075+
(test-modeless-jf/proc 'jf (lambda (x) (judgment-holds jf x)) derivation (judgment-holds jf derivation) #,(get-srcloc stx)))]
30763076
[(_ (jf . rest))
30773077
(unless (judgment-form-id? #'jf)
30783078
(raise-syntax-error 'test-judgment-holds
@@ -3141,25 +3141,42 @@
31413141
;; this case should always result in a syntax error
31423142
#`(judgment-holds #,orig-jf-stx)])]))
31433143

3144-
(define (test-modeless-jf/proc jf derivation val srcinfo)
3144+
(define (derivation-pretty-printer pad)
3145+
(λ (new-line-number op old-len col)
3146+
(cond
3147+
[(number? new-line-number)
3148+
(unless (= new-line-number 0) (newline op))
3149+
(display pad op)
3150+
2]
3151+
[else
3152+
(newline op)
3153+
0])))
3154+
3155+
(define (print-failing-subderivations f d)
3156+
(define (print-derivation-error d)
3157+
(parameterize ([pretty-print-print-line (derivation-pretty-printer " ")])
3158+
(pretty-print d (current-error-port))))
3159+
(let loop ([d d])
3160+
(let ([ls (derivation-subs d)])
3161+
(for ([d ls])
3162+
(unless (loop d)
3163+
(print-derivation-error d)))
3164+
(unless (f d)
3165+
(print-derivation-error d)))))
3166+
3167+
(define (test-modeless-jf/proc jf jf-pred derivation val srcinfo)
31453168
(cond
31463169
[val
31473170
(inc-successes)]
31483171
[else
31493172
(inc-failures)
31503173
(print-failed srcinfo)
31513174
(eprintf " derivation does not satisfy ~a\n" jf)
3152-
(parameterize ([pretty-print-print-line
3153-
(λ (new-line-number op old-len col)
3154-
(cond
3155-
[(number? new-line-number)
3156-
(unless (= new-line-number 0) (newline op))
3157-
(display " " op)
3158-
2]
3159-
[else
3160-
(newline op)
3161-
0]))])
3162-
(pretty-print derivation (current-error-port)))]))
3175+
(parameterize ([pretty-print-print-line (derivation-pretty-printer " ")])
3176+
(pretty-print derivation (current-error-port)))
3177+
(when (not (null? (derivation-subs derivation)))
3178+
(eprintf" because the following sub-derivations fail:\n")
3179+
(print-failing-subderivations jf-pred derivation))]))
31633180

31643181
(define (test-judgment-holds/proc thunk name lang pat srcinfo is-relation?)
31653182
(define results (thunk))

redex-test/redex/tests/tl-test.rkt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,47 @@
185185
(test (capture-output (test-results))
186186
"1 test failed (out of 2 total).\n"))
187187

188+
(let ()
189+
(define-judgment-form empty-language
190+
[----------- "Base"
191+
(J natural 1)]
192+
193+
[(J any_1 any_3)
194+
-------------- "Pair"
195+
(J (any_1 any_2) any_3)])
196+
197+
(test
198+
(capture-output
199+
(test-judgment-holds J (derivation `(J (x 0) 0) "Pair"
200+
(list
201+
(derivation `(J x 0) "Base" (list))))))
202+
(regexp (regexp-quote "because the following sub-derivations fail:\n (derivation '(J x 0) \"Base\" '())\n (derivation '(J (x 0) 0) \"Pair\" (list (derivation '(J x 0) \"Base\" '())))\n")))
203+
204+
(test
205+
(capture-output
206+
(test-judgment-holds J (derivation `(J (1 x) 0) "Pair"
207+
(list
208+
(derivation `(J 1 0) "Base" (list))))))
209+
(regexp (regexp-quote "because the following sub-derivations fail:\n (derivation '(J 1 0) \"Base\" '())\n (derivation '(J (1 x) 0) \"Pair\" (list (derivation '(J 1 0) \"Base\" '())))\n")))
210+
211+
(test
212+
(capture-output
213+
(test-judgment-holds J (derivation `(J x 0) "Base" (list))))
214+
(regexp
215+
(string-append
216+
(regexp-quote "derivation does not satisfy J\n (derivation '(J x 0) \"Base\" '())\n")
217+
"$")))
218+
219+
(test
220+
(capture-output
221+
(test-judgment-holds J (derivation `(J (1 x) 1) "Pair"
222+
(list
223+
(derivation `(J 1 1) "Base" (list))))))
224+
"")
225+
226+
(test (capture-output (test-results))
227+
"3 tests failed (out of 4 total).\n"))
228+
188229
(let ()
189230
(define-judgment-form empty-language
190231
#:mode (broken-swap I I O O)

0 commit comments

Comments
 (0)