introduce datatest reporters

This commit is contained in:
jem 2019-05-29 18:55:46 +02:00
parent 8c13ad2d44
commit 868a53b077
2 changed files with 44 additions and 14 deletions

View file

@ -33,10 +33,9 @@
data-spec-file# (:data-spec-file data-spec#) data-spec-file# (:data-spec-file data-spec#)
message# (new java.io.StringWriter)] message# (new java.io.StringWriter)]
(binding [t/*testing-contexts* (binding [t/*testing-contexts*
(conj ct/*testing-contexts* data-spec-file#) (conj t/*testing-contexts* data-spec-file#)
t/*test-out* message#] reporter/*data-test-report-context* data-spec#]
~@body) ~@body)
(reporter/write data-spec-file# data-spec# message#)
))) )))
:data-spec-key namespaced-test-key#) :data-spec-key namespaced-test-key#)
(fn [] (t/test-var (var ~n))))))) (fn [] (t/test-var (var ~n)))))))

View file

@ -15,17 +15,48 @@
; limitations under the License. ; limitations under the License.
(ns data-test.reporter (ns data-test.reporter
(:require (:require
[clojure.test :as t]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.string :as str] [clojure.stacktrace :as stack]
[schema.core :as s] [schema.core :as s]))
[aero.core :as aero]))
(s/defn write (def ^:dynamic
[data-spec-file :- s/Str *data-test-report-context* nil)
data-spec
message] (s/defn write-data-test-output
(let [output-file (str "target/datatest/" data-spec-file)] [m]
(clojure.java.io/make-parents output-file) (let [data-spec-file (:data-spec-file *data-test-report-context*)
output-file (str "target/datatest/" data-spec-file)]
(io/make-parents output-file)
(spit output-file (merge (spit output-file (merge
{:message (str message)} {:test-event m}
data-spec)))) *data-test-report-context*))))
(defmethod t/report :default [m]
(t/with-test-out (prn m)))
(defmethod t/report :pass [m]
(when *data-test-report-context* (write-data-test-output m))
(t/with-test-out (t/inc-report-counter :pass)))
(defmethod t/report :fail [m]
(t/with-test-out
(t/inc-report-counter :fail)
(println "\nFAIL in" (t/testing-vars-str m))
(when (seq t/*testing-contexts*) (println (t/testing-contexts-str)))
(when-let [message (:message m)] (println message))
(println "expected:" (pr-str (:expected m)))
(println " actual:" (pr-str (:actual m)))))
(defmethod t/report :error [m]
(t/with-test-out
(t/inc-report-counter :error)
(println "\nERROR in" (t/testing-vars-str m))
(when (seq t/*testing-contexts*) (println (t/testing-contexts-str)))
(when-let [message (:message m)] (println message))
(println "expected:" (pr-str (:expected m)))
(print " actual: ")
(let [actual (:actual m)]
(if (instance? Throwable actual)
(stack/print-cause-trace actual t/*stack-trace-depth*)
(prn actual)))))