deftest now is working

This commit is contained in:
jem 2019-05-22 22:31:15 +02:00
parent 552acb357f
commit 328e19f537
2 changed files with 18 additions and 26 deletions

View file

@ -23,26 +23,11 @@
[test-name :- s/Keyword]
(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]
(let [namespaced-test-key (keyword (str *ns*) (name n))]
(println namespaced-test-key)
(data-test/datatestdef-form namespaced-test-key body)))
(defmacro defdatatest2
"Defines ...."
[name & 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))))))
`(clojure.test/deftest ~(symbol (name n))
(let [namespaced-test-key# ~(keyword (str *ns*) (name n))
file-prefix# (data-test.runner/data-file-prefix namespaced-test-key#)
testdata# (data-test.runner/load-test-data file-prefix#)
~(symbol 'input) (:input testdata#)
~(symbol 'expectation) (:expectation testdata#)]
~@body)))

View file

@ -21,19 +21,26 @@
[data-test.runner :as runner]
[data-test :as sut]))
; -------------------- 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"))
{:keys [input expectation]} testdata]
(is (= expectation
input))))
; -------------------------- multi method --------------------------
(s/defmethod runner/data-test ::should-test-with-data-record-version
[_ input :- s/Any expectation :- s/Any]
(= expectation
input))
(= input expectation))
(deftest 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
(is true))
; ---------------------------- macro -----------------------------
(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)