try to use macro created deftests
This commit is contained in:
parent
22227ba979
commit
552acb357f
4 changed files with 34 additions and 17 deletions
|
@ -23,14 +23,26 @@
|
|||
[test-name :- s/Keyword]
|
||||
(runner/run-tests (runner/create-test-runner test-name)))
|
||||
|
||||
(defmacro defdatatest [name & body]
|
||||
(defn datatestdef-form [namespaced-test-key body]
|
||||
'(do
|
||||
(clojure.test/deftest ~name
|
||||
;TODO-1: bring macro to work
|
||||
;TODO-2: crate filename out of package/namespace/test-name.edn
|
||||
;TODO-3: enable more than one test-data-set with optional infix .##
|
||||
(let [testdata (data-test/read-data
|
||||
(clojure.java.io/resource
|
||||
"data_test_test/should-test-with-data-macro-version.edn"))
|
||||
{:keys [input expectation]} testdata]
|
||||
~@body))))
|
||||
(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))))))
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
{:input 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]
|
||||
Object
|
||||
(toString [_] (str "TestRunner: " (:name _) "]")))
|
||||
|
@ -32,8 +39,7 @@
|
|||
(defprotocol RunTest
|
||||
"Protocol for data driven tests"
|
||||
(name-prefix [dda-test])
|
||||
(run-tests [dda-test])
|
||||
)
|
||||
(run-tests [dda-test]))
|
||||
|
||||
(s/defn dispatch-by-name :- s/Keyword
|
||||
"Dispatcher for data-tests."
|
||||
|
@ -60,8 +66,7 @@
|
|||
(s/defn load-test-data
|
||||
[file-prefix :- s/Str]
|
||||
(let [file-path (str file-prefix ".edn")]
|
||||
(read-data
|
||||
(io/resource file-path))))
|
||||
(read-data (io/resource file-path))))
|
||||
|
||||
(extend-type TestRunner
|
||||
RunTest
|
||||
|
|
|
@ -35,5 +35,5 @@
|
|||
(deftest 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
|
||||
;; (is ture)))
|
||||
(sut/defdatatest should-test-with-data-macro-version
|
||||
(is true))
|
||||
|
|
Loading…
Reference in a new issue