Created
December 10, 2015 13:32
-
-
Save minimal/60453b250cacb306701c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns player-ladder.test-util | |
(:require [clojure.data :as data] | |
[clojure.pprint :as pp] | |
[clojure.string :as str] | |
[clojure.test :refer :all])) | |
(defn diff->string [diffs] | |
(str/join | |
(for [[actual [a b]] diffs | |
:when (or a b)] | |
(str | |
(if a | |
(str "- " | |
(with-out-str (pp/pprint a)) | |
" + ") | |
"+ ") | |
(if b (with-out-str (pp/pprint b))))))) | |
(defn diff-map [diffs [m & ms :as more]] | |
{:diffstrs diffs :actual (if ms more m)}) | |
(remove-method clojure.test/assert-expr '=) | |
(remove-method clojure.test/assert-expr 'clojure.core/=) | |
(defn assert-= [msg a more] | |
(let [test-str (str (list '= a (first more)))] | |
`(let [a# ~a] | |
(if-let [more# (seq (list ~@more))] | |
(let [result# (apply = a# more#) | |
diffs# (map vector | |
more# | |
(map #(take 2 (data/diff a# %)) | |
more#)) | |
diff-str# (diff->string diffs#)] | |
(if result# | |
(do-report {:type :pass, :message ~msg, | |
:expected a#, :actual more#}) | |
(do-report (merge {:type :fail, :message ~msg, | |
:expected a#, :actual more#, | |
:test-form ~test-str | |
:diffs diffs#} | |
(diff-map diff-str# more#)))) | |
result#) | |
(throw (Exception. "= expects more than one argument")))))) | |
(defmethod clojure.test/assert-expr '= [msg [_ a & more]] | |
(assert-= msg a more)) | |
(defmethod clojure.test/assert-expr 'clojure.core/= [msg [_ a & more]] | |
(assert-= msg a more)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment