Skip to content

Commit

Permalink
Merge pull request #437 from AlexChalk/expectations-fix
Browse files Browse the repository at this point in the history
deep-diff clojure-expectations' `:actual (not=` output format
  • Loading branch information
plexus authored May 23, 2024
2 parents 0fef3a3 + ae6b1fe commit 129cec1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- deep-diff `:actual (not=` output format.

## Added

## Fixed
Expand Down
20 changes: 14 additions & 6 deletions src/kaocha/report.clj
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,24 @@
:actual '~form})
(t/assert-predicate msg form)))

(defmulti sexpr-for-diff
(fn [m] (first (:actual m))))

;; e.g. (not= ...)
(defmethod sexpr-for-diff 'not= [m]
(-> m :actual))

;; e.g. (not (= ...))
(defmethod sexpr-for-diff :default [m]
(-> m :actual second))

(defn print-expression [m]
(let [printer (output/printer)]
;; :actual is of the form (not (= ...))

(if (and (not= (:type m) ::one-arg-eql)
(seq? (second (:actual m)))
(> (count (second (:actual m))) 2))
(seq? (sexpr-for-diff m))
(> (count (sexpr-for-diff m)) 2))

(let [[_ expected & actuals] (-> m :actual second)]
(let [[_ expected & actuals] (sexpr-for-diff m)]
(output/print-doc
[:span
"Expected:" :line
Expand Down Expand Up @@ -422,7 +431,6 @@
(t/with-test-out
(prn (util/minimal-test-event m))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(def dots
Expand Down
9 changes: 9 additions & 0 deletions test/unit/kaocha/report_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@
(report/print-expr {:expected '(= 1 (+ 1 1))
:actual '(not (= 1 2))})))))

(deftest print-expression-test
(is (= "Expected:\n 1\nActual:\n -1 +2\n"
(with-out-str
(report/print-expression {:expected '(= 1 (+ 1 1))
:actual '(not (= 1 2))}))))
(is (= "Expected:\n 1\nActual:\n -1 +2\n"
(with-out-str
(report/print-expression {:expected '(= 1 (+ 1 1))
:actual '(not= 1 2)})))))
(deftest fail-summary-test
(is (= (str "\n"
"FAIL in foo/bar-test (foo.clj:42)\n"
Expand Down

0 comments on commit 129cec1

Please sign in to comment.