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]
|
2019-05-17 10:26:01 +00:00
|
|
|
[schema.core :as s]
|
2019-05-29 15:39:51 +00:00
|
|
|
[data-test.reporter :as reporter]
|
2019-05-29 15:47:48 +00:00
|
|
|
[data-test.file-loader :as loader]))
|
2019-05-24 07:43:49 +00:00
|
|
|
|
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))]
|
2019-05-24 07:43:49 +00:00
|
|
|
`(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#)
|
2019-05-29 15:39:51 +00:00
|
|
|
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 15:39:51 +00:00
|
|
|
(conj ct/*testing-contexts* data-spec-file#)
|
2019-05-29 15:47:48 +00:00
|
|
|
t/*test-out* message#]
|
2019-05-29 15:39:51 +00:00
|
|
|
~@body)
|
|
|
|
(reporter/write data-spec-file# data-spec# message#)
|
|
|
|
)))
|
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)))))))
|