Skip to content

Commit

Permalink
[Issue #82] fixing shrinking to happen at runtime not macroexpand time
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBaranosky committed Mar 11, 2012
2 parents 2a6db5c + 08e57ec commit b835d32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/midje/ideas/formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(defn shrink [& _args] [])

(defmacro shrink-failure-case [docstring binding-name failed-binding-val body]
`(loop [[cur-shrunk# & rest#] ~(midje.ideas.formulas/shrink failed-binding-val)] ;; (shrink (eval failed-binding-val)) ???
`(loop [[cur-shrunk# & rest#] (midje.ideas.formulas/shrink ~failed-binding-val)]
(when cur-shrunk#
(when (let [~binding-name cur-shrunk#]
(midje.sweet/fact ~docstring ;; duplicated
Expand Down Expand Up @@ -50,10 +50,11 @@
`(try
(loop [cnt-down# midje.ideas.formulas/*num-generations-per-formula*]
(when (pos? cnt-down#)
(let [~(first bindings) ~(second bindings)]
(let [ snd-binding# ~(second bindings)
~(first bindings) snd-binding#]
(if ~fact
(recur (dec cnt-down#))
(shrink-failure-case ~docstring? ~(first bindings) ~(second bindings) ~body)))))
(shrink-failure-case ~docstring? ~(first bindings) snd-binding# ~body)))))
(finally
~conclusion-signal)))))

Expand Down
4 changes: 2 additions & 2 deletions test/midje/ideas/t_formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
(after-silently
(formula [z (z-maker)]
(my-identity z) => "clearly not 'z'"))
(fact @z-maker-count => 1)
(fact @my-identity-count => 1)
(fact "calls generator once" @z-maker-count => 1)
(fact "evalautes body once" @my-identity-count => 1)

;; shrinks failure case to smallest possible failure
(with-redefs [midje.ideas.formulas/shrink (constantly [0 1 2 3 4 5])] ;; I don't think wtih-redefs is working right, hence the failures I'm seeing
Expand Down

0 comments on commit b835d32

Please sign in to comment.