starting on coverage reporting
This commit is contained in:
parent
ed5812cf8b
commit
55a6e03c77
45
main.rkt
45
main.rkt
|
@ -14,7 +14,8 @@
|
||||||
(define (test-files . paths)
|
(define (test-files . paths)
|
||||||
(for ([p paths])
|
(for ([p paths])
|
||||||
(define stx
|
(define stx
|
||||||
(with-module-reading-parameterization (thunk (read-syntax p (open-input-file p)))))
|
(with-module-reading-parameterization
|
||||||
|
(thunk (read-syntax p (open-input-file p)))))
|
||||||
(define-values (name anned)
|
(define-values (name anned)
|
||||||
(syntax-parse (expand stx)
|
(syntax-parse (expand stx)
|
||||||
#:datum-literals (module)
|
#:datum-literals (module)
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
(values (syntax-e #'name)
|
(values (syntax-e #'name)
|
||||||
(annotate-top #'s (namespace-base-phase ns)))]))
|
(annotate-top #'s (namespace-base-phase ns)))]))
|
||||||
(eval-syntax anned ns)
|
(eval-syntax anned ns)
|
||||||
|
;; TODO run test/given submodule
|
||||||
(parameterize ([current-namespace ns])
|
(parameterize ([current-namespace ns])
|
||||||
(namespace-require `',name)))
|
(namespace-require `',name)))
|
||||||
coverage)
|
coverage)
|
||||||
|
@ -30,3 +32,44 @@
|
||||||
(dict-clear! coverage)
|
(dict-clear! coverage)
|
||||||
(set! ns (make-base-empty-namespace))
|
(set! ns (make-base-empty-namespace))
|
||||||
(namespace-attach-module (current-namespace) "coverage.rkt" ns))
|
(namespace-attach-module (current-namespace) "coverage.rkt" ns))
|
||||||
|
|
||||||
|
(define (test-coverage-annotations)
|
||||||
|
;; can-annotate : (listof (list boolean srcloc))
|
||||||
|
;; boolean is #t => code was run
|
||||||
|
;; #f => code was not run
|
||||||
|
;; remove those that cannot be annotated
|
||||||
|
(define can-annotate
|
||||||
|
(filter values
|
||||||
|
(for/list ([(stx covered?) coverage])
|
||||||
|
(and (syntax? stx)
|
||||||
|
(let ([src (syntax-source stx)]
|
||||||
|
[pos (syntax-position stx)]
|
||||||
|
[span (syntax-span stx)])
|
||||||
|
(and pos
|
||||||
|
span
|
||||||
|
#;
|
||||||
|
(hash-ref! port-name-cache src
|
||||||
|
(λ () (send (get-defs) port-name-matches? src)))
|
||||||
|
(list covered?
|
||||||
|
(make-srcloc src #f #f pos span))))))))
|
||||||
|
|
||||||
|
;; filtered : (listof (list boolean srcloc))
|
||||||
|
;; remove redundant expressions
|
||||||
|
(define filtered
|
||||||
|
;; actions-ht : (list src number number) -> (list boolean syntax)
|
||||||
|
(let ([actions-ht (make-hash)])
|
||||||
|
(for-each
|
||||||
|
(λ (pr)
|
||||||
|
(let* ([on? (list-ref pr 0)]
|
||||||
|
[key (list-ref pr 1)]
|
||||||
|
[old (hash-ref actions-ht key 'nothing)])
|
||||||
|
(cond
|
||||||
|
[(eq? old 'nothing) (hash-set! actions-ht key on?)]
|
||||||
|
[old ;; recorded as executed
|
||||||
|
(void)]
|
||||||
|
[(not old) ;; recorded as unexected
|
||||||
|
(when on?
|
||||||
|
(hash-set! actions-ht key #t))])))
|
||||||
|
can-annotate)
|
||||||
|
(hash-map actions-ht (λ (k v) (list v k)))))
|
||||||
|
filtered)
|
||||||
|
|
2
tests/basic/prog.rkt
Normal file
2
tests/basic/prog.rkt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#lang racket
|
||||||
|
(+ 1 2)
|
Loading…
Reference in New Issue
Block a user