Skip to content

Commit b3a5383

Browse files
committed
Refine =-body behavior
* Unwrap lists for :actual for `=` arity 2 * Use traditional clojure.test notation for `=` arity 3+ Fixes #735
1 parent 44792e9 commit b3a5383

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Bugs fixed
66

7+
* [#735](https://github.com/clojure-emacs/cider-nrepl/issues/735): `middleware.test.extensions`: make `:actual` reporting clearer.
78
* [#737](https://github.com/clojure-emacs/cider-nrepl/pull/737): Fix a regression in `middleware.out` that could result in duplicate output.
89

910
## 0.27.3 (2021-12-07)

src/cider/nrepl/middleware/test/extensions.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
(map #(vector % (data/diff expected# %))))})
2424
(merge {:message ~msg
2525
:expected expected#
26-
:actual more#})
26+
:actual
27+
(if (= 1 (count more#))
28+
;; most times,` more` has a count of 1. For this case, we unwrap `more`,
29+
;; which has been the traditional behavior of this feature:
30+
(first more#)
31+
;; if `more` has 2+ arguments, our :actual will closely resemble clojure.test's own:
32+
(list ~''not (apply list ~(list 'quote '=) expected# more#)))})
2733
test/do-report)
2834
result#)
2935
`(throw (Exception. "= expects more than one argument"))))

test/clj/cider/nrepl/middleware/test/extensions_test.clj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns cider.nrepl.middleware.test.extensions-test
22
(:require
33
[cider.nrepl.middleware.test.extensions :as extensions]
4-
[clojure.test :refer :all]))
4+
[clojure.test :refer [are deftest is testing]]))
55

66
(deftest =-body-test
77
(testing "Only evalulates expected form once"
@@ -20,4 +20,16 @@
2020
(- (swap! a inc) 6)
2121
(- (swap! a inc) 7)
2222
(- (swap! a inc) 8)
23-
(- (swap! a inc) 9))))))
23+
(- (swap! a inc) 9)))))
24+
(testing ":actual is a scalar for (= x y) (i.e. arity 2)
25+
and an informative list for (= x y z) (i.e. arity 3+)"
26+
(are [subject args expected] (= expected
27+
(let [proof (atom nil)]
28+
(with-redefs [clojure.test/do-report
29+
(fn [m]
30+
(reset! proof m))]
31+
(eval (extensions/=-body "_" subject args))
32+
@proof)))
33+
1 [1] '{:expected 1, :actual 1, :message "_", :type :pass}
34+
1 [2] '{:expected 1, :actual 2, :message "_", :type :fail, :diffs ([2 [1 2 nil]])}
35+
1 [2 3] '{:expected 1, :actual (not (= 1 2 3)), :message "_", :type :fail, :diffs ([2 [1 2 nil]] [3 [1 3 nil]])})))

0 commit comments

Comments
 (0)