Skip to content

Commit

Permalink
[Issue #82] dynamic binding of *num-generations-per-formula* works again
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBaranosky committed Mar 11, 2012
1 parent 6071991 commit 2a6db5c
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/midje/ideas/formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
~@body :formula :formula-in-progress))
(recur rest#)))))

(defmacro the-loop [cnt-down fact docstring? bindings body]
(if (pos? cnt-down)
`(let [value# ~(second bindings)]
(let [~(first bindings) value#]
(if ~fact
(the-loop ~(dec cnt-down) ~fact ~docstring? ~bindings ~body)
(shrink-failure-case ~docstring? ~(first bindings) value# ~body))))
`(do nil)))

(defmacro formula
"ALPHA/EXPERIMENTAL - Generative-style fact macro.
Expand All @@ -57,7 +48,12 @@
:always-pass midje.sweet/=> :always-pass :formula :formula-conclude )]

`(try
(the-loop ~*num-generations-per-formula* ~fact ~docstring? ~bindings ~body)
(loop [cnt-down# midje.ideas.formulas/*num-generations-per-formula*]
(when (pos? cnt-down#)
(let [~(first bindings) ~(second bindings)]
(if ~fact
(recur (dec cnt-down#))
(shrink-failure-case ~docstring? ~(first bindings) ~(second bindings) ~body)))))
(finally
~conclusion-signal)))))

Expand Down

0 comments on commit 2a6db5c

Please sign in to comment.