removed nan checks. apparently that can't happen
This commit is contained in:
parent
00335ccc12
commit
fad96b4d0e
|
@ -102,9 +102,8 @@
|
||||||
(meta ([charset "utf-8"]))
|
(meta ([charset "utf-8"]))
|
||||||
(link ([rel "stylesheet"] [type "text/css"] [href ,path-to-css])))
|
(link ([rel "stylesheet"] [type "text/css"] [href ,path-to-css])))
|
||||||
(body ()
|
(body ()
|
||||||
,(if (zero? total) "No Coverage Information" (%s->xexpr (/ covered total)))
|
,(%s->xexpr (/ covered total))
|
||||||
(div ([class "code"])
|
(div ([class "code"]) ,(file->html path covered?)))))
|
||||||
,(file->html path covered?)))))
|
|
||||||
|
|
||||||
(define (%s->xexpr %)
|
(define (%s->xexpr %)
|
||||||
`(p () ,(~a "expr" ': " " (~r (* 100 %) #:precision 2) "%") (br ())))
|
`(p () ,(~a "expr" ': " " (~r (* 100 %) #:precision 2) "%") (br ())))
|
||||||
|
@ -199,11 +198,7 @@
|
||||||
[else
|
[else
|
||||||
(define new-expr (add-expr current-cover-type expr/acc covered-exp))
|
(define new-expr (add-expr current-cover-type expr/acc covered-exp))
|
||||||
(values new-expr (string c) (covered? (+ pos offset)))])))
|
(values new-expr (string c) (covered? (+ pos offset)))])))
|
||||||
(define result
|
`(div ([class "line"]) ,@(reverse (add-expr coverage-type acc/str xexpr)))]))
|
||||||
(if coverage-type
|
|
||||||
(cons (build-span acc/str coverage-type) xexpr)
|
|
||||||
xexpr))
|
|
||||||
`(div ([class "line"]) ,@(reverse result))]))
|
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(check-equal? (div:file-line "" 1 mock-covered?) '(br ()))
|
(check-equal? (div:file-line "" 1 mock-covered?) '(br ()))
|
||||||
|
@ -231,17 +226,15 @@
|
||||||
;; [Hash FilePath ExpressionInfo] -> Xexpr
|
;; [Hash FilePath ExpressionInfo] -> Xexpr
|
||||||
(define (div:total-coverage expr-coverages)
|
(define (div:total-coverage expr-coverages)
|
||||||
(define total-coverage-percentage (expression-coverage-percentage/all expr-coverages))
|
(define total-coverage-percentage (expression-coverage-percentage/all expr-coverages))
|
||||||
(define coverage-as-string
|
|
||||||
(if (equal? +nan.0 total-coverage-percentage)
|
|
||||||
"No Coverage Information"
|
|
||||||
(real->decimal-string total-coverage-percentage)))
|
|
||||||
`(div ([class "total-coverage"])
|
`(div ([class "total-coverage"])
|
||||||
,(string-append "Total Project Coverage: " coverage-as-string "%")))
|
,(string-append "Total Project Coverage: "
|
||||||
|
(~r total-coverage-percentage #:precision 2)
|
||||||
|
"%")))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(test-begin (check-equal? (div:total-coverage (hash "foo.rkt" (list 0 10)
|
(test-begin (check-equal? (div:total-coverage (hash "foo.rkt" (list 0 10)
|
||||||
"bar.rkt" (list 10 10)))
|
"bar.rkt" (list 10 10)))
|
||||||
'(div ([class "total-coverage"]) "Total Project Coverage: 50.00%"))))
|
'(div ([class "total-coverage"]) "Total Project Coverage: 50%"))))
|
||||||
|
|
||||||
;; [Hash FilePath ExpressionInfo] -> Xexpr
|
;; [Hash FilePath ExpressionInfo] -> Xexpr
|
||||||
(define (table:file-reports expr-coverages)
|
(define (table:file-reports expr-coverages)
|
||||||
|
@ -262,31 +255,27 @@
|
||||||
(define (tr:file-report path expr-coverage-info stripe?)
|
(define (tr:file-report path expr-coverage-info stripe?)
|
||||||
(define local-file
|
(define local-file
|
||||||
(path->string (find-relative-path (current-directory) (string->path path))))
|
(path->string (find-relative-path (current-directory) (string->path path))))
|
||||||
(define percentage
|
(define percentage (* 100 (/ (first expr-coverage-info) (second expr-coverage-info))))
|
||||||
(cond
|
|
||||||
[(zero? (second expr-coverage-info)) +nan.0]
|
|
||||||
[else (exact->inexact (* 100 (/ (first expr-coverage-info)
|
|
||||||
(second expr-coverage-info))))]))
|
|
||||||
(define styles `([class ,(string-append "file-info" (if stripe? " stripe" ""))]))
|
(define styles `([class ,(string-append "file-info" (if stripe? " stripe" ""))]))
|
||||||
`(tr ,styles
|
`(tr ,styles
|
||||||
(td ([class "file-name"]) (a ([href ,(coverage-report-link path)]) ,local-file))
|
(td ([class "file-name"]) (a ([href ,(coverage-report-link path)]) ,local-file))
|
||||||
(td () ,(if (nan? percentage) "No Coverage Info" (real->decimal-string percentage)))
|
(td () ,(~r percentage #:precision 2))
|
||||||
(td () ,(real->decimal-string (first expr-coverage-info)))
|
(td () ,(~r (first expr-coverage-info) #:precision 2))
|
||||||
(td () ,(real->decimal-string (second expr-coverage-info)))))
|
(td () ,(~r (second expr-coverage-info) #:precision 2))))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(test-begin (check-equal? (tr:file-report "foo.rkt" (list 0 0) #f)
|
(test-begin (check-equal? (tr:file-report "foo.rkt" (list 0 1) #f)
|
||||||
'(tr ((class "file-info"))
|
'(tr ((class "file-info"))
|
||||||
(td ([class "file-name"]) (a ((href "foo.html")) "foo.rkt"))
|
(td ([class "file-name"]) (a ((href "foo.html")) "foo.rkt"))
|
||||||
(td () "No Coverage Info")
|
(td () "0")
|
||||||
(td () "0.00")
|
(td () "0")
|
||||||
(td () "0.00"))))
|
(td () "1"))))
|
||||||
(test-begin (check-equal? (tr:file-report "foo.rkt" (list 10 10) #t)
|
(test-begin (check-equal? (tr:file-report "foo.rkt" (list 10 10) #t)
|
||||||
'(tr ((class "file-info stripe"))
|
'(tr ((class "file-info stripe"))
|
||||||
(td ([class "file-name"]) (a ((href "foo.html")) "foo.rkt"))
|
(td ([class "file-name"]) (a ((href "foo.html")) "foo.rkt"))
|
||||||
(td () "100.00")
|
(td () "100")
|
||||||
(td () "10.00")
|
(td () "10")
|
||||||
(td () "10.00")))))
|
(td () "10")))))
|
||||||
|
|
||||||
;; Path -> String
|
;; Path -> String
|
||||||
;; Generate a link to the coverage report
|
;; Generate a link to the coverage report
|
||||||
|
@ -309,26 +298,21 @@
|
||||||
(define (expression-coverage-percentage/all all-expr-info)
|
(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-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)))
|
(define total-exprs (for/sum ([v (in-list (hash-values all-expr-info))]) (second v)))
|
||||||
(if (zero? total-exprs)
|
(* (/ total-covered total-exprs) 100))
|
||||||
+nan.0
|
|
||||||
(* (/ total-covered total-exprs) 100)))
|
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(test-begin
|
(test-begin
|
||||||
(check-equal?
|
(check-equal?
|
||||||
(expression-coverage-percentage/all (hash "foo.rkt" (list 0 10)
|
(expression-coverage-percentage/all (hash "foo.rkt" (list 0 10)
|
||||||
"bar.rkt" (list 10 10)))
|
"bar.rkt" (list 10 10)))
|
||||||
50))
|
50)))
|
||||||
|
|
||||||
(test-begin (check-equal? (expression-coverage-percentage/all (hash "foo.rkt" (list 0 0)))
|
|
||||||
+nan.0)))
|
|
||||||
|
|
||||||
;; Expression Coverage
|
;; Expression Coverage
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;; ExpressionInfo is a (List Nat Nat) where:
|
;; ExpressionInfo is a (List Nat Nat) where:
|
||||||
;; the first element is the number of covered expressions
|
;; the first element is the number of covered expressions
|
||||||
;; the second element is the total number of expressions
|
;; the second element is the total number of expressions. This will never be 0.
|
||||||
|
|
||||||
;; Coverage -> [Hash FilePath ExpressionInfo]
|
;; Coverage -> [Hash FilePath ExpressionInfo]
|
||||||
;; returns a hash that maps file paths to an ExpressionInfo
|
;; returns a hash that maps file paths to an ExpressionInfo
|
||||||
|
|
Loading…
Reference in New Issue
Block a user