added submodule control (Issue 16)

This commit is contained in:
Spencer Florence 2015-01-08 12:57:53 -05:00
parent 3a7e3d3973
commit 17719434b6
5 changed files with 15 additions and 8 deletions

View File

@ -19,7 +19,7 @@
;; PathString * -> Boolean ;; PathString * -> Boolean
;; Test files and build coverage map ;; Test files and build coverage map
;; returns true if all tests passed ;; returns true if all tests passed
(define (test-files! . paths) (define (test-files! #:submod [submod-name 'test] . paths)
(for ([path paths]) (for ([path paths])
(define p (define p
(if (absolute-path? path) (if (absolute-path? path)
@ -52,7 +52,7 @@
(apply old-check x))]) (apply old-check x))])
(eval `(dynamic-require '(file ,p) #f)) (eval `(dynamic-require '(file ,p) #f))
(namespace-require `(file ,p)) (namespace-require `(file ,p))
(define submod `(submod (file ,p) test)) (define submod `(submod (file ,p) ,submod-name))
(when (module-declared? submod) (when (module-declared? submod)
(namespace-require submod))))) (namespace-require submod)))))
(not tests-failed))) (not tests-failed)))

View File

@ -5,7 +5,7 @@
(contract-out (contract-out
[coverage/c contract?] [coverage/c contract?]
[file-coverage/c contract?] [file-coverage/c contract?]
[test-files! (->* () () #:rest (listof path-string?) any/c)] [test-files! (->* () (#:submod symbol?) #:rest (listof path-string?) any/c)]
[clear-coverage! (-> any)] [clear-coverage! (-> any)]
[get-test-coverage (-> coverage/c)] [get-test-coverage (-> coverage/c)]
[make-covered? [make-covered?

View File

@ -12,6 +12,7 @@
(define output-format "html") (define output-format "html")
(define exclude-paths '()) (define exclude-paths '())
(define include-exts '()) (define include-exts '())
(define submod 'test)
(define args (define args
(command-line (command-line
@ -36,6 +37,9 @@
[("-i" "--include-extentions") f [("-i" "--include-extentions") f
"include these extentions in files to cover." "include these extentions in files to cover."
(set! include-exts (cons f include-exts))] (set! include-exts (cons f include-exts))]
[("-s" "--submodule") s
"Run the given submodule instead of the test submodule"
(set! submod (string->symbol s))]
#:args (file . files) #:args (file . files)
(cons file files))) (cons file files)))
(define files (expand-directories args include-exts)) (define files (expand-directories args include-exts))
@ -46,7 +50,7 @@
[("raw") generate-raw-coverage] [("raw") generate-raw-coverage]
[else (error 'cover "given unknown coverage output format: ~s" output-format)])) [else (error 'cover "given unknown coverage output format: ~s" output-format)]))
(printf "generating test coverage for ~s\n" files) (printf "generating test coverage for ~s\n" files)
(define passed (apply test-files! files)) (define passed (keyword-apply test-files! '(#:submod) (list submod) files))
(define coverage (remove-excluded-paths (get-test-coverage) exclude-paths)) (define coverage (remove-excluded-paths (get-test-coverage) exclude-paths))
(printf "dumping coverage info into ~s\n" coverage-dir) (printf "dumping coverage info into ~s\n" coverage-dir)
(generate-coverage coverage coverage-dir) (generate-coverage coverage coverage-dir)

View File

@ -9,11 +9,12 @@ In addition to a raco tool Cover provides racket bindings for running
tests and collecting coverage information. The following are the basic tests and collecting coverage information. The following are the basic
functions of test coverage. functions of test coverage.
@defproc[(test-files! (files path-string?) ...) any/c]{ @defproc[(test-files! (#:submod submod symbol? 'test) (files path-string?) ...) any/c]{
Tests all given @racket[files] and stores the coverage information. Returns Runs all given @racket[files] and there submodule @racket[submod] (if it exitsts),
false if tests failed. Test coverage information is still collected when test storing the coverage information. Returns false if tests failed. Test coverage
fail. Test coverage info is added to existing coverage info.} information is still collected when test fail. Test coverage info is added to
existing coverage info.}
@defproc[(clear-coverage!) any]{Clears all coverage information.} @defproc[(clear-coverage!) any]{Clears all coverage information.}

View File

@ -37,4 +37,6 @@ The @exec{raco cover} command accepts the following flags:
used when expanding directories, searching for files to cover.} used when expanding directories, searching for files to cover.}
@item{@Flag{v} or @DFlag{verbose} @item{@Flag{v} or @DFlag{verbose}
--- enable verbose logging} --- enable verbose logging}
@item{@Flag{s} or @DFlag{submod}
--- run the given submodule instead of the test submodule.}
] ]