Skip to content
Browse files

Runs fixtures when calling a single test function.

  • Loading branch information...
1 parent bf1a5ef commit c24da58b418e57b94ec6f2810f34b8f1c82c7fe8 @pjstadig committed Mar 6, 2013
Showing with 29 additions and 17 deletions.
  1. +29 −17 src/name/stadig/conjecture.clj
View
46 src/name/stadig/conjecture.clj
@@ -701,33 +701,45 @@
;;; RUNNING TESTS: LOW-LEVEL FUNCTIONS
+(def ^:dynamic *once-fixtures* #{})
+(def ^:dynamic *each-fixtures* #{})
+
(defn test-var
"If v has a function in its :test metadata, calls that function,
with *testing-vars* bound to (conj *testing-vars* v)."
{:dynamic true, :added "1.1"}
[v]
- (when-let [t (:test (meta v))]
- (binding [*testing-vars* (conj *testing-vars* v)]
- (do-report {:type :begin-test-var, :var v})
- (inc-report-counter :test)
- (try (t)
- (catch Throwable e
- (do-report {:type :error,
- :message "Uncaught exception, not in assertion."
- :expected nil, :actual e})))
- (do-report {:type :end-test-var, :var v}))))
+ (let [ns (:ns (meta v))]
+ (when-let [t (:test (meta v))]
+ (if (contains? *once-fixtures* ns)
+ (if (contains? *each-fixtures* ns)
+ (binding [*testing-vars* (conj *testing-vars* v)]
+ (do-report {:type :begin-test-var, :var v})
+ (inc-report-counter :test)
+ (try (t)
+ (catch Throwable e
+ (do-report {:type :error,
+ :message "Uncaught exception, not in assertion."
+ :expected nil, :actual e})))
+ (do-report {:type :end-test-var, :var v}))
+ (let [each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))]
+ (binding [*each-fixtures* (conj *each-fixtures* ns)]
+ (each-fixture-fn (fn [] (test-var v))))))
+ (let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))]
+ (binding [*once-fixtures* (conj *once-fixtures* ns)]
+ (once-fixture-fn (fn [] (test-var v)))))))))
(defn test-all-vars
"Calls test-var on every var interned in the namespace, with fixtures."
{:added "1.1"}
[ns]
- (let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))
- each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))]
- (once-fixture-fn
- (fn []
- (doseq [v (vals (ns-interns ns))]
- (when (:test (meta v))
- (each-fixture-fn (fn [] (test-var v)))))))))
+ (if (contains? *once-fixtures* ns)
+ (doseq [v (vals (ns-interns ns))]
+ (when (:test (meta v))
+ (test-var v)))
+ (let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))]
+ (binding [*once-fixtures* (conj *once-fixtures* ns)]
+ (once-fixture-fn (fn [] (test-all-vars ns)))))))
(defn test-ns
"If the namespace defines a function named test-ns-hook, calls that.

0 comments on commit c24da58

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