1 (define-module (scm coverage))
6 (ice-9 format) ;; needed for ~8@
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 (define-public (coverage:show-all filter?)
15 (sort (map car (hash-table->alist coverage-table)) string<? ))))
21 (format #t "Coverage for file: ~a\n" k)
23 k (hash-ref coverage-table k)
24 (format #f "~a.cov" (basename k))))
28 (define-public (coverage:enable)
29 (trap-set! memoize-symbol-handler record-coverage)
30 (trap-enable 'memoize-symbol)
34 (define-public (coverage:disable)
35 (trap-set! memoize-symbol-handler #f)
36 (trap-disable 'memoize-symbol))
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 (define coverage-table (make-hash-table 57))
42 (define (read-lines port)
43 (string-split (read-delimited "" port) #\newline))
45 (define (display-coverage file vec out-file)
47 ((lines (read-lines (open-file file "r")))
48 (format-str "~8@a: ~5@a:~a\n")
49 (out (if out-file (open-output-file out-file)
50 (current-output-port))))
52 (format out format-str "-" 0 (format #f "Source:~a" file))
58 (format out format-str
60 ((and (< i (vector-length vec)) (vector-ref vec i)) "1")
61 ((and (string-contains file ".ly") (string-match "^[ \t]*%.*$" (car l)))
63 ((string-match "^[ \t]*[()'`,]*$" (car l))
65 ((string-match "^[ \t]*;.*$" (car l))
72 (define (record-coverage key cont exp env)
74 ((name (source-property exp 'filename))
75 (line (source-property exp 'line))
76 (vec (and name (hash-ref coverage-table name #f)))
77 (veclen (and vec (vector-length vec)))
78 (veccopy (lambda (src dst)
79 (vector-move-left! src 0 (vector-length src)
84 (if (or (not vec) (>= line (vector-length vec)))
86 (hash-set! coverage-table name
88 (veccopy vec (make-vector (1+ line) #f))
89 (make-vector (1+ line) #f)))))
91 (vector-set! vec line #t))