Skip to content

Commit

Permalink
Refine =-body behavior
Browse files Browse the repository at this point in the history
* Unwrap lists for :actual for `=` arity 2
* Use traditional clojure.test notation for `=` arity 3+

Fixes #735
  • Loading branch information
vemv committed Dec 10, 2021
1 parent 44792e9 commit b3a5383
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bugs fixed

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

## 0.27.3 (2021-12-07)
Expand Down
8 changes: 7 additions & 1 deletion src/cider/nrepl/middleware/test/extensions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
(map #(vector % (data/diff expected# %))))})
(merge {:message ~msg
:expected expected#
:actual more#})
:actual
(if (= 1 (count more#))
;; most times,` more` has a count of 1. For this case, we unwrap `more`,
;; which has been the traditional behavior of this feature:
(first more#)
;; if `more` has 2+ arguments, our :actual will closely resemble clojure.test's own:
(list ~''not (apply list ~(list 'quote '=) expected# more#)))})
test/do-report)
result#)
`(throw (Exception. "= expects more than one argument"))))
Expand Down
16 changes: 14 additions & 2 deletions test/clj/cider/nrepl/middleware/test/extensions_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns cider.nrepl.middleware.test.extensions-test
(:require
[cider.nrepl.middleware.test.extensions :as extensions]
[clojure.test :refer :all]))
[clojure.test :refer [are deftest is testing]]))

(deftest =-body-test
(testing "Only evalulates expected form once"
Expand All @@ -20,4 +20,16 @@
(- (swap! a inc) 6)
(- (swap! a inc) 7)
(- (swap! a inc) 8)
(- (swap! a inc) 9))))))
(- (swap! a inc) 9)))))
(testing ":actual is a scalar for (= x y) (i.e. arity 2)
and an informative list for (= x y z) (i.e. arity 3+)"
(are [subject args expected] (= expected
(let [proof (atom nil)]
(with-redefs [clojure.test/do-report
(fn [m]
(reset! proof m))]
(eval (extensions/=-body "_" subject args))
@proof)))
1 [1] '{:expected 1, :actual 1, :message "_", :type :pass}
1 [2] '{:expected 1, :actual 2, :message "_", :type :fail, :diffs ([2 [1 2 nil]])}
1 [2 3] '{:expected 1, :actual (not (= 1 2 3)), :message "_", :type :fail, :diffs ([2 [1 2 nil]] [3 [1 3 nil]])})))

0 comments on commit b3a5383

Please sign in to comment.