From fd27a671815b06b5409b8c59a5645c89f35c31ce Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Tue, 3 Jan 2012 22:33:30 -0500 Subject: [PATCH] fix example script on Linux, simplify reporting --- script/examples | 2 +- src/main/clojure/clojure/test/generative.clj | 36 +++++++++----------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/script/examples b/script/examples index 0ea2e7a..63257c7 100755 --- a/script/examples +++ b/script/examples @@ -2,6 +2,6 @@ # Note: First you must run mvn dependency:build-classpath -Dmdep.outputFile=script/maven-classpath CLASSPATH=src/main/clojure:src/test/clojure:src/examples/clojure:`cat script/maven-classpath` -java -server -Xmx2GB -cp $CLASSPATH clojure.main -i script/examples.clj +java -server -Xmx2G -cp $CLASSPATH clojure.main -i script/examples.clj diff --git a/src/main/clojure/clojure/test/generative.clj b/src/main/clojure/clojure/test/generative.clj index 90fbc42..6d025f8 100644 --- a/src/main/clojure/clojure/test/generative.clj +++ b/src/main/clojure/clojure/test/generative.clj @@ -109,16 +109,12 @@ the error message, and the random seed. :seed 42, :error \"Assert failed: (pos? l)\"} -At this point, if you are in a REPL, you can rerun the failing test: - - (eval (-> (failed-forms) first :form)) - Note the :seed value in the error output above. The *rnd* and *seed* values live in the clojure.test.generative.generators namespace, and can be used to conrol the randomization used to generate test data. This can be useful in generating reproducible inputs. -The test runner tracks old inputs, and will not submit the same +The test runner tracks old inputs, and tries not to submit the same input to the same fn twice in a single test run. If the test data generator cannot generate enough unique values to drive the test for the expected msec duration, it will stop when it runs out of values, @@ -149,12 +145,19 @@ one of the built-in generators: (def last-report (agent nil)) +(def report-fn + "Reporting function, defaults to prn. + reset! val to customize reporting." + (atom prn)) + (defn report "Report a result. Thread-safe, unlike prn." [result] (send-off last-report (fn [_] - (prn result) + (try + (@report-fn result) + (catch Exception e (.printStackTrace e))) result))) (defn- deep-take @@ -254,13 +257,6 @@ one of the built-in generators: gens))) (constantly nil)))) -(def ^:private failures-ref - (atom nil)) - -(defn failures - [] - @failures-ref) - (defn run-test "Tests function f with generator gen for up to msec milliseconds. Returns a map of :msec and :iterations completed" @@ -281,13 +277,13 @@ one of the built-in generators: (when verbose (report {:inputs args})) (apply f args) (catch Throwable t - (let [failed-form `(~fname ~@args)] - (report {:form failed-form - :iteration count - :seed gen/*seed* - :error (.getMessage t) - :exception t}) - (swap! failures-ref conj {:form failed-form})) + (let [failed-form `(~fname ~@args) + failure {:form failed-form + :iteration count + :seed gen/*seed* + :error (.getMessage t) + :exception t}] + (report failure)) (throw t))) (recur (inc count) more)))))))