@@ -109,16 +109,12 @@ the error message, and the random seed.
109109 :seed 42,
110110 :error \" Assert failed: (pos? l)\" }
111111
112- At this point, if you are in a REPL, you can rerun the failing test:
113-
114- (eval (-> (failed-forms) first :form))
115-
116112Note the :seed value in the error output above. The *rnd* and *seed*
117113values live in the clojure.test.generative.generators namespace, and
118114can be used to conrol the randomization used to generate test data.
119115This can be useful in generating reproducible inputs.
120116
121- The test runner tracks old inputs, and will not submit the same
117+ The test runner tracks old inputs, and tries not to submit the same
122118input to the same fn twice in a single test run. If the test data
123119generator cannot generate enough unique values to drive the test for
124120the expected msec duration, it will stop when it runs out of values,
@@ -149,12 +145,19 @@ one of the built-in generators:
149145
150146(def last-report (agent nil ))
151147
148+ (def report-fn
149+ " Reporting function, defaults to prn.
150+ reset! val to customize reporting."
151+ (atom prn))
152+
152153(defn report
153154 " Report a result. Thread-safe, unlike prn."
154155 [result]
155156 (send-off last-report
156157 (fn [_]
157- (prn result)
158+ (try
159+ (@report-fn result)
160+ (catch Exception e (.printStackTrace e)))
158161 result)))
159162
160163(defn- deep-take
@@ -254,13 +257,6 @@ one of the built-in generators:
254257 gens)))
255258 (constantly nil ))))
256259
257- (def ^:private failures-ref
258- (atom nil ))
259-
260- (defn failures
261- []
262- @failures-ref )
263-
264260(defn run-test
265261 " Tests function f with generator gen for up to msec
266262 milliseconds. Returns a map of :msec and :iterations completed"
@@ -281,13 +277,13 @@ one of the built-in generators:
281277 (when verbose (report {:inputs args}))
282278 (apply f args)
283279 (catch Throwable t
284- (let [failed-form `(~fname ~@args)]
285- ( report {:form failed-form
286- :iteration count
287- :seed gen/*seed*
288- :error (.getMessage t)
289- :exception t})
290- (swap! failures-ref conj { :form failed-form} ))
280+ (let [failed-form `(~fname ~@args)
281+ failure {:form failed-form
282+ :iteration count
283+ :seed gen/*seed*
284+ :error (.getMessage t)
285+ :exception t}]
286+ (report failure ))
291287 (throw t)))
292288 (recur (inc count) more)))))))
293289
0 commit comments