Get rid of excessive requires in tests
This commit is contained in:
parent
87f311c950
commit
4664f6db8c
6 changed files with 42 additions and 30 deletions
|
@ -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))
|
||||
|
27
src/pjstadig/assert_expr.cljc
Normal file
27
src/pjstadig/assert_expr.cljc
Normal file
|
@ -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)))
|
||||
|
11
src/pjstadig/macro.cljc
Normal file
11
src/pjstadig/macro.cljc
Normal file
|
@ -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))
|
||||
|
||||
|
|
@ -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+]]))
|
||||
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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!)
|
||||
|
|
Loading…
Reference in a new issue