-
-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move rackunit/log to raco/testing
Previously, `rackunit/log` is used by both `raco test` and various testing framework to log testing results. However, this organization doesn't make much sense, as it gives privileges to rackunit over other testing frameworks (technically `rackunit/log` lives in the `testing-util-lib` package, so it's not a rackunit package proper, but it's still very close) This commit moves `rackunit/log` to `raco/testing`, which makes `raco test` "neutral". This also eliminates the dependency on `testing-util-lib`/`rackunit-lib`, for both `raco test` itself, and also other testing frameworks. Fixes #4965
- Loading branch information
Showing
5 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
;; This code originally appeared in rackunit/log | ||
|
||
#lang racket/base | ||
|
||
(provide test-log-enabled? | ||
test-log! | ||
test-report) | ||
|
||
(define test-log-enabled? | ||
(make-parameter #t (lambda (v) (and v #t)))) | ||
|
||
(define TOTAL 0) | ||
(define FAILED 0) | ||
|
||
(define-syntax-rule (inc! id) | ||
(set! id (add1 id))) | ||
|
||
(define (test-log! result) | ||
(when (test-log-enabled?) | ||
(inc! TOTAL) | ||
(unless result | ||
(inc! FAILED)))) | ||
|
||
(define (test-report #:display? [display? #f] | ||
#:exit? [exit? #f]) | ||
(when display? | ||
(unless (zero? TOTAL) | ||
(cond | ||
[(zero? FAILED) | ||
(printf "~a test~a passed\n" | ||
TOTAL | ||
(if (= TOTAL 1) "" "s"))] | ||
[else | ||
(eprintf "~a/~a test failures\n" | ||
FAILED TOTAL)]))) | ||
(when exit? | ||
(unless (zero? FAILED) | ||
(exit 1))) | ||
(cons FAILED TOTAL)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#lang racket/base | ||
(require rackunit | ||
raco/testing) | ||
|
||
(module test racket/base | ||
(require syntax/location) | ||
;; Use a separate namespace to avoid logging results | ||
;; in this namespace (where `raco test` would see errors). | ||
(parameterize ([current-namespace (make-base-namespace)]) | ||
(dynamic-require (quote-module-path "..") #f))) | ||
|
||
(define-syntax-rule (&& label stdout-e stdout-p) | ||
(let () | ||
(define stdout-ev stdout-e) | ||
(define stdout-av stdout-p) | ||
(unless (equal? stdout-ev stdout-av) | ||
(error 'log "bad ~a\n actual: ~v\n expected: ~v" | ||
label stdout-av stdout-ev)))) | ||
|
||
;; TODO(jackfirth): This testing system is pretty weird, and it's only necessary | ||
;; because the test log is a pair of global variables. That makes it hard to | ||
;; keep these tests from affecting the test log used by raco test. If the test | ||
;; log were a parameter, then these tests could simply create a new log and | ||
;; parameterize the current log to it. We should probably do that instead. | ||
(define-syntax-rule (& test-e stdout-e stderr-e exit-e) | ||
(let () | ||
(define stdout-p (open-output-string)) | ||
(define stderr-p (open-output-string)) | ||
(define exit-av 0) | ||
(parameterize ([current-output-port stdout-p] | ||
[current-error-port stderr-p] | ||
[exit-handler (λ (ec) (set! exit-av ec))]) | ||
test-e) | ||
(&& 'stdout stdout-e (get-output-string stdout-p)) | ||
(&& 'stderr stderr-e (get-output-string stderr-p)) | ||
(&& 'exit-code exit-e exit-av))) | ||
|
||
(& (test-report) "" "" 0) | ||
(& (test-report #:display? #t) "" "" 0) | ||
(& (test-report #:exit? #t) "" "" 0) | ||
(& (test-report #:display? #t #:exit? #t) "" "" 0) | ||
|
||
(check-true #t) | ||
|
||
(& (test-report) "" "" 0) | ||
(& (test-report #:display? #t) "1 test passed\n" "" 0) | ||
(& (test-report #:exit? #t) "" "" 0) | ||
(& (test-report #:display? #t #:exit? #t) "1 test passed\n" "" 0) | ||
|
||
(parameterize ([current-error-port (open-output-string)]) | ||
(check-true #f)) | ||
|
||
(& (test-report) "" "" 0) | ||
(& (test-report #:display? #t) "" "1/2 test failures\n" 0) | ||
(& (test-report #:exit? #t) "" "" 1) | ||
(& (test-report #:display? #t #:exit? #t) "" "1/2 test failures\n" 1) | ||
|
||
(parameterize ([test-log-enabled? #f]) | ||
(check-true #t) | ||
(& (test-report) "" "" 0) | ||
(& (test-report #:display? #t) "" "1/2 test failures\n" 0) | ||
(& (test-report #:exit? #t) "" "" 1) | ||
(& (test-report #:display? #t #:exit? #t) "" "1/2 test failures\n" 1)) | ||
|
||
(test-begin | ||
(check-true #t)) | ||
|
||
(& (test-report #:display? #t) "" "1/3 test failures\n" 0) | ||
|
||
(parameterize ([current-error-port (open-output-string)]) | ||
(test-begin | ||
(check-true #f))) | ||
|
||
(& (test-report #:display? #t) "" "2/4 test failures\n" 0) |