Skip to content

Commit

Permalink
Refactoring test report formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred Xiao committed Aug 7, 2019
1 parent 1ab7a69 commit 8349f56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject canvas "0.1.2"
(defproject canvas "0.1.6"
:description "Clojure plugin for leiningen that reports on test coverage."
:url "https://github.com/alfredxiao/canvas"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
30 changes: 19 additions & 11 deletions src/canvas/report.clj
Expand Up @@ -10,27 +10,35 @@
(map count)
(apply max))
nsname-fmt-str (str " %s %-" (inc max-nsname-len) "s%s")
max-chars-per-line (+ max-nsname-len 20)]
(println (apply str (repeat max-chars-per-line "=")))
max-chars-per-line (+ max-nsname-len 11)
title " Canvas Test Coverage Report "
half-long-equal-sign (apply str (repeat (/ (- max-chars-per-line
(count title))
2)
"="))]
(println (str half-long-equal-sign title half-long-equal-sign))
(doseq [[nsname ns-stats] stats]
(println nsname)
(doseq [[fn-name fn-stat] ns-stats]
(let [visibility-indicator (if (:private fn-stat) "-" "+")
tested-indicator (if (:tested? fn-stat) "T" " ")]
(println (format nsname-fmt-str visibility-indicator fn-name
(format "%s %d" tested-indicator (:hit fn-stat)))))))
(if (zero? (:hit fn-stat))
"/ /"
(format "%s %2d" tested-indicator (:hit fn-stat))))))))
(println (apply str (repeat max-chars-per-line "=")))))

(defn report [nss reporter]
(let [stats (into {}
(for [n nss :when (not (user? n))]
[(ns-name n)
(into {}
(for [[_ v] (ns-interns n) :when (ins/instrumentable? v)]
[(:name (meta v)) (let [mt (meta v)]
{:private (:private mt)
:line (:line mt)
:tested? (:canvas.instrument/tested? mt)
:hit (:canvas.instrument/hit mt)})]))]))]
(let [ns-stats (into {}
(for [[_ v] (ns-interns n) :when (ins/instrumentable? v)]
[(:name (meta v)) (let [mt (meta v)]
{:private (:private mt)
:line (:line mt)
:tested? (:canvas.instrument/tested? mt)
:hit (:canvas.instrument/hit mt)})]))]
(when-not (empty? ns-stats)
[(ns-name n) ns-stats]))))]
(case reporter
(console stats))))

0 comments on commit 8349f56

Please sign in to comment.