From 64cd769fbeb73ba51cfbe47bef51068266d5f4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Sat, 16 Jan 2016 14:47:44 +0100 Subject: [PATCH 01/15] Allow multiple output formats, by specifying `f` several times on the command-line, e.g. `raco cover -f html -f coveralls file.rkt`. --- cover/cover.rkt | 6 +++--- cover/raco.rkt | 21 +++++++++++++-------- cover/scribblings/basics.scrbl | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cover/cover.rkt b/cover/cover.rkt index b768d94..2d6d9da 100644 --- a/cover/cover.rkt +++ b/cover/cover.rkt @@ -96,9 +96,9 @@ Thus, In essence this module has three responsibilites: (compile-file f)) (for*/fold ([tests-failed #f]) ([f (in-list abs)] - [submod-name (in-list (if (symbol? submod-names) - (list submod-names) - submod-names))]) + [submod-name (in-list (if (list? submod-names) + submod-names + (list submod-names)))]) (printf "cover: running file: ~a\n" f) (define failed? (handle-file f submod-name)) (or failed? tests-failed))))) diff --git a/cover/raco.rkt b/cover/raco.rkt index 37984e5..da3b7a7 100644 --- a/cover/raco.rkt +++ b/cover/raco.rkt @@ -21,7 +21,7 @@ (module+ main (define coverage-dir "coverage") - (define output-format "html") + (define output-formats "html") (define exclude-paths '()) (define include-exts '()) (define submods 'test) @@ -36,9 +36,6 @@ [("-d" "--directory") d "Specify output directory. Defaults to ./coverage." (set! coverage-dir d)] - [("-f" "--format") format - "Specify that coverage should be run and optional what format. Defaults to html." - (set! output-format format)] [("-v" "--verbose") "Verbose mode" (set! verbose #t)] @@ -46,6 +43,9 @@ "exclude info.rkt, the tests directory, and the scribblings directory from the coverage report" (set! exclude-paths (list* "info.rkt" "tests" "scribblings" exclude-paths))] #:multi + [("-f" "--format") format + "Specify that coverage should be run and optionally what formats. Defaults to html." + (set! output-formats (cons format (if (list? output-formats) output-formats '())))] [("-n" "--no-output-for-path") t "exclude any paths named this from the coverage report." (set! exclude-paths (cons t exclude-paths))] @@ -54,7 +54,7 @@ (set! include-exts (cons f include-exts))] [("-s" "--submodule") s "Run the given submodule instead of the test submodule." - (set! submods (cons (string->symbol s) (if (symbol? submods) '() submods)))] + (set! submods (cons (string->symbol s) (if (list? submods) submods '())))] [("-e" "--irrelevant-submodules") s "Consider the given submodules irrelevant when generating coverage. If not provided defaults to all submodules." (unless irrel-submods @@ -91,9 +91,14 @@ (expand-directories (map pkg-directory a) b))])) (define files (path-expand args include-exts)) (define cleaned-files (remove-excluded-paths files exclude-paths)) - (define generate-coverage - (hash-ref (get-formats) output-format - (lambda _ (error 'cover "given unknown coverage output format: ~s" output-format)))) + (define (generate-coverage . args) + (for/list ([output-format (in-list (if (list? output-formats) + output-formats + (list output-formats)))]) + (apply (hash-ref (get-formats) output-format + (lambda _ + (error 'cover "given unknown coverage output format: ~s" output-format))) + args))) (define passed (apply test-files! #:submod submods #:dont-compile exclude-paths diff --git a/cover/scribblings/basics.scrbl b/cover/scribblings/basics.scrbl index 8d18acf..9742898 100644 --- a/cover/scribblings/basics.scrbl +++ b/cover/scribblings/basics.scrbl @@ -11,8 +11,8 @@ exists). It will then dump the coverage information into a directory, by default The @exec{raco cover} command accepts the following flags: @itemize[@item{@Flag{f} or @DFlag{format} - --- Sets the coverage output type. This flag defaults to html. - valid formats are: + --- Sets the coverage output type. Can be included more than once. + This flag defaults to html. Valid formats are: @itemize[@item{html: Generates one html file per tested file.}] Other packages may install new formats. See @secref{plugin}} @item{@Flag{b} or @DFlag{exclude-pkg-basics} -- 2.34.1 From 9cef685a0dff576158fe84488a6d1725155db97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Tue, 2 Feb 2016 23:07:39 +0100 Subject: [PATCH 02/15] Fixes links in HTML output. When the destination directory has more than one path component, e.g. raco cover -d foo/coverage file.rkt, the URLs were of the form coverage/coverage/file.html . Also, when the -d option was a relative path starting with ./, e.g. ./foo/coverage, the URL in the links was an absolute path, like /home/user/project/foo/coverage/file.html, which doesn't work if the generated HTML is put online. --- cover/private/html/html.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cover/private/html/html.rkt b/cover/private/html/html.rkt index a0b4175..43f2fba 100644 --- a/cover/private/html/html.rkt +++ b/cover/private/html/html.rkt @@ -73,7 +73,7 @@ [p (in-list file-list)]) (values k (path->string - (apply build-path (rest (explode-path (first p)))))))) + (find-relative-path dir (first p)))))) (define index (generate-index coverage files file/path-mapping)) (cons (list (build-path dir "index.html") dir index) file-list)) -- 2.34.1 From 3b5aa3acfa108af1fbccd0824c8de3dd78b42893 Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Wed, 3 Feb 2016 13:22:34 -0600 Subject: [PATCH 03/15] Remove confusing prose in README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index e6fef1f..d5dc63b 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ You can also create your own coverage formats. ## How to install -Install via `raco pkg install cover`. To install for development, checkout the repository, `cd` into -the new directory and run `raco pkg install`. +Install via `raco pkg install cover`, or from the `"File" -> "Install Package..."` menu in DrRacket. ## Basic Usage -- 2.34.1 From e997e6d15fc1a221efa1f62f913e9c5de254f195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Thu, 4 Feb 2016 00:47:16 +0100 Subject: [PATCH 04/15] Implements GH issue #114 Allow for linking to line numbers in HTML output --- cover/private/html/assets/main.css | 12 ++++++++++- cover/private/html/html.rkt | 32 +++++++++++++++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/cover/private/html/assets/main.css b/cover/private/html/assets/main.css index de25e68..86ac5cf 100644 --- a/cover/private/html/assets/main.css +++ b/cover/private/html/assets/main.css @@ -38,7 +38,7 @@ td a, td a:visited { color: #07A; } -tr.stripe { +tr.stripe, :target { background-color: #F5F5EC; } @@ -59,6 +59,16 @@ div.line-numbers { text-align: right; } +.line-numbers a { + color: black; + text-decoration: none; +} + +.line-numbers a:hover { + color: blue; + text-decoration: underline; +} + div.file-lines { display: table-cell; } diff --git a/cover/private/html/html.rkt b/cover/private/html/html.rkt index 43f2fba..336c3e5 100644 --- a/cover/private/html/html.rkt +++ b/cover/private/html/html.rkt @@ -210,33 +210,36 @@ (define (div:line-numbers line-count) `(div ([class "line-numbers"]) ,@(for/list ([num (in-range 1 (add1 line-count))]) - `(div () ,(number->string num))))) + (let ([str-num (number->string num)]) + `(div () (a ([href ,(string-append "#" str-num)]) ,str-num)))))) (module+ test (check-equal? (div:line-numbers 5) `(div ([class "line-numbers"]) - ,@(build-list 5 (λ (n) `(div () ,(number->string (add1 n)))))))) + ,@(build-list 5 (λ (n) `(div () (a ([href ,(format "#~a" (add1 n))]) + ,(number->string (add1 n))))))))) ;; [List String] Covered? -> Xexpr (define (div:file-lines file-lines covered?) - (define-values (line-divs _) - (for/fold ([lines '()] [pos 1]) ([line (in-list file-lines)]) - (values (cons (div:file-line line pos covered?) lines) - (add1 (+ pos (string-length line)))))) + (define-values (line-divs _1 _2) + (for/fold ([lines '()] [pos 1] [line-number 1]) ([line (in-list file-lines)]) + (values (cons (div:file-line line pos covered? line-number) lines) + (add1 (+ pos (string-length line))) + (add1 line-number)))) `(div ([class "file-lines"]) ,@(reverse line-divs))) (module+ test (define lines '("hello world" "goodbye")) (check-equal? (div:file-lines lines mock-covered?) `(div ([class "file-lines"]) - ,(div:file-line (first lines) 1 mock-covered?) - ,(div:file-line (second lines) 12 mock-covered?)))) + ,(div:file-line (first lines) 1 mock-covered? 1) + ,(div:file-line (second lines) 12 mock-covered? 2)))) ;; String Nat Covered? -> Xexpr ;; Build a single line into an Xexpr -(define (div:file-line line pos covered?) - (cond [(zero? (string-length line)) '(br ())] +(define (div:file-line line pos covered? line-number) + (cond [(zero? (string-length line)) `(br ([id ,(number->string line-number)]))] [else (define (build-span str type) `(span ([class ,(symbol->string type)]) ,str)) (define (add-expr cover-type expr cover-exprs) @@ -255,12 +258,13 @@ [else (define new-expr (add-expr current-cover-type expr/acc covered-exp)) (values new-expr (string c) (covered? (+ pos offset)))]))) - `(div ([class "line"]) ,@(reverse (add-expr coverage-type acc/str xexpr)))])) + `(div ([class "line"] [id ,(number->string line-number)]) + ,@(reverse (add-expr coverage-type acc/str xexpr)))])) (module+ test - (check-equal? (div:file-line "" 1 mock-covered?) '(br ())) - (check-equal? (div:file-line "hello world" 1 mock-covered?) - '(div ([class "line"]) (span ([class "covered"]) "hello") + (check-equal? (div:file-line "" 1 mock-covered? 999) '(br ([id "999"]))) + (check-equal? (div:file-line "hello world" 1 mock-covered? 2) + '(div ([class "line"] [id "2"]) (span ([class "covered"]) "hello") nbsp (span ([class "uncovered"]) "world")))) -- 2.34.1 From e7b2eab15b0cf9b25a01276c5eac8f021337856d Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Thu, 4 Feb 2016 10:37:47 -0600 Subject: [PATCH 05/15] move coveralls to after_success to avoid these pointless failures --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index ff1380c..c8dfafa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,6 @@ install: script: - raco test -Q $TRAVIS_BUILD_DIR + +after_success: - raco cover -f coveralls -d $TRAVIS_BUILD_DIR/coverage -b $TRAVIS_BUILD_DIR -- 2.34.1 From aa4b7ae8d8f753fb4e16fb748f364e71ad65a1f2 Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Thu, 11 Feb 2016 20:41:45 -0600 Subject: [PATCH 06/15] added codecov to readme --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d5dc63b..6a1be1e 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ [![Stories in Ready](https://badge.waffle.io/florence/cover.png?label=ready&title=Ready)](https://waffle.io/florence/cover) This library is an extensible code coverage tool for racket. It comes with the ability to generate -HTML reports, and has extensions to submit coverage reports to [Coveralls](https://coveralls.io/). -You can also create your own coverage formats. +HTML reports, and has extensions to submit coverage reports to [Codecov](https://codecov.io/) and +[Coveralls](https://coveralls.io/). You can also create your own coverage formats. ## How to install @@ -34,6 +34,9 @@ Code coverage can be generated in a different format by specifying the `-f
Date: Thu, 11 Feb 2016 21:03:46 -0600 Subject: [PATCH 07/15] moving to codecov --- .travis.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8dfafa..f70fd66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,10 @@ before_install: install: - raco pkg install --deps search-auto $TRAVIS_BUILD_DIR - - raco pkg install cover-coveralls + - raco pkg install cover-codecov script: - raco test -Q $TRAVIS_BUILD_DIR after_success: - - raco cover -f coveralls -d $TRAVIS_BUILD_DIR/coverage -b $TRAVIS_BUILD_DIR + - raco cover -f codecov -d $TRAVIS_BUILD_DIR/coverage -b $TRAVIS_BUILD_DIR diff --git a/README.md b/README.md index 6a1be1e..26f3a09 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Cover [![Build Status](https://img.shields.io/travis/florence/cover/master.svg)](https://travis-ci.org/florence/cover) -[![Coverage Status](https://img.shields.io/coveralls/florence/cover/master.svg)](https://coveralls.io/r/florence/cover?branch=master) +[![Coverage Status](https://codecov.io/github/florence/cover/coverage.svg?branch=master)](https://codecov.io/github/florence/cover?branch=master) [![Scribble](https://img.shields.io/badge/Docs-Scribble-blue.svg)](http://pkg-build.racket-lang.org/doc/cover/index.html) [![Stories in Ready](https://badge.waffle.io/florence/cover.png?label=ready&title=Ready)](https://waffle.io/florence/cover) -- 2.34.1 From c9be7019fbf9f22e0c32094c27028de1b014028c Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Mon, 29 Feb 2016 13:53:00 -0600 Subject: [PATCH 08/15] fixed multibyte coverage in submodules --- cover/private/format-utils.rkt | 4 +++- cover/tests/main.rkt | 2 +- cover/tests/multibyte-coverage/arrow.rkt | 27 ++++++++++++++++++++++ cover/tests/multibyte-coverage/arrow.rktl | 2 ++ cover/tests/multibyte-coverage/submod.rkt | 9 ++++++++ cover/tests/multibyte-coverage/submod.rktl | 2 ++ info.rkt | 3 ++- 7 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 cover/tests/multibyte-coverage/arrow.rkt create mode 100644 cover/tests/multibyte-coverage/arrow.rktl create mode 100644 cover/tests/multibyte-coverage/submod.rkt create mode 100644 cover/tests/multibyte-coverage/submod.rktl diff --git a/cover/private/format-utils.rkt b/cover/private/format-utils.rkt index ae702a4..66c412a 100644 --- a/cover/private/format-utils.rkt +++ b/cover/private/format-utils.rkt @@ -102,6 +102,7 @@ ;; String (Maybe (Listof Symbol)) (-> Natural Natural) Interval-Map -> Void ;; make listed submodules irrelevant (define (submod-irrelevant! str submods offset cmap) + ;; stx positions are in terms of bytes (define stx (with-input-from-string str (thunk (with-module-reading-parameterization read-syntax)))) @@ -118,7 +119,8 @@ (define ?start (syntax-position stx)) (when ?start (define start (- ?start (* 2 (offset ?start)))) - (define end (+ start (syntax-span stx))) + (define end* (+ ?start (syntax-span stx))) + (define end (- end* (* 2 (offset end*)))) (interval-map-set! cmap start end 'irrelevant))] [(e ...) (for-each loop* (syntax->list #'(e ...)))] [_else (void)]))) diff --git a/cover/tests/main.rkt b/cover/tests/main.rkt index d69b7fa..73efd5a 100644 --- a/cover/tests/main.rkt +++ b/cover/tests/main.rkt @@ -54,7 +54,7 @@ (cons a (ranges->numbers (cons (list (add1 a) b) r))))])) (module+ test - (define-runtime-path-list test-dirs '("basic" "simple-multi" "syntax" "at-exp")) + (define-runtime-path-list test-dirs '("basic" "simple-multi" "syntax" "at-exp" "multibyte-coverage")) (for-each (compose test-dir path->string) test-dirs) (define-runtime-path submods "submods") (parameterize ([irrelevant-submodules null]) diff --git a/cover/tests/multibyte-coverage/arrow.rkt b/cover/tests/multibyte-coverage/arrow.rkt new file mode 100644 index 0000000..545f483 --- /dev/null +++ b/cover/tests/multibyte-coverage/arrow.rkt @@ -0,0 +1,27 @@ +#lang racket + +;; Don't forget to require this at the template level! Otherwise, Racket will +;; complain that two instances of racket/gui are started. + +(module m-browse-syntax typed/racket + (require/typed macro-debugger/syntax-browser + [browse-syntax (→ Syntax Any)] + [browse-syntaxes (→ (Listof Syntax) Any)]) + + (provide browse-syntax + browse-syntaxes)) + +(define (debug-syntax stx) + (syntax-local-lift-expression #`(browse-syntax #'#,stx))) + +(require 'm-browse-syntax) +(provide browse-syntax + browse-syntaxes + debug-syntax) + +;; Avoid problems with raco test on headless machines (GTK tries to open +;; display :0 otherwise) +(module main racket) +(module test racket) + +;; FROM GH ISSUE 116 diff --git a/cover/tests/multibyte-coverage/arrow.rktl b/cover/tests/multibyte-coverage/arrow.rktl new file mode 100644 index 0000000..e20f098 --- /dev/null +++ b/cover/tests/multibyte-coverage/arrow.rktl @@ -0,0 +1,2 @@ +() +((400 485)) diff --git a/cover/tests/multibyte-coverage/submod.rkt b/cover/tests/multibyte-coverage/submod.rkt new file mode 100644 index 0000000..049bbd3 --- /dev/null +++ b/cover/tests/multibyte-coverage/submod.rkt @@ -0,0 +1,9 @@ +#lang racket +;; this is a comment +(+ 1 2) +(module+ test (λ (x) 3)) +(λ (x) 3) +(module+ test (λ (x) 3)) +(λ (x) 3) +(module+ test (λ (x) 3)) +(λ (x) 3) diff --git a/cover/tests/multibyte-coverage/submod.rktl b/cover/tests/multibyte-coverage/submod.rktl new file mode 100644 index 0000000..b2e4ac1 --- /dev/null +++ b/cover/tests/multibyte-coverage/submod.rktl @@ -0,0 +1,2 @@ +((14 41) (68 74) (76 76) (103 109) (111 111) (138 144) (146 146)) +() diff --git a/info.rkt b/info.rkt index 4cf39ab..d435c0a 100644 --- a/info.rkt +++ b/info.rkt @@ -10,4 +10,5 @@ (define build-deps '("racket-doc" "scribble-lib" "typed-racket-doc" "htdp-lib" - "net-doc" "scribble-doc" "at-exp-lib" "scheme-lib")) + "net-doc" "scribble-doc" "at-exp-lib" "scheme-lib" "typed-racket-lib" + "macro-debugger")) -- 2.34.1 From 578f4ebd0dee8b62e2e9325fbd7632c4b73499fe Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Mon, 29 Feb 2016 13:53:20 -0600 Subject: [PATCH 09/15] inc version number --- info.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.rkt b/info.rkt index d435c0a..f2309dd 100644 --- a/info.rkt +++ b/info.rkt @@ -3,7 +3,7 @@ (define name "cover") (define collection 'multi) -(define version "3.0.2") +(define version "3.0.3") (define deps '(("base" #:version "6.1.1") "errortrace-lib" "rackunit-lib" "syntax-color-lib" "compiler-lib" "custom-load" "data-lib")) -- 2.34.1 From 829735ffaebcd3994afb1ea569fde916243dc6e6 Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Mon, 29 Feb 2016 16:37:01 -0600 Subject: [PATCH 10/15] updated version matrix and print test failures --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f70fd66..eb3aff0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ env: - RACKET_VERSION=6.1.1 - RACKET_VERSION=6.2 - RACKET_VERSION=6.2.1 + - RACKET_VERSION=6.3 + - RACKET_VERSION=6.4 - RACKET_VERSION=HEAD matrix: @@ -22,7 +24,7 @@ install: - raco pkg install cover-codecov script: - - raco test -Q $TRAVIS_BUILD_DIR + - raco test $TRAVIS_BUILD_DIR after_success: - raco cover -f codecov -d $TRAVIS_BUILD_DIR/coverage -b $TRAVIS_BUILD_DIR -- 2.34.1 From d8771bec02f17e0e3e34a6e2ae10f14dc2a9b012 Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Mon, 29 Feb 2016 16:45:41 -0600 Subject: [PATCH 11/15] fix tests prior to 6.3 --- cover/tests/main.rkt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cover/tests/main.rkt b/cover/tests/main.rkt index 73efd5a..0d47a46 100644 --- a/cover/tests/main.rkt +++ b/cover/tests/main.rkt @@ -54,7 +54,11 @@ (cons a (ranges->numbers (cons (list (add1 a) b) r))))])) (module+ test - (define-runtime-path-list test-dirs '("basic" "simple-multi" "syntax" "at-exp" "multibyte-coverage")) + (define-runtime-path-list test-dirs (list* "basic" "simple-multi" "syntax" "at-exp" + ;; submodules don't work prior to this version! + (if (version<=? (version) "6.2.900") + null + "multibyte-coverage"))) (for-each (compose test-dir path->string) test-dirs) (define-runtime-path submods "submods") (parameterize ([irrelevant-submodules null]) -- 2.34.1 From 81649bb378c75d65df36cbfdf759aec01eb0ddac Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Mon, 29 Feb 2016 16:55:25 -0600 Subject: [PATCH 12/15] fixed tests --- cover/tests/main.rkt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cover/tests/main.rkt b/cover/tests/main.rkt index 0d47a46..c4b11ce 100644 --- a/cover/tests/main.rkt +++ b/cover/tests/main.rkt @@ -54,11 +54,12 @@ (cons a (ranges->numbers (cons (list (add1 a) b) r))))])) (module+ test + (require (for-syntax version/utils) version/utils) (define-runtime-path-list test-dirs (list* "basic" "simple-multi" "syntax" "at-exp" ;; submodules don't work prior to this version! (if (version<=? (version) "6.2.900") null - "multibyte-coverage"))) + (list "multibyte-coverage")))) (for-each (compose test-dir path->string) test-dirs) (define-runtime-path submods "submods") (parameterize ([irrelevant-submodules null]) -- 2.34.1 From 09290b40839f1f62b3e5262298f5fe0e1b0bdcb5 Mon Sep 17 00:00:00 2001 From: Spencer Florence Date: Fri, 4 Mar 2016 18:05:11 -0600 Subject: [PATCH 13/15] handle modules setting port-count-lines-enabled --- cover/private/format-utils.rkt | 49 +++++++++++++++++++++++----------- cover/tests/main.rkt | 3 ++- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cover/private/format-utils.rkt b/cover/private/format-utils.rkt index 66c412a..94f6096 100644 --- a/cover/private/format-utils.rkt +++ b/cover/private/format-utils.rkt @@ -38,25 +38,27 @@ ;; (or/c #f (listof symbol)) (define irrelevant-submodules (make-parameter #f)) +(define current-file (make-parameter #f)) ;; Path FileCoverage -> [Hashof Natural Cover] ;; build a hash caching coverage info for that file (define (coverage-cache-file key c submods) - (vprintf "caching coverage info for ~s\n" key) - (define get-covered (raw-covered c)) + (parameterize ([current-file key] [port-count-lines-enabled #f]) + (vprintf "caching coverage info for ~s\n" key) + (define get-covered (raw-covered c)) - (when (path-string? key) - (call-with-input-file key - (lambda (input) - (define lexer - (maybe-wrap-lexer - (with-handlers ([exn:fail:read? (const racket-lexer)]) - (define f (read-language input)) - (cond [f (f 'color-lexer racket-lexer)] - [else racket-lexer])))) - (make-irrelevant! lexer key input submods get-covered)))) + (when (path-string? key) + (call-with-input-file key + (lambda (input) + (define lexer + (maybe-wrap-lexer + (with-handlers ([exn:fail:read? (const racket-lexer)]) + (define f (read-language input)) + (cond [f (f 'color-lexer racket-lexer)] + [else racket-lexer])))) + (make-irrelevant! lexer key input submods get-covered)))) - get-covered) + get-covered)) ;; There are two variatese of racket lexers ;; if we are given the one argument kind, wrap it to the three arg kind @@ -83,6 +85,7 @@ (define (lex-irrelevant! lexer fstr str offset cmap) (define init-offset (- (string-length fstr) (string-length str))) (define for-lex (open-input-string str)) + (let loop ([mode #f]) (define-values (v type _m start end backup-dist new-mode/ds) (lexer for-lex 0 mode)) @@ -95,7 +98,7 @@ [(comment sexp-comment white-space) (define s (+ init-offset (- start (offset start)))) (define e (+ init-offset (- end (offset end)))) - (interval-map-set! cmap s e 'irrelevant) + (update-map! cmap s e 'irrelevant) (loop new-mode)] [else (loop new-mode)]))) @@ -121,7 +124,7 @@ (define start (- ?start (* 2 (offset ?start)))) (define end* (+ ?start (syntax-span stx))) (define end (- end* (* 2 (offset end*)))) - (interval-map-set! cmap start end 'irrelevant))] + (update-map! cmap start end 'irrelevant))] [(e ...) (for-each loop* (syntax->list #'(e ...)))] [_else (void)]))) @@ -136,7 +139,7 @@ (for ([pair (in-list ordered)]) (match-define (list m (srcloc _ _ _ start range)) pair) (define val (if m 'covered 'uncovered)) - (interval-map-set! r start (+ start range) val)) + (update-map! r start (+ start range) val)) r) @@ -166,6 +169,20 @@ (vector-ref mapping (sub1 (vector-length mapping))) (vector-ref mapping (sub1 offset))))) +;; intervalmap nat nat any file -> void +;; sets the interval map if the range makes sense +;; logs a warning otherwise +(define (update-map! i s e v [extra-debug #f]) + (if (> e s) + (interval-map-set! i s e v) + (log-message + (current-logger) + 'warning + 'cover + (format "found non-sensable character range [~a,~a) in file ~a. Skiping coverage info for that range ~a" + s e (current-file) (or extra-debug "")) + (current-continuation-marks)))) + (module+ test (require racket/lazy-require) (lazy-require ["../cover.rkt" diff --git a/cover/tests/main.rkt b/cover/tests/main.rkt index c4b11ce..f8988f6 100644 --- a/cover/tests/main.rkt +++ b/cover/tests/main.rkt @@ -21,7 +21,8 @@ (path->string (path-replace-suffix f ".rktl"))))) (define (do-test files) - (parameterize ([current-cover-environment (make-cover-environment)]) + (parameterize ([current-cover-environment (make-cover-environment)] + [port-count-lines-enabled (> 0.5 (random))]) (apply test-files! files) (define coverage (get-test-coverage)) -- 2.34.1 From 835c9f8cdd4aa8f35acb93379388f98eadf07235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 23 Mar 2016 17:46:10 +0100 Subject: [PATCH 14/15] Fixes GH issue #118 "Division by zero when there are no relevant expressions" Fixed by showing 100% coverage in that case (100% is what coveralls.io shows when there are no relevant lines). --- cover/private/html/html.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cover/private/html/html.rkt b/cover/private/html/html.rkt index a0b4175..528c8bd 100644 --- a/cover/private/html/html.rkt +++ b/cover/private/html/html.rkt @@ -151,7 +151,7 @@ (meta ([charset "utf-8"])) (link ([rel "stylesheet"] [type "text/css"] [href ,(string-append assets-path "main.css")]))) (body () - ,(%s->xexpr (/ covered total)) + ,(%s->xexpr (if (= total 0) 1 (/ covered total))) (div ([class "code"]) ,(file->html path covered?))))) (define (%s->xexpr %) -- 2.34.1 From 3d592e00568df9a102e5a0233e46bdab67e446c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 23 Mar 2016 17:46:10 +0100 Subject: [PATCH 15/15] Fixes GH issue #118 "Division by zero when there are no relevant expressions" Fixed by showing 100% coverage in that case (100% is what coveralls.io shows when there are no relevant lines). --- cover/private/html/html.rkt | 66 +++++++++++++++++++++------ cover/raco.rkt | 3 +- cover/tests/basic/no-expressions.rkt | 1 + cover/tests/basic/no-expressions.rktl | 2 + 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 cover/tests/basic/no-expressions.rkt create mode 100644 cover/tests/basic/no-expressions.rktl diff --git a/cover/private/html/html.rkt b/cover/private/html/html.rkt index 336c3e5..f00be11 100644 --- a/cover/private/html/html.rkt +++ b/cover/private/html/html.rkt @@ -21,6 +21,7 @@ (define-runtime-path root "../..") (define-runtime-path tests/basic/prog.rkt "../../tests/basic/prog.rkt") (define-runtime-path tests/basic/not-run.rkt "../../tests/basic/not-run.rkt") + (define-runtime-path tests/basic/no-expressions.rkt "../../tests/basic/no-expressions.rkt") (define (mock-covered? pos) (cond [(<= 1 pos 6) 'covered] [(= 6 pos) 'missing] @@ -151,7 +152,7 @@ (meta ([charset "utf-8"])) (link ([rel "stylesheet"] [type "text/css"] [href ,(string-append assets-path "main.css")]))) (body () - ,(%s->xexpr (/ covered total)) + ,(%s->xexpr (if (= total 0) 1 (/ covered total))) (div ([class "code"]) ,(file->html path covered?))))) (define (%s->xexpr %) @@ -164,6 +165,20 @@ (test-files! f) (define cov (get-test-coverage)) (define covered? (curry cov f)) + (check-equal? (make-html-file cov f "assets/") + `(html () + (head () + (meta ([charset "utf-8"])) + (link ([rel "stylesheet"] [type "text/css"] [href "assets/main.css"]))) + (body () + (p () "expr: 100%" (br ())) + (div ([class "code"]) + ,(file->html f covered?)))))) + (parameterize ([current-cover-environment (make-cover-environment)]) + (define f (path->string (simplify-path tests/basic/no-expressions.rkt))) + (test-files! f) + (define cov (get-test-coverage)) + (define covered? (curry cov f)) (check-equal? (make-html-file cov f "assets/") `(html () (head () @@ -191,16 +206,27 @@ (check-equal? (file->html f covered?) `(div ([class "lines-wrapper"]) ,(div:line-numbers (length lines)) - ,(div:file-lines lines covered?))) + ,(div:file-lines lines covered?))))) + (test-begin (parameterize ([current-cover-environment (make-cover-environment)]) - (define f2 (path->string (simplify-path tests/basic/not-run.rkt))) - (test-files! f2) - (define covered? (curry (get-test-coverage) f2)) - (define lines (string-split (file->string f2) "\n" #:trim? #f)) - (check-equal? (file->html f2 covered?) - `(div ([class "lines-wrapper"]) - ,(div:line-numbers 4) - ,(div:file-lines lines covered?))))))) + (define f (path->string (simplify-path tests/basic/not-run.rkt))) + (test-files! f) + (define covered? (curry (get-test-coverage) f)) + (define lines (string-split (file->string f) "\n" #:trim? #f)) + (check-equal? (file->html f covered?) + `(div ([class "lines-wrapper"]) + ,(div:line-numbers 4) + ,(div:file-lines lines covered?))))) + (test-begin + (parameterize ([current-cover-environment (make-cover-environment)]) + (define f (path->string (simplify-path tests/basic/no-expressions.rkt))) + (test-files! f) + (define covered? (curry (get-test-coverage) f)) + (define lines (string-split (file->string f) "\n" #:trim? #f)) + (check-equal? (file->html f covered?) + `(div ([class "lines-wrapper"]) + ,(div:line-numbers 1) + ,(div:file-lines lines covered?)))))) ;; File Report ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -324,7 +350,7 @@ (path->string (find-relative-path (current-directory) (string->path name)))) (define covered (first expr-coverage-info)) (define total (second expr-coverage-info)) - (define percentage (* 100 (/ covered total))) + (define percentage (* 100 (if (= total 0) 1 (/ covered total)))) (define styles `([class "file-info"])) `(tr ,styles (td ([class "file-name"]) (a ([href ,path]) ,local-file)) @@ -347,7 +373,14 @@ (td ([class "coverage-percentage"]) "100") (td ([class "covered-expressions"]) "10") (td ([class "uncovered-expressions"]) "0") - (td ([class "total-expressions"]) "10"))))) + (td ([class "total-expressions"]) "10")))) + (test-begin (check-equal? (tr:file-report "foo.rkt" "foo.html" (list 0 0)) + '(tr ((class "file-info")) + (td ([class "file-name"]) (a ((href "foo.html")) "foo.rkt")) + (td ([class "coverage-percentage"]) "100") + (td ([class "covered-expressions"]) "0") + (td ([class "uncovered-expressions"]) "0") + (td ([class "total-expressions"]) "0"))))) ;; Percentage ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -359,14 +392,19 @@ (define (expression-coverage-percentage/all all-expr-info) (define total-covered (for/sum ([v (in-list (hash-values all-expr-info))]) (first v))) (define total-exprs (for/sum ([v (in-list (hash-values all-expr-info))]) (second v))) - (* (/ total-covered total-exprs) 100)) + (* (if (= total-exprs 0) 1 (/ total-covered total-exprs)) 100)) (module+ test (test-begin (check-equal? (expression-coverage-percentage/all (hash "foo.rkt" (list 0 10) "bar.rkt" (list 10 10))) - 50))) + 50)) + (test-begin + (check-equal? + (expression-coverage-percentage/all (hash "foo.rkt" (list 0 0) + "bar.rkt" (list 0 0))) + 100))) ;; Expression Coverage ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/cover/raco.rkt b/cover/raco.rkt index da3b7a7..1d1be0c 100644 --- a/cover/raco.rkt +++ b/cover/raco.rkt @@ -233,7 +233,8 @@ (check-equal? (list->set (map (compose path->string ->relative) (flatten (expand-directory (list extensions))))) (set "prog.rkt" - "not-run.rkt"))) + "not-run.rkt" + "no-expressions.rkt"))) (parameterize ([current-directory cur]) (define omit (map ->absolute (get-info-var cur 'test-omit-paths))) (define dirs (map ->absolute (filter list? (flatten (expand-directory (list extensions)))))) diff --git a/cover/tests/basic/no-expressions.rkt b/cover/tests/basic/no-expressions.rkt new file mode 100644 index 0000000..9c79238 --- /dev/null +++ b/cover/tests/basic/no-expressions.rkt @@ -0,0 +1 @@ +#lang racket \ No newline at end of file diff --git a/cover/tests/basic/no-expressions.rktl b/cover/tests/basic/no-expressions.rktl new file mode 100644 index 0000000..c5c5ef4 --- /dev/null +++ b/cover/tests/basic/no-expressions.rktl @@ -0,0 +1,2 @@ +() +() -- 2.34.1