diff --git a/src/pjstadig/assert_expr.clj b/src/pjstadig/assert_expr.clj deleted file mode 100644 index 3879da4..0000000 --- a/src/pjstadig/assert_expr.clj +++ /dev/null @@ -1,26 +0,0 @@ -(ns pjstadig.assert-expr - (:require [cljs.test :refer [assert-expr]])) - -(defn =-body - [msg a more] - `(let [a# ~a] - (if-let [more# (seq (list ~@more))] - (let [result# (apply = a# more#)] - (if result# - (~'cljs.test/do-report {:type :pass, :message ~msg, - :expected a#, :actual more#}) - (~'cljs.test/do-report {:type :fail, :message ~msg, - :expected a#, :actual more#, - :diffs (map vector - more# - (map #(take 2 (clojure.data/diff a# %)) - more#))})) - result#) - (throw (Exception. "= expects more than one argument"))))) - -(defmethod assert-expr '= [menv msg [_ a & more]] - (=-body msg a more)) - -(defmethod assert-expr 'cljs.core/= [menv msg [_ a & more]] - (=-body msg a more)) - diff --git a/src/pjstadig/assert_expr.cljc b/src/pjstadig/assert_expr.cljc new file mode 100644 index 0000000..adda9a7 --- /dev/null +++ b/src/pjstadig/assert_expr.cljc @@ -0,0 +1,27 @@ +(ns pjstadig.assert-expr + #?(:clj (:require [cljs.test :refer [assert-expr]] + [pjstadig.macro :as m]))) + +(defn =-body + [msg a more] + `(let [a# ~a] + (if-let [more# (seq (list ~@more))] + (let [result# (apply = a# more#)] + (if result# + (m/do-report {:type :pass, :message ~msg, + :expected a#, :actual more#}) + (m/do-report {:type :fail, :message ~msg, + :expected a#, :actual more#, + :diffs (map vector + more# + (map #(take 2 (m/diff a# %)) + more#))})) + result#) + (throw (Exception. "= expects more than one argument"))))) + +#?(:clj (defmethod assert-expr '= [menv msg [_ a & more]] + (=-body msg a more))) + +#?(:clj (defmethod assert-expr 'cljs.core/= [menv msg [_ a & more]] + (=-body msg a more))) + diff --git a/src/pjstadig/macro.cljc b/src/pjstadig/macro.cljc new file mode 100644 index 0000000..7f91324 --- /dev/null +++ b/src/pjstadig/macro.cljc @@ -0,0 +1,11 @@ +(ns pjstadig.macro + (:require [cljs.test] + [clojure.data :as data :include-macros true])) + +(defn diff [& args] + (apply data/diff args)) + +(defn do-report [& args] + (apply cljs.test/do-report args)) + + diff --git a/test/pjstadig/humane_test_output/formatting_test.cljs b/test/pjstadig/humane_test_output/formatting_test.cljs index 78ee77d..b8612ed 100644 --- a/test/pjstadig/humane_test_output/formatting_test.cljs +++ b/test/pjstadig/humane_test_output/formatting_test.cljs @@ -1,5 +1,4 @@ (ns pjstadig.humane-test-output.formatting-test - (:use [clojure.data :only [diff]]) (:require-macros [cljs.test :refer [deftest testing is]] [pjstadig.macro :refer [deftest+]])) diff --git a/test/pjstadig/humane_test_output/records_test.cljs b/test/pjstadig/humane_test_output/records_test.cljs index 12ab68f..b8e7253 100644 --- a/test/pjstadig/humane_test_output/records_test.cljs +++ b/test/pjstadig/humane_test_output/records_test.cljs @@ -1,5 +1,4 @@ (ns pjstadig.humane-test-output.records-test - (:use [clojure.data :only [diff]]) (:require-macros [cljs.test :refer [deftest testing is]])) (defrecord ARecord [foo]) diff --git a/test/pjstadig/run_all.cljs b/test/pjstadig/run_all.cljs index 1754ab1..51af3bd 100644 --- a/test/pjstadig/run_all.cljs +++ b/test/pjstadig/run_all.cljs @@ -1,10 +1,12 @@ (ns pjstadig.run-all (:require [cljs.test - :refer [inc-report-counter! testing-vars-str testing-contexts-str get-current-env do-report] + :refer [inc-report-counter! testing-vars-str testing-contexts-str get-current-env] :refer-macros [run-all-tests run-tests]] [pjstadig.humane-test-output.formatting-test] [pjstadig.humane-test-output.records-test] - [cljs.pprint :as pp]) + [clojure.data :refer [diff]] + [cljs.pprint :as pp] + [pjstadig.macro :refer [do-report]]) (:require-macros [pjstadig.assert-expr])) (enable-console-print!)