lambdaisland

plexus 2023-06-08T16:16:14.341879Z

@itai The thing to realize is that ddiff/pretty-print does actually printing, whereas you seem to be expecting that it returns a string. That's a bit more involved, something like this:

(ns repl-sessions.poke
  (:require
   [lambdaisland.deep-diff2.puget.printer :as ddiff-printer]
   [lambdaisland.deep-diff2.printer-impl :as ddiff-printer-impl]
   [lambdaisland.deep-diff2 :as ddiff]
   [clojure.test :refer :all]))

(defn ddiff->str [expected actual]
  (ddiff-printer/render-str
   (ddiff/printer)
   (ddiff/minimize (ddiff/diff expected actual))))

plexus 2023-06-08T16:16:35.324289Z

now you can do

(let [expected {:a 1 :b 2 :c 3}
      actual {:a 1 :b 2 :c 4}]
  (is (submap? expected actual)
      (ddiff->str expected actual)))

plexus 2023-06-08T16:17:05.163339Z

or (this is getting close to dark arts), you can override how clojure.test handles the 'submap? predicate

plexus 2023-06-08T16:17:22.652869Z

(defmethod clojure.test/assert-expr 'submap? [msg form]
  (let [[_ expected actual] form]
    `(let [exp# ~expected
           act# ~actual]
       (if (submap? exp# act#)
         (do-report {:type :pass, :message ~msg,
                     :expected '~form, :actual (cons 'submap? exp# act#)})
         (do-report {:type :fail, :message (ddiff->str exp# act#)
                     :expected '~form, :actual (list '~'not (list '~'submap? exp# act#))})))))

plexus 2023-06-08T16:17:37.278429Z

Now if you use (is (submap? ...)) it'll automatically print the diff

plexus 2023-06-08T16:17:50.884559Z

(let [expected {:a 1 :b 2 :c 3}
      actual {:a 1 :b 2 :c 4}]
  (is (submap? expected actual)))

plexus 2023-06-08T16:18:23.924809Z

plexus 2023-06-08T16:20:30.087109Z

but like @lee said matcher-combinators is the way to go. You should be able to add :diff-style :minimal to your kaocha config in order to reduce the diff size.