Skip to content
Browse files

Initial commit: 1.0.0.

  • Loading branch information...
0 parents commit 12fa8543cdaacc39f75ed1d3913641f0346e23cc @technomancy committed Jul 1, 2010
Showing with 80 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +27 −0 README
  3. +5 −0 project.clj
  4. +10 −0 src/leiningen/radagast.clj
  5. +34 −0 src/radagast/coverage.clj
4 .gitignore
@@ -0,0 +1,4 @@
+pom.xml
+*jar
+lib
+classes
27 README
@@ -0,0 +1,27 @@
+# Radagast
+
+ Radagast the Brown! ... Radagast the Bird-tamer! Radagast the
+ Simple! Radagast the Fool! Yet he had just the wit to play the
+ part that I set him.
+ -- Saruman, Lord of the Rings
+
+Radagast is a simplistic test coverage tool. It will let you know if
+you've got huge holes in your test coverage. However, you should not
+rely on Radagast to tell you if your tests are good!
+
+## Usage
+
+For now it only works as a Leiningen plugin. Include it as a
+dev-dependency in your project.clj:
+
+ :dev-dependencies [[radagast "1.0.0"]]
+
+Then you can use it:
+
+ lein deps && lein radagast
+
+## License
+
+Copyright (C) 2010 Phil Hagelberg
+
+Distributed under the Eclipse Public License, the same as Clojure.
5 project.clj
@@ -0,0 +1,5 @@
+(defproject radagast "1.0.0"
+ :description "Simplistic test coverage."
+ :dev-dependencies [[org.clojure/clojure "1.1.0"]
+ [org.clojure/clojure-contrib "1.1.0"]
+ [swank-clojure "1.2.1"]])
10 src/leiningen/radagast.clj
@@ -0,0 +1,10 @@
+(ns leiningen.radagast
+ (:use [leiningen.compile :only [eval-in-project]]))
+
+(defn radagast [project & nses]
+ (eval-in-project
+ project `(do (require '~'radagast.coverage)
+ (binding [radagast.coverage/*ns-must-match*
+ ~(:radagast/ns-whitelist project)]
+ (@(ns-resolve '~'radagast.coverage '~'coverage)
+ ~@nses)))))
34 src/radagast/coverage.clj
@@ -0,0 +1,34 @@
+(ns radagast.coverage
+ (:require [clojure.test]))
+
+(def *ns-must-match* nil)
+
+(defn skip-ns? [n]
+ (or (re-find #"(^clojure\.|radagast)" (str (.getName n)))
+ (and *ns-must-match*
+ (not (re-find *ns-must-match* (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 (and (.isBound v) (fn? @v)
+ (not (:macro (meta v))) (not (:test (meta 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 coverage [& 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))))

0 comments on commit 12fa854

Please sign in to comment.
Something went wrong with that request. Please try again.