This commit is contained in:
Spencer Florence 2015-02-22 15:31:46 -05:00
parent ef06b50a2c
commit b514675182
4 changed files with 48 additions and 31 deletions

View File

@ -1,6 +1,6 @@
#lang racket/base
(provide test-files!
make-clean-cover-environment clear-coverage!
make-cover-environment clear-coverage!
get-test-coverage
current-cover-environment environment?
environment-compile environment-namespace)
@ -169,9 +169,9 @@ in "coverage.rkt". This raw coverage information is converted to a usable form b
;;; ---------------------- Environments ---------------------------------
(define (clear-coverage!)
(current-cover-environment (make-clean-cover-environment)))
(current-cover-environment (make-cover-environment)))
(define (make-clean-cover-environment [ns (make-base-namespace)])
(define (make-cover-environment [ns (make-base-namespace)])
(parameterize ([current-namespace ns])
(define ann (load-annotate-top))
(environment
@ -235,7 +235,7 @@ in "coverage.rkt". This raw coverage information is converted to a usable form b
out))
(define current-cover-environment
(make-parameter (make-clean-cover-environment)))
(make-parameter (make-cover-environment)))
;; here live tests for actually saving compiled files
(module+ test
@ -246,7 +246,7 @@ in "coverage.rkt". This raw coverage information is converted to a usable form b
"tests/compiled/prog_rkt.zo"
"tests/compiled/prog_rkt.dep"))
(test-begin
(parameterize ([current-cover-environment (make-clean-cover-environment)])
(parameterize ([current-cover-environment (make-cover-environment)])
(for-each (lambda (f) (when (file-exists? f) (delete-file f)))
compiled)
(check-false (ormap file-exists? compiled))
@ -266,7 +266,7 @@ in "coverage.rkt". This raw coverage information is converted to a usable form b
;; break cyclic dependency in testing
(lazy-require ["private/format-utils.rkt" (make-covered?)])
(define-runtime-path simple-multi/2.rkt "tests/simple-multi/2.rkt")
(define env (make-clean-cover-environment))
(define env (make-cover-environment))
(define ns (environment-namespace env))
(parameterize ([current-cover-environment env]
[current-namespace ns])

View File

@ -26,7 +26,7 @@
(-> environment? (any/c boolean? . -> . compiled-expression?))]
[clear-coverage! (-> any)]
[make-clean-cover-environment (->* () ((-> namespace?)) environment?)]
[make-cover-environment (->* () ((-> namespace?)) environment?)]
[current-cover-environment (parameter/c environment?)]
[get-test-coverage (->* () (environment?) coverage/c)]

View File

@ -88,7 +88,7 @@
(define file (path->string (simplify-path tests/prog.rkt)))
(test-files! (path->string (simplify-path tests/prog.rkt)))
(define coverage (get-test-coverage))
(define report
(define report
(with-env ("COVERALLS_REPO_TOKEN" "abc") (generate-coveralls-report coverage)))
(check-equal?
(hash-ref report 'source_files)

View File

@ -11,38 +11,38 @@ functions of test coverage.
@deftogether[(@defthing[coverage/c
contract?
#:value (hash/c (and/c path-string? absolute-path?)
file-coverage/c)]
#:value (hash/c any/c file-coverage/c)]
@defthing[file-coverage/c contract? #:value (listof (list/c boolean? srcloc?))])]{
Coverage information is a hash map mapping absolute
file paths to a list detailing the coverage of that file. The file coverage
information is a list of lists, mapping a boolean to a range of
characters within the file. True means the @racket[srcloc] structure
represents an expression that was run, and False means the structure
represents an expression that was not run. Some expressions may not be
represented directly in this coverage information.
For example, type annotations in @racketmodname[typed/racket]
removed during macro expansion and are thus neither run or not run.
Note that the @racket[srcloc]s are one indexed, meaning a @racket[1]
represents the first character in the file.}
Coverage information is a hash map mapping absolute file paths to a list detailing the coverage of
that file. The file is keyed on the @racket[syntax-source] of the syntax objects for that
file. Usually this will be the absolute path to the file. The file coverage information is a list of
lists, mapping a boolean to a range of characters within the file. True means the @racket[srcloc]
structure represents an expression that was run, and False means the structure represents an
expression that was not run. Some expressions may not be represented directly in this coverage
information. For example, type annotations in @racketmodname[typed/racket] removed during macro
expansion and are thus neither run or not run. Note that the @racket[srcloc]s are one indexed,
meaning a @racket[1] represents the first character in the file.}
@defproc[(test-files! (#:submod submod symbol? 'test)
(files (or/c path-string?
(list/c path-string
(and/c (negate impersonator?)
(vectorof string? #:immutable #t))))) ...)
(files (or/c (or/c path-string? input-port?)
(list/c (or/c path-string? input-port?)
(not-impersonated/c
(vectorof (not-impersonated/c string?) #:immutable #t))))) ...)
any]{
Runs all given @racket[files] and their submodule @racket[submod] (if it exists), storing the
coverage information. If the path is paired with a vector then that vector is used as the
@racket[current-command-line-arguments] when executing that file. This vector must be immuatable and
not wrapped by a @racket[chaperone] or @racket[impersonator]. The function returns false if any
tests fail. Test coverage information is still collected when test fail. Test coverage info is
added to existing coverage info.}
@racket[current-command-line-arguments] when executing that file. This vector must be immutable and
not wrapped by a @racket[chaperone] or @racket[impersonator], nor may its elements be wrapped in a
chaperone or impersonator. The function returns false if any tests fail. Test coverage 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! [environment environment? (current-coverage-environment)]) any]{
Clears all coverage information.}
@defproc[(get-test-coverage) coverage/c]{Gets the current coverage information.}
@defproc[(get-test-coverage [environment environment? (current-coverage-environment)]) coverage/c]{
Gets the current coverage information.}
@defproc[(make-covered? (coverage file-coverage/c) (path path-string?))
(->* (exact-positive-integer?)
(#:byte? boolean?)
@ -67,6 +67,23 @@ defaults to @racket[#f], which tells @racket[make-covered?] to consider all subm
irrelevant. If its value is a list, then each element of that list is the name of a submodule to be
considered irrelevant.}
@defproc[(environment? [v any/c]) any/c]{
Tests if the given value is a coverage environment.}
@defthing[current-coverage-environment (parameter/c environment?)]{
The current coverage environment}
@defproc[(environment-namespace [environment environment?]) namespace?]{
Get the namespace that coverage should be run in}
@defproc[(environment-compile [environment environment?])
(any/c boolean? . -> . compiled-expression?)]{
Returns a value suitable for @racket[current-compile] that will compile code with coverage
annotations. That code must be run in @racket[environment]'s namespace.}
@defproc[(make-cover-environment [namespace namespace? (make-base-namespace)]) environment?]{
Makes a coverage environment such that @racket[environment-namespace] will return
@racket[namespace], and @racket[namespace] will be set up to handle coverage information.}
@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])]{