/
cljtest.clj
58 lines (53 loc) · 2.44 KB
/
cljtest.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
(ns state-flow.cljtest
(:require [clojure.test :as t]
[matcher-combinators.printer :as matcher-combinators.printer] ;; to register clojure.test assert-expr for `match?`
[matcher-combinators.test]
[state-flow.assertions.matcher-combinators]
[state-flow.core :as core]
[state-flow.probe :as probe]))
(defmacro ^:deprecated match?
"DEPRECATED. Use state-flow.assertions.matcher-combinators/match? instead. "
[match-desc actual expected & [params]]
(let [params* (merge {:times-to-try probe/default-times-to-try
:sleep-time probe/default-sleep-time
:caller-meta (meta &form)
:description match-desc
:called-from-deprecated-match? true}
params)]
`(~'state-flow.assertions.matcher-combinators/match? ~expected ~actual ~params*)))
(defn- tag-for-pretty-printing [actual-summary result]
(with-meta {:summary actual-summary
:match-result result}
{:type ::mismatch}))
(defmethod clojure.core/print-method ::mismatch [{:keys [match-result]} out]
(binding [*out* out]
(matcher-combinators.printer/pretty-print match-result)))
(defn- clojure-test-report
[{:match/keys [result expected actual]
:flow/keys [description-stack]
:as assertion-report}]
(let [message (core/format-description description-stack)]
{:type (case result :match :pass :mismatch :fail)
:message message
:expected expected
:actual (if (:mismatch/detail assertion-report)
(tag-for-pretty-printing
(list '~'not (list 'match? expected actual))
(:mismatch/detail assertion-report))
actual)
:file (-> description-stack last core/description->file)
:line (-> description-stack last :line)}))
(defmacro defflow
{:doc "Creates a flow and binds it a Var named by name"
:arglists '([name & flows]
[name parameters & flows])}
[name & forms]
(let [[parameters & flows] (if (map? (first forms))
forms
(cons {} forms))]
`(t/deftest ~name
(let [[ret# state#] (core/run* ~parameters (core/flow ~(str name) ~@flows))
assertions# (get-in (meta state#) [:test-report :assertions])]
(doseq [assertion-data# assertions#]
(t/report (#'clojure-test-report assertion-data#)))
[ret# state#]))))