Skip to content

Commit

Permalink
fixes #39 by ignoring qualifiers when checking nested calls
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Corfield <[email protected]>
  • Loading branch information
seancorfield committed Nov 21, 2024
1 parent 9fea734 commit b90ed5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Only accretive/fixative changes will be made from now on.

* 2.1.next in progress
* Address [#39](https://github.com/clojure-expectations/clojure-test/issues/39) by ignoring qualifier on Expectations' macros. This is potentially breaking but is required for migration (to LazyTest, for example).
* Address [#36](https://github.com/clojure-expectations/clojure-test/issues/36) by expanding `side-effects` documentation, and mentioning `with-redefs`.
* Expose `run-test` and `run-test-var` from `clojure.test` (Clojure 1.11).
* Update dev/test dependencies.
Expand Down
24 changes: 18 additions & 6 deletions src/expectations/clojure/test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@
([e a] `(expect ~e ~a nil true ~e))
([e a msg] `(expect ~e ~a ~msg true ~e))
([e a msg ex? e']
(let [within (if (and (sequential? e') (= 'expect (first e')))
(let [within (if (and (sequential? e')
(symbol? (first e'))
(= "expect" (name (first e'))))
`(pr-str '~e')
`(pr-str (list '~'expect '~e' '~a)))
msg' `(str/join
Expand All @@ -313,15 +315,19 @@
:else
(conj (str (pr-str '~a) "\n"))))]
(cond
(and (sequential? a) (= 'from-each (first a)))
(and (sequential? a)
(symbol? (first a))
(= "from-each" (name (first a))))
(let [[_ bindings & body] a]
(if (= 1 (count body))
`(doseq ~bindings
(expect ~e ~(first body) ~msg ~ex? ~e))
`(doseq ~bindings
(expect ~e (do ~@body) ~msg ~ex? ~e))))

(and (sequential? a) (= 'in (first a)))
(and (sequential? a)
(symbol? (first a))
(= "in" (name (first a))))
(let [form `(~'expect ~e ~a)]
`(let [e# ~e
a# ~(second a)
Expand Down Expand Up @@ -370,12 +376,16 @@
:else
(throw (illegal-argument "'in' requires map or sequence")))))

(and (sequential? e) (= 'more (first e)))
(and (sequential? e)
(symbol? (first e))
(= "more" (name (first e))))
(let [sa (gensym)
es (mapv (fn [e] `(expect ~e ~sa ~msg ~ex? ~e')) (rest e))]
`(let [~sa (? ~a)] ~@es))

(and (sequential? e) (= 'more-> (first e)))
(and (sequential? e)
(symbol? (first e))
(= "more->" (name (first e))))
(let [sa (gensym)
es (mapv (fn [[e a->]]
(if (and (sequential? a->)
Expand All @@ -388,7 +398,9 @@
(partition 2 (rest e)))]
`(let [~sa (? ~a)] ~@es))

(and (sequential? e) (= 'more-of (first e)))
(and (sequential? e)
(symbol? (first e))
(= "more-of" (name (first e))))
(let [es (mapv (fn [[e a]] `(expect ~e ~a ~msg ~ex? ~e'))
(partition 2 (rest (rest e))))]
`(let [~(second e) ~a] ~@es))
Expand Down

0 comments on commit b90ed5b

Please sign in to comment.