Skip to content

Commit 2807a59

Browse files
committed
Support reporting sub-derivation failures from any specified judgment
1 parent c3bfe1d commit 2807a59

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,8 @@
30603060

30613061
(define-syntax (test-judgment-holds stx)
30623062
(syntax-parse stx
3063-
[(_ jf e:expr)
3063+
[(_ jf e:expr (~optional (~seq #:mutuals (mjf:id ...))
3064+
#:defaults ([(mjf 1) '()])))
30643065
(unless (judgment-form-id? #'jf)
30653066
(raise-syntax-error 'test-judgment-holds
30663067
"expected a modeless judgment-form"
@@ -3072,7 +3073,13 @@
30723073
"expected a modeless judgment-form"
30733074
#'jf))
30743075
#`(let ([derivation e])
3075-
(test-modeless-jf/proc 'jf (lambda (x) (judgment-holds jf x)) derivation (judgment-holds jf derivation) #,(get-srcloc stx)))]
3076+
(test-modeless-jf/proc 'jf
3077+
(make-hasheq
3078+
`((jf . ,(lambda (x) (judgment-holds jf x)))
3079+
#,@(for/list ([jf (attribute mjf)])
3080+
`(,jf . ,#`,(lambda (x) (judgment-holds #,jf x))))))
3081+
derivation (judgment-holds jf derivation)
3082+
#,(get-srcloc stx)))]
30763083
[(_ (jf . rest))
30773084
(unless (judgment-form-id? #'jf)
30783085
(raise-syntax-error 'test-judgment-holds
@@ -3159,23 +3166,24 @@
31593166
;; Sub-derivations from other judgments get ignored.
31603167
;; TODO: Can we create a generic sub-derivation checker that does not,
31613168
;; statically, know the name of the judgment it is checking?
3162-
(define (print-failing-subderivations jf f d)
3169+
(define (print-failing-subderivations jf jf-pred-hash d)
31633170
(define (print-derivation-error d)
31643171
(parameterize ([pretty-print-print-line (derivation-pretty-printer " ")])
31653172
(pretty-print d (current-error-port))))
3166-
(define (checkable-derivation d)
3167-
(equal? jf (car (derivation-term d))))
3173+
(define (check-derivation d)
3174+
(define f (hash-ref jf-pred-hash (car (derivation-term d)) (lambda () #f)))
3175+
(if f
3176+
(f d)
3177+
#t))
31683178
(let loop ([d d])
31693179
(let ([ls (derivation-subs d)])
31703180
(for ([d ls])
31713181
(unless (loop d)
31723182
(print-derivation-error d)))
3173-
(unless (if (checkable-derivation d)
3174-
(f d)
3175-
#t)
3183+
(unless (check-derivation d)
31763184
(print-derivation-error d)))))
31773185

3178-
(define (test-modeless-jf/proc jf jf-pred derivation val srcinfo)
3186+
(define (test-modeless-jf/proc jf jf-preds derivation val srcinfo)
31793187
(cond
31803188
[val
31813189
(inc-successes)]
@@ -3187,7 +3195,7 @@
31873195
(pretty-print derivation (current-error-port)))
31883196
(when (not (null? (derivation-subs derivation)))
31893197
(eprintf" because the following sub-derivations fail:\n")
3190-
(print-failing-subderivations jf jf-pred derivation))]))
3198+
(print-failing-subderivations jf jf-preds derivation))]))
31913199

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

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@
257257
(derivation '(J1 1 x) \"Base\" '())
258258
(derivation '(J2 1 1) \"Base\" '())))")))
259259

260+
(test
261+
(capture-output
262+
(test-judgment-holds J2 (derivation `(J2 (1 x) 1) "Pair"
263+
(list
264+
(derivation `(J1 1 x) "Base"
265+
(list))
266+
(derivation `(J2 1 1) "Base"
267+
(list))))
268+
#:mutuals (J1)))
269+
(regexp
270+
(regexp-quote "because the following sub-derivations fail:
271+
(derivation '(J1 1 x) \"Base\" '())
272+
(derivation
273+
'(J2 (1 x) 1)
274+
\"Pair\"
275+
(list
276+
(derivation '(J1 1 x) \"Base\" '())
277+
(derivation '(J2 1 1) \"Base\" '())))")))
278+
260279
(test
261280
(capture-output
262281
(test-judgment-holds J2 (derivation `(J2 (1 1) 2) "Pair"
@@ -286,7 +305,7 @@
286305
"")
287306

288307
(test (capture-output (test-results))
289-
"2 tests failed (out of 3 total).\n"))
308+
"3 tests failed (out of 4 total).\n"))
290309

291310
(let ()
292311
(define-judgment-form empty-language

0 commit comments

Comments
 (0)