Skip to content

Commit

Permalink
Fixed #211 - against-background check counts future-fact
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed May 4, 2013
1 parent 971f045 commit c60f0d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/midje/parsing/1_to_explicit_form/background.clj
Expand Up @@ -201,9 +201,17 @@

(def against-background-forms-without-enclosed-facts (atom []))

(defn note-new-nesting-level! []
(swap! against-background-forms-without-enclosed-facts #(cons :any-old-value %)))
(defn decrease-nesting-level! []
(swap! against-background-forms-without-enclosed-facts rest))
(defn note-fact! []
(reset! against-background-forms-without-enclosed-facts []))


(defmacro expecting-nested-facts [form & body]
`(try
(swap! against-background-forms-without-enclosed-facts #(cons 'token %))
(note-new-nesting-level!)
(let [result# ~@body]
(when-not (empty? @against-background-forms-without-enclosed-facts)
(error/report-error ~form
Expand All @@ -224,7 +232,5 @@
" (against-background (f 1) => 1)) "))
result#)
(finally
(swap! against-background-forms-without-enclosed-facts rest))))
(decrease-nesting-level!))))

(defn note-fact! []
(reset! against-background-forms-without-enclosed-facts []))
2 changes: 2 additions & 0 deletions src/midje/parsing/1_to_explicit_form/future_facts.clj
Expand Up @@ -5,11 +5,13 @@
[midje.parsing.util.file-position :as position]
[midje.data.nested-facts :as nested-facts]
[midje.parsing.1-to-explicit-form.metadata :as parse-metadata]
[midje.parsing.1-to-explicit-form.background :as background]
[midje.emission.api :as emit]))

(defn parse [form]
(let [lineno (reader-line-number form)
[metadata _] (parse-metadata/separate-metadata form)]
(background/note-fact!)
`(emit/future-fact (nested-facts/descriptions ~(:midje/description metadata))
(position/line-number-known ~lineno))))

Expand Down
11 changes: 8 additions & 3 deletions test/user/fus_parse_errors.clj
Expand Up @@ -202,11 +202,16 @@
(fact
@fact-output => #"\(first thing\) does not look like"))

(silent-fact "It also complains if there are no facts nested inside it"
(against-background [(f 1) => 1]
(inc (f 1)) => 2))
(silent-fact "It also complains if there are no facts nested inside it"
(against-background [(f 1) => 1]
(inc (f 1)) => 2))
(note-that parse-error-found (fact-failed-with-note #"against-background.*only affect nested facts"))

(fact "Nested future-facts do not trigger the complaint"
(macroexpand-1 '(against-background [(f 1) => 1] (future-fact (+ 1 1) => 3))))



;; It would be nice if it didn't complain about outer-level against-backgrounds
;; with nothing inside them, but that's more trouble than it's worth.

Expand Down

0 comments on commit c60f0d8

Please sign in to comment.