diff --git a/src/pjstadig/humane_test_output.clj b/src/pjstadig/humane_test_output.clj index 3e38e9f..d086e66 100644 --- a/src/pjstadig/humane_test_output.clj +++ b/src/pjstadig/humane_test_output.clj @@ -3,24 +3,30 @@ (:require [clojure.data :as data] [clojure.pprint :as pp])) +(defn =-body + [msg a more] + `(let [a# ~a] + (if-let [more# (seq (list ~@more))] + (let [result# (apply = a# more#)] + (if result# + (do-report {:type :pass, :message ~msg, + :expected a#, :actual more#}) + (do-report {:type :fail, :message ~msg, + :expected a#, :actual more#, + :diffs (map vector + more# + (map #(take 2 (data/diff a# %)) + more#))})) + result#) + (throw (Exception. "= expects more than one argument"))))) + (defonce activation-body (delay (when (not (System/getenv "INHUMANE_TEST_OUTPUT")) (defmethod assert-expr '= [msg [_ a & more]] - `(let [a# ~a] - (if-let [more# (seq (list ~@more))] - (let [result# (apply = a# more#)] - (if result# - (do-report {:type :pass, :message ~msg, - :expected a#, :actual more#}) - (do-report {:type :fail, :message ~msg, - :expected a#, :actual more#, - :diffs (map vector - more# - (map #(take 2 (data/diff a# %)) - more#))})) - result#) - (throw (Exception. "= expects more than one argument"))))) + (=-body msg a more)) + (defmethod assert-expr 'clojure.core/= [msg [_ a & more]] + (=-body msg a more)) (defmethod report :fail [{:keys [type expected actual diffs message] :as event}] diff --git a/test/pjstadig/humane_test_output/formatting_test.clj b/test/pjstadig/humane_test_output/formatting_test.clj index b0c505e..34e3d5b 100644 --- a/test/pjstadig/humane_test_output/formatting_test.clj +++ b/test/pjstadig/humane_test_output/formatting_test.clj @@ -17,3 +17,10 @@ (let [foo {:foo :bar :baz :quux :something "a long string?" :another-key "and another value"}] (is (list? foo))))) + +(defmacro deftest+ + [test-name expected actual] + `(deftest ~test-name + (is (= ~expected ~actual)))) + +(deftest+ t-macro-wrapping 1 2)