-
Notifications
You must be signed in to change notification settings - Fork 81
/
check.clj
76 lines (63 loc) · 2.93 KB
/
check.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(ns kaocha.type.spec.test.check
(:refer-clojure :exclude [symbol])
(:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha]
[kaocha.core-ext :refer :all]
[kaocha.hierarchy :as hierarchy]
[kaocha.load :as load]
[kaocha.specs]
[kaocha.test-suite :as test-suite]
[kaocha.testable :as testable]
[kaocha.type :as type]
[kaocha.type.spec.test.fdef :as type.fdef]
[kaocha.type.spec.test.ns :as type.spec.ns]))
;; This namespace does not actually exist, but is created by
;; requiring clojure.spec.test.alpha
(alias 'stc 'clojure.spec.test.check)
(def check-defaults {:kaocha.spec.test.check/ns-patterns [".*"]
:kaocha.spec.test.check/syms :all-fdefs})
(defn all-fdef-tests [{:kaocha/keys [source-paths]
:kaocha.spec.test.check/keys [ns-patterns]
:as testable}]
(let [ns-patterns (map regex ns-patterns)
ns-names (load/find-test-nss source-paths ns-patterns)
testables (map #(type.spec.ns/->testable testable %) ns-names)]
(testable/load-testables testables)))
(defn check-tests [check]
(let [{syms :kaocha.spec.test.check/syms :as check} (merge check-defaults check)]
(condp = syms
:all-fdefs (all-fdef-tests check)
:other-fdefs nil ;; TODO: this requires orchestration from the plugin
:else (type.fdef/load-testables check syms))))
(defn checks [{checks :kaocha.spec.test.check/checks :as testable}]
(let [checks (or checks [{}])]
(map #(merge testable %) checks)))
(defmethod testable/-load :kaocha.type/spec.test.check [testable]
(-> (checks testable)
(->> (map check-tests)
(apply concat)
(assoc testable :kaocha.test-plan/tests))
(testable/add-desc "clojure.spec.test.check")))
(defmethod testable/-run :kaocha.type/spec.test.check [testable test-plan]
(test-suite/run testable test-plan))
(s/def :kaocha.spec.test.check/syms
(s/or :given-symbols (s/coll-of symbol?)
:catch-all #{:all-fdefs :other-fdefs}))
(s/def :kaocha.spec.test.check/ns-patterns :kaocha/ns-patterns)
(s/def :kaocha.spec.test.check/check
(s/keys :opt [:kaocha.spec.test.check/syms
::stc/instrument?
::stc/check-asserts?
::stc/opts
:kaocha.spec.test.check/ns-patterns]))
(s/def :kaocha.spec.test.check/checks (s/coll-of :kaocha.spec.test.check/check))
(s/def :kaocha.type/spec.test.check
(s/merge (s/keys :req [:kaocha.testable/type
:kaocha.testable/id
:kaocha/source-paths]
:opt [:kaocha.filter/skip-meta
:kaocha.spec.test.check/ns-patterns
:kaocha.spec.test.check/checks])
:kaocha.spec.test.check/check))
(hierarchy/derive! :kaocha.type/spec.test.check
:kaocha.testable.type/suite)