Skip to content

Commit 129cec1

Browse files
authored
Merge pull request #437 from AlexChalk/expectations-fix
deep-diff clojure-expectations' `:actual (not=` output format
2 parents 0fef3a3 + ae6b1fe commit 129cec1

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- deep-diff `:actual (not=` output format.
4+
35
## Added
46

57
## Fixed

src/kaocha/report.clj

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,24 @@
238238
:actual '~form})
239239
(t/assert-predicate msg form)))
240240

241+
(defmulti sexpr-for-diff
242+
(fn [m] (first (:actual m))))
243+
244+
;; e.g. (not= ...)
245+
(defmethod sexpr-for-diff 'not= [m]
246+
(-> m :actual))
247+
248+
;; e.g. (not (= ...))
249+
(defmethod sexpr-for-diff :default [m]
250+
(-> m :actual second))
251+
241252
(defn print-expression [m]
242253
(let [printer (output/printer)]
243-
;; :actual is of the form (not (= ...))
244-
245254
(if (and (not= (:type m) ::one-arg-eql)
246-
(seq? (second (:actual m)))
247-
(> (count (second (:actual m))) 2))
255+
(seq? (sexpr-for-diff m))
256+
(> (count (sexpr-for-diff m)) 2))
248257

249-
(let [[_ expected & actuals] (-> m :actual second)]
258+
(let [[_ expected & actuals] (sexpr-for-diff m)]
250259
(output/print-doc
251260
[:span
252261
"Expected:" :line
@@ -422,7 +431,6 @@
422431
(t/with-test-out
423432
(prn (util/minimal-test-event m))))
424433

425-
426434
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
427435

428436
(def dots

test/unit/kaocha/report_test.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@
157157
(report/print-expr {:expected '(= 1 (+ 1 1))
158158
:actual '(not (= 1 2))})))))
159159

160+
(deftest print-expression-test
161+
(is (= "Expected:\n 1\nActual:\n -1 +2\n"
162+
(with-out-str
163+
(report/print-expression {:expected '(= 1 (+ 1 1))
164+
:actual '(not (= 1 2))}))))
165+
(is (= "Expected:\n 1\nActual:\n -1 +2\n"
166+
(with-out-str
167+
(report/print-expression {:expected '(= 1 (+ 1 1))
168+
:actual '(not= 1 2)})))))
160169
(deftest fail-summary-test
161170
(is (= (str "\n"
162171
"FAIL in foo/bar-test (foo.clj:42)\n"

0 commit comments

Comments
 (0)