From b90ed5b24924238b3b16b0bbaaee4c3b05a1268a Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Wed, 20 Nov 2024 23:38:02 -0800 Subject: [PATCH] fixes #39 by ignoring qualifiers when checking nested calls Signed-off-by: Sean Corfield --- CHANGELOG.md | 1 + src/expectations/clojure/test.cljc | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31a6a18..5df4c4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/expectations/clojure/test.cljc b/src/expectations/clojure/test.cljc index dd85408..e946058 100644 --- a/src/expectations/clojure/test.cljc +++ b/src/expectations/clojure/test.cljc @@ -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 @@ -313,7 +315,9 @@ :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 @@ -321,7 +325,9 @@ `(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) @@ -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->) @@ -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))