From 328e19f5375e33ccbdfdcc41bc84a45562838294 Mon Sep 17 00:00:00 2001 From: jem Date: Wed, 22 May 2019 22:31:15 +0200 Subject: [PATCH] deftest now is working --- main/src/data_test.clj | 29 +++++++---------------------- test/src/data_test_test.clj | 15 +++++++++++---- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/main/src/data_test.clj b/main/src/data_test.clj index 9281cbd..c07f7b6 100644 --- a/main/src/data_test.clj +++ b/main/src/data_test.clj @@ -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))) diff --git a/test/src/data_test_test.clj b/test/src/data_test_test.clj index 709942b..e713b42 100644 --- a/test/src/data_test_test.clj +++ b/test/src/data_test_test.clj @@ -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)