add the ability to control which submodules are ignored

This commit is contained in:
Spencer Florence 2015-02-14 19:37:38 -05:00
parent 2fe1a73ece
commit 2d2a6d094b
6 changed files with 33 additions and 17 deletions

View File

@ -14,6 +14,7 @@
any)] any)]
[clear-coverage! (-> any)] [clear-coverage! (-> any)]
[get-test-coverage (-> coverage/c)] [get-test-coverage (-> coverage/c)]
[irrelevant-submodules (parameter/c (or/c #f (listof symbol?)))]
[make-covered? [make-covered?
(-> file-coverage/c path-string? (-> file-coverage/c path-string?
(->* (exact-positive-integer?) (->* (exact-positive-integer?)

View File

@ -1,5 +1,5 @@
#lang racket/base #lang racket/base
(provide make-covered?) (provide make-covered? irrelevant-submodules)
(require racket/file (require racket/file
racket/function racket/function
racket/list racket/list
@ -26,7 +26,8 @@
;; A Covered? is a [Nat [#:byte? Boolean] -> Cover] ;; A Covered? is a [Nat [#:byte? Boolean] -> Cover]
;; FileCoverage PathString #:ignored-submods (maybe (listof symbol)) -> Covered? ;; FileCoverage PathString #:ignored-submods (maybe (listof symbol)) -> Covered?
(define (make-covered? c path #:ignored-submods [submods #f]) (define (make-covered? c path)
(define submods (irrelevant-submodules))
(define vec (define vec
(list->vector (string->list (file->string path)))) (list->vector (string->list (file->string path))))
(define file/byte->str-offset (make-byte->str-offset vec)) (define file/byte->str-offset (make-byte->str-offset vec))
@ -36,8 +37,10 @@
(hash-ref file-location-coverage-cache (if (not byte?) loc (- loc (file/byte->str-offset loc))) (hash-ref file-location-coverage-cache (if (not byte?) loc (- loc (file/byte->str-offset loc)))
'missing))) 'missing)))
;; (or/c #f (listof symbol))
(define irrelevant-submodules (make-parameter #f))
;; Path FileCoverage OffsetFunc -> [Hashof Natural Cover] ;; Path FileCoverage -> [Hashof Natural Cover]
;; build a hash caching coverage info for that file ;; build a hash caching coverage info for that file
(define (coverage-cache-file f c submods) (define (coverage-cache-file f c submods)
(vprintf "caching coverage info for ~s\n" f) (vprintf "caching coverage info for ~s\n" f)

View File

@ -46,18 +46,23 @@ coverage information for that file @racket[make-covered?] returns
a functions that determines if some @racket[1] indexed character or byte location a functions that determines if some @racket[1] indexed character or byte location
in that file is covered. By default it checks character locations. in that file is covered. By default it checks character locations.
There are three possible results: There are three possible results: @itemize[@item{@racket['irrelevant] --- The location is not
@itemize[@item{@racket['irrelevant] --- The location is not considered relevant to coverage information. considered relevant to coverage information. It is either not in the coverage information; is in a
It is either not in the coverage information; is in a submodule; is a @racket[begin-for-syntax] form; submodule specified by @racket[irrelevant-submodules]; is a @racket[begin-for-syntax] form; or lexes
or lexes (in the sense of that languages, @racket[_color-lexer]) as a comment or whitespace.} (in the sense of that languages, @racket[_color-lexer]) as a comment or whitespace.}
@item{@racket['covered] --- The location is not @racket['irrelevant] and is @item{@racket['covered] --- The location is not @racket['irrelevant] and is covered}
covered} @item{@racket['uncovered] --- The location is not @racket['uncovered] and is not covered}] }
@item{@racket['uncovered] --- The location is not @racket['uncovered]
and is not covered}] @defthing[irrelevant-submodules (parameter/c (or/c #f (listof symbol?)))]{
}
A parameter that controls with submodules are considered irrelevant by @racket[make-covered?]. It
defaults to @racket[#f], which tells @racket[make-covered?] to consider all submodules
irrelevant. If its value is a list, then each element of that list is the name of a submodule to be
considered irrelevant.}
@deftogether[(@defproc[(generate-coveralls-coverage (c coverage/c) (p path-string? "coverage")) any] @deftogether[(@defproc[(generate-coveralls-coverage (c coverage/c) (p path-string? "coverage")) any]
@defproc[(generate-html-coverage (c coverage/c) (p path-string? "coverage")) any])]{ @defproc[(generate-html-coverage (c coverage/c) (p path-string? "coverage")) any])]{
Generates coverage information in the coveralls and html
formats. Equivalent to the specifications of the @Flag{c} argument to Generates coverage information in the coveralls and html formats. Equivalent to the specifications
@exec{raco cover}.} of the @Flag{c} argument to @exec{raco cover}. Both use @racket[make-covered?] to determine file
coverage.}

View File

@ -3,7 +3,7 @@
;; for every .rkt file in those directories it loads ;; for every .rkt file in those directories it loads
;; tests that file and checks its coverage against an ;; tests that file and checks its coverage against an
;; .rktl file of the same name ;; .rktl file of the same name
(require (only-in "../main.rkt" test-files! clear-coverage! get-test-coverage) (require (only-in "../main.rkt" test-files! clear-coverage! get-test-coverage irrelevant-submodules)
"../private/file-utils.rkt" "../private/file-utils.rkt"
racket/runtime-path rackunit) racket/runtime-path rackunit)
@ -65,7 +65,10 @@
(module+ test (module+ test
(define-runtime-path-list test-dirs '("basic" "simple-multi" "syntax")) (define-runtime-path-list test-dirs '("basic" "simple-multi" "syntax"))
(for-each (compose test-dir path->string) test-dirs)) (for-each (compose test-dir path->string) test-dirs)
(define-runtime-path submods "submods")
(parameterize ([irrelevant-submodules null])
(test-dir (path->string submods))))
(module+ test (module+ test
(define-runtime-path prog.rkt "prog.rkt") (define-runtime-path prog.rkt "prog.rkt")

2
tests/submods/prog.rkt Normal file
View File

@ -0,0 +1,2 @@
#lang racket
(module+ test (+ 1 2))

2
tests/submods/prog.rktl Normal file
View File

@ -0,0 +1,2 @@
((1 35))
()