Skip to content

Instantly share code, notes, and snippets.

@devn
Created November 21, 2011 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devn/1381725 to your computer and use it in GitHub Desktop.
Save devn/1381725 to your computer and use it in GitHub Desktop.
Cannot recur across try
(defn property*
"The property* driver handles the work when testing a property. It
expects:
* a descriptive message for failure reporting
* a list of locals (also for reporting)
* a generator which takes the scaled size and returns the input
for the property
* the property test in form of a function of the generated
input."
{:added "2.0"}
[msg locals gen prop]
(let [results (atom [])
report-fn #(swap! results conj %)]
(loop [n 1]
(reset! results [])
(if (< trials n)
(report {:type :pass})
(let [input (-> n size-scale gen)]
(try
(binding [report report-fn]
(prop input))
(let [failures (filter #(-> % :type (not= :pass)) @results)]
(if (seq failures)
(report {:type ::property-fail
:message msg
:locals locals
:input input
:attempts n
:failures failures})
(recur (inc n))))
(catch Throwable t
(report {:type ::property-error
:message msg
:locals locals
:input input
:attempt n
:error t}))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment