mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
Add current-test-value-formatter.
This commit is contained in:
parent
dce487fa3a
commit
d677a135f1
2 changed files with 24 additions and 11 deletions
|
@ -526,6 +526,7 @@
|
||||||
(not (assq-ref info 'line-number)))
|
(not (assq-ref info 'line-number)))
|
||||||
`((file-name . ,(car (pair-source expr)))
|
`((file-name . ,(car (pair-source expr)))
|
||||||
(line-number . ,(cdr (pair-source expr)))
|
(line-number . ,(cdr (pair-source expr)))
|
||||||
|
(format . ,(current-test-value-formatter))
|
||||||
,@info)
|
,@info)
|
||||||
info)))
|
info)))
|
||||||
|
|
||||||
|
@ -584,14 +585,20 @@
|
||||||
((SKIP) "-")
|
((SKIP) "-")
|
||||||
(else "."))))
|
(else "."))))
|
||||||
|
|
||||||
(define (display-expected/actual expected actual)
|
(define (display-expected/actual expected actual format)
|
||||||
(let* ((e-str (write-to-string expected))
|
(let ((e-str (format expected))
|
||||||
(a-str (write-to-string actual))
|
(a-str (format actual)))
|
||||||
(diff (diff e-str a-str read-char)))
|
(if (and (equal? e-str a-str)
|
||||||
(write-string "expected ")
|
(not (eqv? format write-to-string)))
|
||||||
(write-string (edits->string/color (car diff) (car (cddr diff)) 1))
|
;; If the formatter can't display any difference, fall back to
|
||||||
(write-string " but got ")
|
;; write-to-string.
|
||||||
(write-string (edits->string/color (cadr diff) (car (cddr diff)) 2))))
|
(display-expected/actual expected actual write-to-string)
|
||||||
|
(let ((diff (diff e-str a-str read-char)))
|
||||||
|
(write-string "expected ")
|
||||||
|
(write-string (edits->string/color (car diff) (car (cddr diff)) 1))
|
||||||
|
(write-string " but got ")
|
||||||
|
(write-string (edits->string/color (cadr diff) (car (cddr diff)) 2))
|
||||||
|
))))
|
||||||
|
|
||||||
(define (test-print-explanation indent status info)
|
(define (test-print-explanation indent status info)
|
||||||
(cond
|
(cond
|
||||||
|
@ -617,8 +624,9 @@
|
||||||
(write (assq-ref info 'result)))))
|
(write (assq-ref info 'result)))))
|
||||||
((eq? status 'FAIL)
|
((eq? status 'FAIL)
|
||||||
(display indent)
|
(display indent)
|
||||||
(display-expected/actual
|
(display-expected/actual (assq-ref info 'expected)
|
||||||
(assq-ref info 'expected) (assq-ref info 'result))))
|
(assq-ref info 'result)
|
||||||
|
(or (assq-ref info 'format) write-to-string))))
|
||||||
;; print variables
|
;; print variables
|
||||||
(cond
|
(cond
|
||||||
((and (memq status '(FAIL ERROR)) (assq-ref info 'var-names))
|
((and (memq status '(FAIL ERROR)) (assq-ref info 'var-names))
|
||||||
|
@ -863,6 +871,11 @@
|
||||||
|
|
||||||
;;> \section{Parameters}
|
;;> \section{Parameters}
|
||||||
|
|
||||||
|
;;> If specified, takes a single object as input (the expected or
|
||||||
|
;;> actual value of a test) and returns the string representation
|
||||||
|
;;> (default \scheme{write-to-string}).
|
||||||
|
(define current-test-value-formatter (make-parameter #f))
|
||||||
|
|
||||||
;;> The current test group as started by \scheme{test-group} or
|
;;> The current test group as started by \scheme{test-group} or
|
||||||
;;> \scheme{test-begin}.
|
;;> \scheme{test-begin}.
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
test-get-name! test-group-name test-group-ref
|
test-get-name! test-group-name test-group-ref
|
||||||
test-group-set! test-group-inc! test-group-push!
|
test-group-set! test-group-inc! test-group-push!
|
||||||
;; parameters
|
;; parameters
|
||||||
current-test-verbosity
|
current-test-value-formatter current-test-verbosity
|
||||||
current-test-applier current-test-skipper current-test-reporter
|
current-test-applier current-test-skipper current-test-reporter
|
||||||
current-test-group-reporter test-failure-count
|
current-test-group-reporter test-failure-count
|
||||||
current-test-epsilon current-test-comparator
|
current-test-epsilon current-test-comparator
|
||||||
|
|
Loading…
Add table
Reference in a new issue