/
specs.clj
72 lines (52 loc) · 2.61 KB
/
specs.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
(ns kaocha.specs
(:require [clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.test :as t]
[expound.alpha :as expound]))
(def global-opts [:kaocha/reporter
:kaocha/color?
:kaocha/fail-fast?
:kaocha/watch?
:kaocha/plugins])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; config
(s/def :kaocha/config (s/keys :req ~(conj global-opts :kaocha/tests)))
(s/def :kaocha/tests (s/coll-of :kaocha/testable))
(s/def :kaocha/testable (s/keys :req [:kaocha.testable/type
:kaocha.testable/id]
:opt [:kaocha.testable/meta]))
(s/def :kaocha.testable/type qualified-keyword?)
(s/def :kaocha.testable/id keyword?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test plan
(s/def :kaocha/test-plan (s/keys :req ~(conj global-opts :kaocha.test-plan/tests)))
(s/def :kaocha.test-plan/tests (s/coll-of :kaocha.test-plan/testable))
(s/def :kaocha.test-plan/testable (s/and :kaocha/testable
(s/keys :opt [:kaocha.test-plan/tests
:kaacha.test-plan/load-error])))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; result
(s/def :kaocha/result (s/keys :req ~(conj global-opts :kaocha.result/tests)))
(s/def :kaocha.result/tests (s/coll-of :kaocha.result/testable))
(s/def :kaocha.result/testable (s/and :kaocha/testable
(s/keys #_#_:req [:kaocha.result/count]
:opt [:kaocha.result/count
:kaocha.result/tests
:kaocha.result/pass
:kaocha.result/error
:kaocha.result/fail
:kaocha.result/out
:kaocha.result/err
:kaocha.result/time])))
(s/def :kaocha.result/count nat-int?)
(s/def :kaocha.result/pass nat-int?)
(s/def :kaocha.result/fail nat-int?)
(s/def :kaocha.result/error nat-int?)
(s/def :kaocha.result/out string?)
(s/def :kaocha.result/err string?)
(s/def :kaocha.result/time nat-int?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; helpers
(defn assert-spec [spec value]
(when-not (s/valid? spec value)
(throw (AssertionError. (expound/expound-str spec value)))))