|
1 | | -;; copyright (c) 2018-2020 sean corfield, all rights reserved |
| 1 | +;; copyright (c) 2018-2021 sean corfield, all rights reserved |
2 | 2 |
|
3 | 3 | (ns expectations.clojure.test |
4 | 4 | "This namespace provides compatibility with `clojure.test` and related tooling. |
|
297 | 297 |
|
298 | 298 | (and (sequential? a) (= 'in (first a))) |
299 | 299 | (let [form `(~'expect ~e ~a)] |
300 | | - `(let [a# ~(second a) |
| 300 | + `(let [e# ~e |
| 301 | + a# ~(second a) |
301 | 302 | not-in# (str '~e " not found in " a#) |
302 | 303 | msg# (if (seq ~msg') (str ~msg' "\n" not-in#) not-in#)] |
303 | | - (cond (or (sequential? a#) (set? a#)) |
| 304 | + (cond (and (set? a#) (set? e#)) |
| 305 | + ;; special case of set in set -- report any elements from |
| 306 | + ;; expected set that are not in the actual set: |
| 307 | + (t/is (~'=? (clojure.set/difference e# a#) #{} '~form) msg#) |
| 308 | + (or (sequential? a#) (set? a#)) |
304 | 309 | (let [all-reports# (atom nil) |
305 | 310 | one-report# (atom nil)] |
306 | 311 | ;; we accumulate any and all failures and errors but we |
307 | 312 | ;; only accumulate passes if each sequential expectation |
308 | 313 | ;; fully passes (i.e., no failures or errors) |
309 | 314 | (with-redefs [t/do-report (all-report one-report#)] |
310 | 315 | (doseq [a'# a#] |
311 | | - (expect ~e a'# msg# ~ex? ~form) |
| 316 | + (expect e# a'# msg# ~ex? ~form) |
312 | 317 | (if (or (contains? @one-report# :error) |
313 | 318 | (contains? @one-report# :fail)) |
314 | 319 | (do |
|
332 | 337 | (when-let [r# (first (:fail @all-reports#))] |
333 | 338 | (t/do-report r#))))) |
334 | 339 | (map? a#) |
335 | | - (let [e# ~e] |
336 | | - (if (map? e#) |
337 | | - (let [submap# (select-keys a# (keys e#))] |
338 | | - (t/is (~'=? e# submap# '~form) ~msg')) |
339 | | - (throw (#?(:clj IllegalArgumentException. |
340 | | - :cljs js/Error.) |
341 | | - "'in' requires map or sequence")))) |
| 340 | + (if (map? e#) |
| 341 | + (let [submap# (select-keys a# (keys e#))] |
| 342 | + (t/is (~'=? e# submap# '~form) ~msg')) |
| 343 | + (throw (#?(:clj IllegalArgumentException. |
| 344 | + :cljs js/Error.) |
| 345 | + "'in' requires map or sequence"))) |
342 | 346 | :else |
343 | 347 | (throw (#?(:clj IllegalArgumentException. |
344 | 348 | :cljs js/Error.) |
345 | | - "'in' requires map or sequence"))))) |
| 349 | + "'in' requires map or sequence"))))) |
346 | 350 |
|
347 | 351 | (and (sequential? e) (= 'more (first e))) |
348 | 352 | (let [es (mapv (fn [e] `(expect ~e ~a ~msg ~ex? ~e')) (rest e))] |
|
0 commit comments