Skip to content

Instantly share code, notes, and snippets.

@arohner
Created May 31, 2013 21:15
Show Gist options
  • Select an option

  • Save arohner/5688067 to your computer and use it in GitHub Desktop.

Select an option

Save arohner/5688067 to your computer and use it in GitHub Desktop.
Fixed clojure.test fixtures
(ns circle.monkey-patch-clojure-test
"less buggy test runner"
(:require clojure.test))
(in-ns 'clojure.test)
(require '[clojure.core.strint :refer (<<)])
(defn test*
"Circle monkeypatch."
[v]
(when-let [t (:test (meta v))]
(do-report {:type :begin-test-var, :var v})
(inc-report-counter :test)
(t)
(do-report {:type :end-test-var, :var v})))
(defn test-var
"Circle monkeypatch. Same as clojure.test/test-var, but actually uses the damned fixtures. Also binds *testing-vars* earlier, so it's accessible to fixtures"
[v]
(assert (var? v) (<< "v must be a var. got ~(class v)"))
(let [ns (-> v meta :ns)
each-fixture-fn (join-fixtures (:clojure.test/each-fixtures (meta ns)))]
(when (:test (meta v))
(binding [*testing-vars* (conj *testing-vars* v)]
(try
(each-fixture-fn (fn [] (test* v)))
(catch Throwable e
(do-report {:type :error, :message "Uncaught exception, not in assertion."
:expected nil, :actual e})))))))
(defn test-all-vars
"Circle monkeypatch. Since we moved the fixture call into test-var,
move it out of here so we don't call them twice"
[ns]
(let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))]
(once-fixture-fn
(fn []
(doseq [v (vals (ns-interns ns))]
(when (:test (meta v))
(test-var v)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment