(ns thomas.core
  "Function-level test coverage reports."
  (:require [clojure.test])
  (:gen-class))

(defn skip-ns? [n]
  (re-find #"^(clojure\.|swank\.|user$)" (str (.getName n))))

(defn instrument [f v]
  (fn [& args]
    (alter-meta! v assoc ::untested? false)
    (apply f args)))

(defn instrument-nses [nses]
  (doseq [n nses [_ v] (ns-publics n)]
    (when (fn? @v)
      (alter-meta! v assoc ::untested? true)
      (alter-var-root v instrument v))))

(defn uncovered [nses]
  (for [n nses [_ v] (ns-publics n) :when (::untested? (meta v))] v))

(defn -main [& test-nses]
  (doseq [n test-nses] (require (symbol n)))
  (let [impl-nses (remove skip-ns? (all-ns))]
    (instrument-nses impl-nses)
    (with-out-str
      (apply clojure.test/run-tests (map symbol test-nses)))
    (println "Missing test coverage for:")
    (doseq [v (uncovered impl-nses)]
      (println v))))

Generated by Phil Hagelberg using scpaste at Tue Mar 16 12:51:16 2010. PDT. (raw)