Skip to content

Commit fd27a67

Browse files
author
Stuart Halloway
committed
fix example script on Linux, simplify reporting
1 parent b135023 commit fd27a67

2 files changed

Lines changed: 17 additions & 21 deletions

File tree

script/examples

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Note: First you must run mvn dependency:build-classpath -Dmdep.outputFile=script/maven-classpath
33
CLASSPATH=src/main/clojure:src/test/clojure:src/examples/clojure:`cat script/maven-classpath`
44

5-
java -server -Xmx2GB -cp $CLASSPATH clojure.main -i script/examples.clj
5+
java -server -Xmx2G -cp $CLASSPATH clojure.main -i script/examples.clj
66

77

src/main/clojure/clojure/test/generative.clj

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
116112
Note the :seed value in the error output above. The *rnd* and *seed*
117113
values live in the clojure.test.generative.generators namespace, and
118114
can be used to conrol the randomization used to generate test data.
119115
This 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
122118
input to the same fn twice in a single test run. If the test data
123119
generator cannot generate enough unique values to drive the test for
124120
the 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

Comments
 (0)