matcher-combinators

respatialized 2026-02-10T01:59:51.938439Z

What's the easiest way to customize the mismatch message? Can I take the actual value and pass it to a function that transforms it into a custom mismatch message - similar to m/with but for reporting rather than matching?

Phillip Mates 2026-02-10T09:24:49.656809Z

At the moment I there isn't an API exposed to configure such things. Is this for clojure.test usage? I recently did a few tweaks to matcher-combinators.standalone that might serve as an example if you want to hack your own reporting https://github.com/nubank/matcher-combinators/pull/231 There is also matcher-combinators.matchers/via that, depending on your use case, could potentially fit(?)

(is (match? {:payloads [(m/via read-string {:foo :bar})]}
            {:payloads ["{:foo :bar :baz :qux}"]})))
I might be able to help more with a concrete example

Phillip Mates 2026-02-10T09:41:27.406659Z

if you want to play around with manipulating the actual in clojure.test without any changes to the lib you can redef matcher-combinators.clj-test/tagged-for-pretty-printing which is called on the actual value

(def original-tagged-for-pretty-printing matcher-combinators.clj-test/tagged-for-pretty-printing)
(with-redefs [matcher-combinators.clj-test/tagged-for-pretty-printing (fn [summary mismatch-result]
                                                                       (prn "override happened")
                                                                       (def mismatch-result mismatch-result) ;; save for inspection
                                                                       ;; invoke original so that clojure.core/print-method gets invoked correctly
                                                                       (original-tagged-for-pretty-printing summary mismatch-result))]
  (testing "redef reporting of `:actual` value in clojure.test"
    (is (match? {:payloads [{:foo :squid}]}
                {:payloads [{:foo :bar :baz :qux}]}))))

Phillip Mates 2026-02-10T09:43:15.287489Z

if you try that and it ends up being useful to you, I can look into making it possible to register a custom function to call in such places that can be set either globally via matcher-combinators.config or locally via with-redefs (in a less hacky/indirect way as the example above)