try to use macro created deftests

This commit is contained in:
jem 2019-05-22 09:21:14 +02:00
parent 22227ba979
commit 552acb357f
4 changed files with 34 additions and 17 deletions

View file

@ -23,14 +23,26 @@
[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)))
(defmacro defdatatest [name & body] (defn datatestdef-form [namespaced-test-key body]
'(do '(do
(clojure.test/deftest ~name (clojure.test/deftest ~(symbol (name namespaced-test-key))
;TODO-1: bring macro to work ;(let [file-prefix (data-test.runner/data-file-prefix ~namespaced-test-key)
;TODO-2: crate filename out of package/namespace/test-name.edn ; testdata (data-test.runner/load-test-data file-prefix)
;TODO-3: enable more than one test-data-set with optional infix .## ; {:keys [input expectation]} testdata]
(let [testdata (data-test/read-data ~@body)))
(clojure.java.io/resource
"data_test_test/should-test-with-data-macro-version.edn")) (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] {:keys [input expectation]} testdata]
~@body)))) ~@body)))
(fn [] (ct/test-var (var ~name))))))

View file

@ -25,6 +25,13 @@
{:input s/Any {:input s/Any
:expectation s/Any}) :expectation s/Any})
(def TestResult
{:input s/Any
:expectation s/Any
:output s/Any
:passed? s/Bool
:error s/Any})
(s/defrecord TestRunner [name :- s/Keyword] (s/defrecord TestRunner [name :- s/Keyword]
Object Object
(toString [_] (str "TestRunner: " (:name _) "]"))) (toString [_] (str "TestRunner: " (:name _) "]")))
@ -32,8 +39,7 @@
(defprotocol RunTest (defprotocol RunTest
"Protocol for data driven tests" "Protocol for data driven tests"
(name-prefix [dda-test]) (name-prefix [dda-test])
(run-tests [dda-test]) (run-tests [dda-test]))
)
(s/defn dispatch-by-name :- s/Keyword (s/defn dispatch-by-name :- s/Keyword
"Dispatcher for data-tests." "Dispatcher for data-tests."
@ -60,8 +66,7 @@
(s/defn load-test-data (s/defn load-test-data
[file-prefix :- s/Str] [file-prefix :- s/Str]
(let [file-path (str file-prefix ".edn")] (let [file-path (str file-prefix ".edn")]
(read-data (read-data (io/resource file-path))))
(io/resource file-path))))
(extend-type TestRunner (extend-type TestRunner
RunTest RunTest

View file

@ -35,5 +35,5 @@
(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)))
;;(macroexpand '(sut/defdatatest should-test-with-data-macro-version (sut/defdatatest should-test-with-data-macro-version
;; (is ture))) (is true))