diff --git a/main.rkt b/main.rkt index 2b6593a..8edeb8f 100644 --- a/main.rkt +++ b/main.rkt @@ -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?) diff --git a/private/format-utils.rkt b/private/format-utils.rkt index fcc16e8..ad9fec4 100644 --- a/private/format-utils.rkt +++ b/private/format-utils.rkt @@ -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) diff --git a/scribblings/api.scrbl b/scribblings/api.scrbl index 8fe5776..0711b0c 100644 --- a/scribblings/api.scrbl +++ b/scribblings/api.scrbl @@ -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.} diff --git a/tests/main.rkt b/tests/main.rkt index dd0fcc4..1466805 100644 --- a/tests/main.rkt +++ b/tests/main.rkt @@ -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") diff --git a/tests/submods/prog.rkt b/tests/submods/prog.rkt new file mode 100644 index 0000000..dab3972 --- /dev/null +++ b/tests/submods/prog.rkt @@ -0,0 +1,2 @@ +#lang racket +(module+ test (+ 1 2)) diff --git a/tests/submods/prog.rktl b/tests/submods/prog.rktl new file mode 100644 index 0000000..01ea0dc --- /dev/null +++ b/tests/submods/prog.rktl @@ -0,0 +1,2 @@ +((1 35)) +()