Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix example script on Linux, simplify reporting

  • Loading branch information...
commit fd27a671815b06b5409b8c59a5645c89f35c31ce 1 parent b135023
Stuart Halloway authored
2  script/examples
@@ -2,6 +2,6 @@
2 2 # Note: First you must run mvn dependency:build-classpath -Dmdep.outputFile=script/maven-classpath
3 3 CLASSPATH=src/main/clojure:src/test/clojure:src/examples/clojure:`cat script/maven-classpath`
4 4
5   -java -server -Xmx2GB -cp $CLASSPATH clojure.main -i script/examples.clj
  5 +java -server -Xmx2G -cp $CLASSPATH clojure.main -i script/examples.clj
6 6
7 7
36 src/main/clojure/clojure/test/generative.clj
@@ -109,16 +109,12 @@ the error message, and the random seed.
109 109 :seed 42,
110 110 :error \"Assert failed: (pos? l)\"}
111 111
112   -At this point, if you are in a REPL, you can rerun the failing test:
113   -
114   - (eval (-> (failed-forms) first :form))
115   -
116 112 Note the :seed value in the error output above. The *rnd* and *seed*
117 113 values live in the clojure.test.generative.generators namespace, and
118 114 can be used to conrol the randomization used to generate test data.
119 115 This can be useful in generating reproducible inputs.
120 116
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
122 118 input to the same fn twice in a single test run. If the test data
123 119 generator cannot generate enough unique values to drive the test for
124 120 the expected msec duration, it will stop when it runs out of values,
@@ -149,12 +145,19 @@ one of the built-in generators:
149 145
150 146 (def last-report (agent nil))
151 147
  148 +(def report-fn
  149 + "Reporting function, defaults to prn.
  150 + reset! val to customize reporting."
  151 + (atom prn))
  152 +
152 153 (defn report
153 154 "Report a result. Thread-safe, unlike prn."
154 155 [result]
155 156 (send-off last-report
156 157 (fn [_]
157   - (prn result)
  158 + (try
  159 + (@report-fn result)
  160 + (catch Exception e (.printStackTrace e)))
158 161 result)))
159 162
160 163 (defn- deep-take
@@ -254,13 +257,6 @@ one of the built-in generators:
254 257 gens)))
255 258 (constantly nil))))
256 259
257   -(def ^:private failures-ref
258   - (atom nil))
259   -
260   -(defn failures
261   - []
262   - @failures-ref)
263   -
264 260 (defn run-test
265 261 "Tests function f with generator gen for up to msec
266 262 milliseconds. Returns a map of :msec and :iterations completed"
@@ -281,13 +277,13 @@ one of the built-in generators:
281 277 (when verbose (report {:inputs args}))
282 278 (apply f args)
283 279 (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))
291 287 (throw t)))
292 288 (recur (inc count) more)))))))
293 289

0 comments on commit fd27a67

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