Merge pull request #21 from rfindler/master

make the top-level checks look more like how they look when using text-ui
This commit is contained in:
Jay McCarthy 2016-12-23 11:47:10 -05:00 committed by GitHub
commit 0584d9ecf3
3 changed files with 62 additions and 59 deletions

View File

@ -1,7 +1,9 @@
#lang racket/base #lang racket/base
(require racket/match (require racket/match
"base.rkt" "base.rkt"
"check-info.rkt") "check-info.rkt"
"text-ui-util.rkt"
"location.rkt")
(provide display-check-info-name-value (provide display-check-info-name-value
display-check-info display-check-info
@ -15,7 +17,10 @@
display-test-failure/error display-test-failure/error
strip-redundant-params strip-redundant-params
check-info-stack-max-name-width) check-info-stack-max-name-width
display-verbose-check-info
sort-stack)
;; name-width : integer ;; name-width : integer
;; ;;
@ -56,6 +61,33 @@
[(struct check-info (name value)) [(struct check-info (name value))
(display-check-info-name-value max-name-width name value)])) (display-check-info-name-value max-name-width name value)]))
;; display-verbose-check-info : test-result -> void
(define (display-verbose-check-info result)
(cond
((test-failure? result)
(let* ((exn (test-failure-result result))
(stack (exn:test:check-stack exn)))
(display-verbose-check-info-stack check-info-stack)))
((test-error? result)
(display-exn (test-error-result result)))
(else
(void))))
(define (display-verbose-check-info-stack check-info-stack)
(define max-name-width (check-info-stack-max-name-width check-info-stack))
(for ([info (in-list (sort-stack check-info-stack))])
(cond
((check-location? info)
(display-check-info-name-value max-name-width
'location
(trim-current-directory
(location->string
(check-info-value info)))
(λ (x) (printf "~a\n" x))))
(else
(display-check-info-name-value max-name-width
(check-info-name info)
(check-info-value info))))))
(define (check-info-stack-max-name-width check-info-stack) (define (check-info-stack-max-name-width check-info-stack)
(apply max 0 (apply max 0
@ -63,11 +95,9 @@
;; display-check-info-stack : (listof check-info) -> void ;; display-check-info-stack : (listof check-info) -> void
(define (display-check-info-stack check-info-stack) (define (display-check-info-stack check-info-stack)
(define max-name-width (check-info-stack-max-name-width check-info-stack)) (display-verbose-check-info-stack
(define (display-check-info-with-width check-info) (filter (λ (x) (not (check-expression? x)))
(display-check-info max-name-width check-info)) (strip-redundant-params check-info-stack)))
(for-each display-check-info-with-width
(strip-redundant-params check-info-stack))
(newline)) (newline))
;; display-test-name : (U string #f) -> void ;; display-test-name : (U string #f) -> void
@ -131,3 +161,21 @@
(display-error) (newline) (display-error) (newline)
(display-exn e)]) (display-exn e)])
(display-delimiter))) (display-delimiter)))
(define (sort-stack l)
(sort l <
#:key
(λ (info)
(cond
[(check-name? info)
0]
[(check-location? info)
1]
[(check-params? info)
2]
[(check-actual? info)
3]
[(check-expected? info)
4]
[else
5]))))

View File

@ -111,24 +111,6 @@
(display-exn exn))] (display-exn exn))]
[else (void)])) [else (void)]))
(define (sort-stack l)
(sort l <
#:key
(λ (info)
(cond
[(check-name? info)
0]
[(check-location? info)
1]
[(check-params? info)
2]
[(check-actual? info)
3]
[(check-expected? info)
4]
[else
5]))))
(define (textui-display-check-info-stack stack [verbose? #f]) (define (textui-display-check-info-stack stack [verbose? #f])
(define max-name-width (check-info-stack-max-name-width stack)) (define max-name-width (check-info-stack-max-name-width stack))
(for-each (for-each
@ -172,31 +154,6 @@
stack stack
(strip-redundant-params stack))))) (strip-redundant-params stack)))))
;; display-verbose-check-info : test-result -> void
(define (display-verbose-check-info result)
(cond
((test-failure? result)
(let* ((exn (test-failure-result result))
(stack (exn:test:check-stack exn)))
(for-each
(lambda (info)
(cond
((check-location? info)
(display "location: ")
(display (trim-current-directory
(location->string
(check-info-value info)))))
(else
(display (check-info-name info))
(display ": ")
(write (check-info-value info))))
(newline))
(sort-stack stack))))
((test-error? result)
(display-exn (test-error-result result)))
(else
(void))))
(define (std-test/text-ui display-context test) (define (std-test/text-ui display-context test)
(fold-test-results (fold-test-results
(lambda (result seed) (lambda (result seed)

View File

@ -47,9 +47,9 @@ Outta here!
-------------------- --------------------
FAILURE FAILURE
name: check name: check
location: (#<path:PLTHOME/collects/tests/rackunit/standalone-check-test.rkt> 48 0 1450 17) location: standalone-check-test.rkt:48:0
expression: (check = 1 2) params: (#<procedure:=> 1 2)
params: (#<procedure:=> 1 2)\nmessage: 0.0 message: 0.0
Check failure Check failure
-------------------- --------------------
@ -71,22 +71,20 @@ Second Outta here!
-------------------- --------------------
-------------------- --------------------
FAILURE FAILURE
name: check-eq?
location: standalone-test-case-test.rkt:23:12
actual: 1 actual: 1
expected: 2 expected: 2
name: check-eq?
location: (#<path:PLTHOME/collects/tests/rackunit/standalone-test-case-test.rkt> 23 12 626 15)
expression: (check-eq? 1 2)
Check failure Check failure
-------------------- --------------------
-------------------- --------------------
failure failure
FAILURE FAILURE
name: check-eq?
location: standalone-test-case-test.rkt:24:21
actual: 1 actual: 1
expected: 2 expected: 2
name: check-eq?
location: (#<path:PLTHOME/collects/tests/rackunit/standalone-test-case-test.rkt> 24 21 664 15)
expression: (check-eq? 1 2)
Check failure Check failure
-------------------- --------------------