Created
November 21, 2011 05:24
-
-
Save devn/1381725 to your computer and use it in GitHub Desktop.
Cannot recur across try
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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