Skip to content

Commit

Permalink
Add command output test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfirth committed Sep 3, 2016
1 parent fdcfc83 commit 187c5cc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ install:
- raco pkg install --auto
$TRAVIS_BUILD_DIR/syntax-warn
$TRAVIS_BUILD_DIR/syntax-warn-lang
$TRAVIS_BUILD_DIR/syntax-warn-test
script:
- raco test -c warn racket/base
- if [ -n "$RUN_COVER" ]; then raco cover -f coveralls -d $TRAVIS_BUILD_DIR/coverage -c warn racket/base; fi
Expand Down
5 changes: 5 additions & 0 deletions syntax-warn-test/info.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#lang info
(define name "syntax-warn-test")
(define collection "warn")
(define deps
'("syntax-warn"))
6 changes: 6 additions & 0 deletions syntax-warn-test/test-no-warnings/main.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#lang racket/base/warn

(require (for-syntax syntax/parse
syntax/parse/define)
rackunit
racket/format)
6 changes: 6 additions & 0 deletions syntax-warn-test/test-warnings/main.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#lang racket/base/warn

(require rackunit
(for-syntax syntax/parse
syntax/parse/define)
racket/format)
47 changes: 42 additions & 5 deletions syntax-warn-test/test.rkt
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
#lang racket/base/warn
#lang racket/base

(require rackunit
(for-syntax syntax/parse
syntax/parse/define)
racket/format)
(require racket/system)

(module+ test
(require rackunit
warn/private/rackunit-string))


(struct system-result (code stdout stderr) #:transparent)

(define (system/result system-str)
(define stdout-str-port (open-output-string))
(define stderr-str-port (open-output-string))
(define exit-code
(parameterize ([current-output-port stdout-str-port]
[current-error-port stderr-str-port])
(system/exit-code system-str)))
(define stdout (get-output-string stdout-str-port))
(define stderr (get-output-string stderr-str-port))
(system-result exit-code stdout stderr))

(define (run-warn-command collect)
(system/result (format "raco warn -c ~a" collect)))

(module+ test
(test-case "Checking a module with no warnings"
(define result (run-warn-command "warn/test-no-warnings"))
(check-equal? (system-result-code result) 0)
(check-string-contains? (system-result-stdout result)
"Checking 1 module\n")
(check-equal? (system-result-stderr result) ""))
(test-case "Checking a module with warnings"
(define result (run-warn-command "warn/test-warnings"))
(check-equal? (system-result-code result) 1)
(check-equal? (system-result-stderr result) "")
(check-string-contains-all? (system-result-stdout result)
(list "Checking 1 module\n"
"syntax-warn-test/test-warnings/main.rkt"
"phase order"
"suggested fix"
"require"
"for-syntax"))))
9 changes: 7 additions & 2 deletions syntax-warn/raco-warn.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@
[(package) (append-map package-warn-modules module-args)]))

(define (warn-modules resolved-module-paths)
(define any-warned? (box #f))
(for ([modpath resolved-module-paths])
(for-each print-warning (read-modpath-warnings modpath))))
(for ([warning (read-modpath-warnings modpath)])
(set-box! any-warned? #t)
(print-warning warning)))
(unbox any-warned?))

(define (read-modpath-warnings modpath)
(define (read-modpath-expansion)
Expand All @@ -152,4 +156,5 @@
[(== 1) (printf "Checking 1 module\n")]
[num-modules (printf "Checking ~a modules\n" num-modules)])
(flush-output)
(warn-modules modules))
(when (warn-modules modules)
(exit 1)))

0 comments on commit 187c5cc

Please sign in to comment.