diff --git a/main/src/data_test.clj b/main/src/data_test.clj index 232b0df..8d8a884 100644 --- a/main/src/data_test.clj +++ b/main/src/data_test.clj @@ -17,15 +17,11 @@ (:require [clojure.test :as ct] [schema.core :as s] - [data-test.runner :as runner] + [data-test.reporter :as reporter] [data-test.file-loader :as fl])) (def TestDataSpec fl/TestDataSpec) -(s/defn test-with-data - [test-name :- s/Keyword] - (runner/run-tests (runner/create-test-runner test-name))) - (defmacro defdatatest [n bindings & body] (when ct/*load-tests* (let [namespaced-test-key# (keyword (str *ns*) (name n))] @@ -34,9 +30,13 @@ (doseq [data-spec# (fl/load-data-test-specs ~namespaced-test-key#)] (let [~(symbol (first bindings)) (:input data-spec#) ~(symbol (second bindings)) (:expectation data-spec#) - data-spec-file# (:data-spec-file data-spec#)] + data-spec-file# (:data-spec-file data-spec#) + message# (new java.io.StringWriter)] (binding [ct/*testing-contexts* - (conj ct/*testing-contexts* data-spec-file#)] - ~@body)))) + (conj ct/*testing-contexts* data-spec-file#) + ct/*test-out* message#] + ~@body) + (reporter/write data-spec-file# data-spec# message#) + ))) :data-spec-key namespaced-test-key#) (fn [] (ct/test-var (var ~n))))))) diff --git a/test/src/data_test/runner_test.clj b/main/src/data_test/reporter.clj similarity index 67% rename from test/src/data_test/runner_test.clj rename to main/src/data_test/reporter.clj index 916470f..b076fcd 100644 --- a/test/src/data_test/runner_test.clj +++ b/main/src/data_test/reporter.clj @@ -13,16 +13,19 @@ ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. -(ns data-test.runner-test +(ns data-test.reporter (:require - [clojure.test :refer :all] + [clojure.java.io :as io] + [clojure.string :as str] [schema.core :as s] - [data-test.runner :as sut])) + [aero.core :as aero])) -(s/defmethod sut/data-test ::test-it - [_ input :- s/Any expectation :- s/Any] - "my-result") - -(deftest should-reslove-multimethod - (is (= "my-result" - (sut/data-test (sut/create-test-runner ::test-it) nil nil)))) +(s/defn write + [data-spec-file :- s/Str + data-spec + message] + (let [output-file (str "target/datatest/" data-spec-file)] + (clojure.java.io/make-parents output-file) + (spit output-file (merge + {:message (str message)} + data-spec)))) \ No newline at end of file diff --git a/main/src/data_test/runner.clj b/main/src/data_test/runner.clj deleted file mode 100644 index 9237c2b..0000000 --- a/main/src/data_test/runner.clj +++ /dev/null @@ -1,59 +0,0 @@ -; Licensed to the Apache Software Foundation (ASF) under one -; or more contributor license agreements. See the NOTICE file -; distributed with this work for additional information -; regarding copyright ownership. The ASF licenses this file -; to you under the Apache License, Version 2.0 (the -; "License"); you may not use this file except in compliance -; with the License. You may obtain a copy of the License at -; -; http://www.apache.org/licenses/LICENSE-2.0 -; -; Unless required by applicable law or agreed to in writing, software -; distributed under the License is distributed on an "AS IS" BASIS, -; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; See the License for the specific language governing permissions and -; limitations under the License. -(ns data-test.runner - (:require - [schema.core :as s] - [data-test.file-loader :as fl])) - -(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 _) "]"))) - -(defprotocol RunTest - "Protocol for data driven tests" - (name-prefix [dda-test]) - (run-tests [dda-test])) - -(s/defn dispatch-by-name :- s/Keyword - "Dispatcher for data-tests." - [runner :- TestRunner - input :- s/Any - expectation :- s/Any] - (:name runner)) - -(defmulti data-test - "Multimethod for data-test." - dispatch-by-name) - -(extend-type TestRunner - RunTest - (name-prefix [_] - (fl/data-test-spec-file-prefix (:name _))) - (run-tests [_] - (let [testdata (fl/load-data-test-spec (fl/data-test-spec-file-prefix (:name _))) - {:keys [input expectation]} testdata] - (data-test _ input expectation)))) - -(defn create-test-runner - [test-name] - (->TestRunner test-name))