deftest now is working
This commit is contained in:
parent
552acb357f
commit
328e19f537
2 changed files with 18 additions and 26 deletions
|
@ -23,26 +23,11 @@
|
||||||
[test-name :- s/Keyword]
|
[test-name :- s/Keyword]
|
||||||
(runner/run-tests (runner/create-test-runner test-name)))
|
(runner/run-tests (runner/create-test-runner test-name)))
|
||||||
|
|
||||||
(defn datatestdef-form [namespaced-test-key body]
|
|
||||||
'(do
|
|
||||||
(clojure.test/deftest ~(symbol (name namespaced-test-key))
|
|
||||||
;(let [file-prefix (data-test.runner/data-file-prefix ~namespaced-test-key)
|
|
||||||
; testdata (data-test.runner/load-test-data file-prefix)
|
|
||||||
; {:keys [input expectation]} testdata]
|
|
||||||
~@body)))
|
|
||||||
|
|
||||||
(defmacro defdatatest [n & body]
|
(defmacro defdatatest [n & body]
|
||||||
(let [namespaced-test-key (keyword (str *ns*) (name n))]
|
`(clojure.test/deftest ~(symbol (name n))
|
||||||
(println namespaced-test-key)
|
(let [namespaced-test-key# ~(keyword (str *ns*) (name n))
|
||||||
(data-test/datatestdef-form namespaced-test-key body)))
|
file-prefix# (data-test.runner/data-file-prefix namespaced-test-key#)
|
||||||
|
testdata# (data-test.runner/load-test-data file-prefix#)
|
||||||
(defmacro defdatatest2
|
~(symbol 'input) (:input testdata#)
|
||||||
"Defines ...."
|
~(symbol 'expectation) (:expectation testdata#)]
|
||||||
[name & body]
|
~@body)))
|
||||||
(when ct/*load-tests*
|
|
||||||
`(def ~(vary-meta name assoc :test
|
|
||||||
`(fn []
|
|
||||||
`(let [testdata `(runner/load-test-data `(runner/data-file-prefix name))
|
|
||||||
{:keys [input expectation]} testdata]
|
|
||||||
~@body)))
|
|
||||||
(fn [] (ct/test-var (var ~name))))))
|
|
||||||
|
|
|
@ -21,19 +21,26 @@
|
||||||
[data-test.runner :as runner]
|
[data-test.runner :as runner]
|
||||||
[data-test :as sut]))
|
[data-test :as sut]))
|
||||||
|
|
||||||
|
; -------------------- explicit version ------------------
|
||||||
(deftest should-test-with-data-explicit-version
|
(deftest should-test-with-data-explicit-version
|
||||||
(let [testdata (runner/read-data (io/resource "data_test_test/should-test-with-data-explicit-version.edn"))
|
(let [testdata (runner/read-data (io/resource "data_test_test/should-test-with-data-explicit-version.edn"))
|
||||||
{:keys [input expectation]} testdata]
|
{:keys [input expectation]} testdata]
|
||||||
(is (= expectation
|
(is (= expectation
|
||||||
input))))
|
input))))
|
||||||
|
|
||||||
|
; -------------------------- multi method --------------------------
|
||||||
(s/defmethod runner/data-test ::should-test-with-data-record-version
|
(s/defmethod runner/data-test ::should-test-with-data-record-version
|
||||||
[_ input :- s/Any expectation :- s/Any]
|
[_ input :- s/Any expectation :- s/Any]
|
||||||
(= expectation
|
(= input expectation))
|
||||||
input))
|
|
||||||
|
|
||||||
(deftest should-test-with-data-record-version
|
(deftest should-test-with-data-record-version
|
||||||
(is (sut/test-with-data ::should-test-with-data-record-version)))
|
(is (sut/test-with-data ::should-test-with-data-record-version)))
|
||||||
|
|
||||||
(sut/defdatatest should-test-with-data-macro-version
|
; ---------------------------- macro -----------------------------
|
||||||
(is true))
|
(sut/defdatatest should-test-with-data-macro-version (is (= input expectation)))
|
||||||
|
|
||||||
|
(macroexpand-1 '(sut/defdatatest should-test-with-data-macro-version (is (= 1 1))))
|
||||||
|
|
||||||
|
((-> #'should-test-with-data-macro-version meta :test))
|
||||||
|
|
||||||
|
(meta #'should-test-with-data-macro-version)
|
||||||
|
|
Loading…
Reference in a new issue