data-test/main/src/data_test.clj

41 lines
2 KiB
Clojure
Raw Normal View History

2019-05-17 10:26:01 +00:00
; 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
(:require
2019-05-29 15:47:48 +00:00
[clojure.test :as t]
[data-test.reporter :as reporter]
2019-05-29 17:00:43 +00:00
[data-test.loader :as loader]))
2019-05-29 15:47:48 +00:00
(def TestDataSpec loader/TestDataSpec)
2019-05-17 10:26:01 +00:00
2019-05-28 06:43:23 +00:00
(defmacro defdatatest [n bindings & body]
2019-05-29 15:47:48 +00:00
(when t/*load-tests*
2019-05-28 16:53:08 +00:00
(let [namespaced-test-key# (keyword (str *ns*) (name n))]
`(def ~(vary-meta n assoc
:test `(fn []
2019-05-29 15:47:48 +00:00
(doseq [data-spec# (loader/load-data-test-specs ~namespaced-test-key#)]
2019-05-28 16:53:08 +00:00
(let [~(symbol (first bindings)) (:input data-spec#)
2019-05-28 16:59:52 +00:00
~(symbol (second bindings)) (:expectation data-spec#)
data-spec-file# (:data-spec-file data-spec#)
message# (new java.io.StringWriter)]
2019-05-29 15:47:48 +00:00
(binding [t/*testing-contexts*
2019-05-29 16:55:46 +00:00
(conj t/*testing-contexts* data-spec-file#)
reporter/*data-test-report-context* data-spec#]
~@body)
)))
2019-05-28 16:53:08 +00:00
:data-spec-key namespaced-test-key#)
2019-05-29 15:47:48 +00:00
(fn [] (t/test-var (var ~n)))))))