diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-11-02 10:41:23 -0500 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-11-02 10:41:23 -0500 |
commit | 7e11a5525bc35083ebdf53484cbdfb76755b252f (patch) | |
tree | 1ae708f568b1e152fda21df2c4460e0313c18c6b /src | |
parent | e0080e640a2d9b79564a3fb6eb7ee36be1882901 (diff) |
test-is: don't compose fixtures forever; fixes #36
This is the same as Clojure ticket #194, same changes applied.
clojure.contrib.test-is/use-fixtures would compose fixtures repeatedly
when called multiple times.
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/contrib/test_contrib/test_is_fixtures.clj | 11 | ||||
-rw-r--r-- | src/clojure/contrib/test_is.clj | 10 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/clojure/contrib/test_contrib/test_is_fixtures.clj b/src/clojure/contrib/test_contrib/test_is_fixtures.clj index 218c45d5..4b723235 100644 --- a/src/clojure/contrib/test_contrib/test_is_fixtures.clj +++ b/src/clojure/contrib/test_contrib/test_is_fixtures.clj @@ -17,6 +17,8 @@ (declare *a* *b* *c* *d*) +(def *n* 0) + (defn fixture-a [f] (binding [*a* 3] (f))) @@ -29,9 +31,13 @@ (defn fixture-d [f] (binding [*d* 11] (f))) +(defn inc-n-fixture [f] + (binding [*n* (inc *n*)] (f))) + (use-fixtures :once fixture-a fixture-b) -(use-fixtures :each fixture-c fixture-d) +(use-fixtures :each fixture-c fixture-d inc-n-fixture) +(use-fixtures :each fixture-c fixture-d inc-n-fixture) (deftest can-use-once-fixtures (is (= 3 *a*)) @@ -40,3 +46,6 @@ (deftest can-use-each-fixtures (is (= 7 *c*)) (is (= 11 *d*))) + +(deftest use-fixtures-replaces + (is (= *n* 1))) diff --git a/src/clojure/contrib/test_is.clj b/src/clojure/contrib/test_is.clj index 7175fa2a..dcfb0564 100644 --- a/src/clojure/contrib/test_is.clj +++ b/src/clojure/contrib/test_is.clj @@ -505,7 +505,7 @@ Chas Emerick, Allen Rohner, and Stuart Halloway", "Returns a vector [filename line-number] for the nth call up the stack." [n] - (let [s (nth (.getStackTrace (new java.lang.Throwable)) n)] + (let [#^StackTraceElement s (nth (.getStackTrace (new java.lang.Throwable)) n)] [(.getFileName s) (.getLineNumber s)])) (defn testing-vars-str @@ -825,9 +825,13 @@ Chas Emerick, Allen Rohner, and Stuart Halloway", "Adds elements in coll to the current namespace metadata as the value of key." [key coll] - (alter-meta! *ns* assoc key (concat (key (meta *ns*)) coll))) + (alter-meta! *ns* assoc key coll)) -(defmulti use-fixtures (fn [fixture-type & args] fixture-type)) +(defmulti use-fixtures + "Wrap test runs in a fixture function to perform setup and + teardown. Using a fixture-type of :each wraps every test + individually, while:once wraps the whole run in a single function." + (fn [fixture-type & args] fixture-type)) (defmethod use-fixtures :each [fixture-type & args] (add-ns-meta ::each-fixtures args)) |