Compare commits

...

10 Commits
v6.5 ... master

Author SHA1 Message Date
Georges Dupéron
25163f81ef Use define-runtime-path for the rackunit screenshot. 2017-05-22 04:18:13 +02:00
Georges Dupéron
71c164e9f0 Added screenshot of the RackUnit GUI, fixed typo. 2017-05-18 23:29:16 +02:00
Robby Findler
19a87ffe13 adjust 86a91d675d to bring back the "expression:" field of
a failed test

or, in other words, make a top-level check-equal? more like a
check-equal? inside a test-suite that runs in verbose mode

(except that a top-level one limits the output to error-print-width
 characters, but the one inside a test-suite doesn't seem to do that)
2017-01-05 07:33:00 -06:00
Jay McCarthy
0584d9ecf3 Merge pull request #21 from rfindler/master
make the top-level checks look more like how they look when using text-ui
2016-12-23 11:47:10 -05:00
Robby Findler
86a91d675d make the top-level checks look more like how they look
when using text-ui

Or, in other words, try to make these two print similarly:

  #lang racket
  (require rackunit rackunit/text-ui)
  (check-equal? 1 2)
  (run-tests (test-suite "name" (check-equal? 1 2)))
2016-12-23 08:38:51 -06:00
Celeste Hollenbeck
902e41b08a fix typo in test-suite example 2016-10-14 15:32:59 -04:00
Don March
a83d76a6ef Update doc for check-exn: predicate can be trueish 2016-10-14 14:53:04 -04:00
Spencer Florence
2407b02f38 don't catch exn breaks
Please Include In Release
2016-10-10 11:27:21 -05:00
Ryan Culpepper
7f484888f5 fix check-exn contract error message 2016-07-29 11:45:52 -04:00
Spencer Florence
21b278c864 moved rackunit/log to new pkg, fixed docs 2016-04-29 12:45:59 -05:00
14 changed files with 116 additions and 67 deletions

View File

@ -109,7 +109,7 @@ For example, the following checks all fail:
void?]{
Checks that @racket[thunk] raises an exception and that either
@racket[exn-predicate] returns @racket[#t] if it is a function, or
@racket[exn-predicate] returns a true value if it is a function, or
that it matches the message in the exception if @racket[exn-predicate]
is a regexp. In the latter case, the exception raised must be an
@racket[exn:fail?]. The optional @racket[message] is included in the

View File

@ -122,7 +122,7 @@ finished.
(check-eq? 1 1))
(test-suite "A nested test suite"
(test-case "Another test"
(check-< 1 2))))
(check < 1 2))))
]
@defproc[(make-test-suite [name string?]

View File

@ -7,7 +7,7 @@ The @racket[before], @racket[after], and @racket[around]
macros allow you to specify code that is always run before,
after, or around expressions in a test case.
@defform[(before before-expr expr1 expr2 ...)]{
@defform[(before before-expr expr-1 expr-2 ...)]{
Whenever control enters the scope execute the @racket[before-expr]
before executing @racket[expr-1], and @racket[expr-2 ...]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -38,6 +38,8 @@ information.
RackUnit also provides a GUI test runner, available from the
@racketmodname[rackunit/gui] module.
@define-runtime-path[scribblings/rackunit-screen-shot.png
"scribblings/rackunit-screen-shot.png"]
@defproc[(test/gui [test (or/c test-case? test-suite?)] ...
[#:wait? wait? boolean? #f])
void?]{
@ -47,6 +49,29 @@ GUI is updated as tests complete.
When @racket[wait?] is true, @racket[test/gui] does not return until
the test runner window has been closed.
Given the following program, the RackUnit GUI will look as shown below:
@racketblock[
#,(hash-lang) racket
(require rackunit rackunit/gui)
(test/gui
(test-suite
"all tests"
(test-suite
"math tests"
(test-case "addition" (check-equal? (+ 1 1) 2))
(test-case "subtraction" (check-equal? (- 0 0) 0))
(test-case "multiplication" (check-equal? (* 2 2) 5)))
(test-suite
"string tests"
(test-case "append" (check-equal? (string-append "a" "b") "ab"))
(test-case "ref" (check-equal? (string-ref "abc" 1) #\b)))))]
@image[scribblings/rackunit-screen-shot.png]{Screenshot of the RackUnit
window. It features a tree representing the nested test suites (with test
cases as leaves) on the left pane, and information about the selected test
failure in the right pane.}
}
@defproc[(make-gui-runner)

View File

@ -48,11 +48,12 @@ then the test is considered a failure.
@defproc[(test-log [#:display? display? boolean? #t]
[#:exit? exit? boolean? #t])
void?]{
(cons/c exact-nonnegative-integer?
exact-nonnegative-integer?)]{
Processes the running test log. If @racket[display?] is true, then a
message is displayed. If there were failures, the message is printed
on @racket[(current-error-port)]. If @racket[exit?] is true, then if
there were failures, calls @racket[(exit 1)].
Processes the running test log. The first integer is the failed tests, the second is the total
tests. If @racket[display?] is true, then a message is displayed. If there were failures, the
message is printed on @racket[(current-error-port)]. If @racket[exit?] is true, then if there were
failures, calls @racket[(exit 1)].
}

View File

@ -3,7 +3,10 @@
(define collection 'multi)
(define deps '("base"
"data-lib"))
"data-lib"
"testing-util-lib"))
(define implies '("testing-util-lib"))
(define pkg-desc "RackUnit testing framework")

View File

@ -215,7 +215,7 @@
[(and (procedure? raw-pred) (procedure-arity-includes? raw-pred 1))
raw-pred]
[else
(raise-argument-error 'check-exn "(-> any/c any/c)" raw-pred)])])
(raise-argument-error 'check-exn "(or/c (-> any/c any/c) regexp?)" raw-pred)])])
(raise-error-if-not-thunk 'check-exn thunk)
(let/ec succeed
(with-handlers

View File

@ -1,7 +1,9 @@
#lang racket/base
(require racket/match
"base.rkt"
"check-info.rkt")
"check-info.rkt"
"text-ui-util.rkt"
"location.rkt")
(provide display-check-info-name-value
display-check-info
@ -15,7 +17,10 @@
display-test-failure/error
strip-redundant-params
check-info-stack-max-name-width)
check-info-stack-max-name-width
display-verbose-check-info
sort-stack)
;; name-width : integer
;;
@ -56,6 +61,38 @@
[(struct check-info (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))))
((check-expression? info)
(display-check-info-name-value max-name-width
(check-info-name info)
(check-info-value info)
(λ (x) (printf "~.s\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)
(apply max 0
@ -63,11 +100,8 @@
;; display-check-info-stack : (listof check-info) -> void
(define (display-check-info-stack check-info-stack)
(define max-name-width (check-info-stack-max-name-width check-info-stack))
(define (display-check-info-with-width check-info)
(display-check-info max-name-width check-info))
(for-each display-check-info-with-width
(strip-redundant-params check-info-stack))
(display-verbose-check-info-stack
(strip-redundant-params check-info-stack))
(newline))
;; display-test-name : (U string #f) -> void
@ -131,3 +165,21 @@
(display-error) (newline)
(display-exn e)])
(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

@ -28,7 +28,7 @@
;;
;; Run a test-case immediately, printing information on failure
(define (default-test-case-around thunk)
(with-handlers ([(lambda (e) #t) default-test-case-handler])
(with-handlers ([(lambda (e) (not (exn:break? e))) default-test-case-handler])
(parameterize ((current-custodian (make-custodian)))
(thunk))))

View File

@ -111,24 +111,6 @@
(display-exn exn))]
[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 max-name-width (check-info-stack-max-name-width stack))
(for-each
@ -172,31 +154,6 @@
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)
(fold-test-results
(lambda (result seed)

View File

@ -47,9 +47,10 @@ Outta here!
--------------------
FAILURE
name: check
location: (#<path:PLTHOME/collects/tests/rackunit/standalone-check-test.rkt> 48 0 1450 17)
location: standalone-check-test.rkt:48:0
params: (#<procedure:=> 1 2)
expression: (check = 1 2)
params: (#<procedure:=> 1 2)\nmessage: 0.0
message: 0.0
Check failure
--------------------
@ -71,10 +72,10 @@ Second Outta here!
--------------------
--------------------
FAILURE
name: check-eq?
location: standalone-test-case-test.rkt:23:12
actual: 1
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
@ -82,10 +83,10 @@ Check failure
--------------------
failure
FAILURE
name: check-eq?
location: standalone-test-case-test.rkt:24:21
actual: 1
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

10
testing-util-lib/info.rkt Normal file
View File

@ -0,0 +1,10 @@
#lang info
(define collection 'multi)
(define deps '("base"))
(define pkg-desc "Utilities for interoperating between testing frameworks")
(define version "1.0")
(define pkg-authors '(florence))