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)]
[clear-coverage! (-> any)]
[get-test-coverage (-> coverage/c)]
[irrelevant-submodules (parameter/c (or/c #f (listof symbol?)))]
[make-covered?
(-> file-coverage/c path-string?
(->* (exact-positive-integer?)

View File

@ -1,5 +1,5 @@
#lang racket/base
(provide make-covered?)
(provide make-covered? irrelevant-submodules)
(require racket/file
racket/function
racket/list
@ -26,7 +26,8 @@
;; A Covered? is a [Nat [#:byte? Boolean] -> Cover]
;; 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
(list->vector (string->list (file->string path))))
(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)))
'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
(define (coverage-cache-file f c submods)
(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
in that file is covered. By default it checks character locations.
There are three possible results:
@itemize[@item{@racket['irrelevant] --- The location is not considered relevant to coverage information.
It is either not in the coverage information; is in a submodule; is a @racket[begin-for-syntax] form;
or lexes (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
covered}
@item{@racket['uncovered] --- The location is not @racket['uncovered]
and is not covered}]
}
There are three possible results: @itemize[@item{@racket['irrelevant] --- The location is not
considered relevant to coverage information. It is either not in the coverage information; is in a
submodule specified by @racket[irrelevant-submodules]; is a @racket[begin-for-syntax] form; or lexes
(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 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]
@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
@exec{raco cover}.}
Generates coverage information in the coveralls and html formats. Equivalent to the specifications
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
;; tests that file and checks its coverage against an
;; .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"
racket/runtime-path rackunit)
@ -65,7 +65,10 @@
(module+ test
(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
(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))
()