generated from exercism/generic-test-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-runner.clj
46 lines (34 loc) · 1.21 KB
/
test-runner.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
#!/usr/bin/env bb
(require '[clojure.test :as t]
'[babashka.classpath :as cp]
'[cheshire.core :as json]
'[clojure.string :as str])
(def test-ns (symbol (str (first *command-line-args*) "-test")))
(def in-dir (second *command-line-args*))
(cp/add-classpath "src:test")
(require test-ns)
(def passes (atom []))
(def fails (atom []))
(def errors (atom []))
(defmethod t/report :begin-test-ns [m])
(defmethod t/report :pass [m]
(swap! passes conj {:name (:name (meta (first t/*testing-vars*)))
:status "pass"}))
(defmethod t/report :fail [m]
(swap! fails conj {:name (:name (meta (first t/*testing-vars*)))
:status "fail"
:message (str "Expected " (:expected m) " but got " (:actual m))}))
(defmethod t/report :error [m]
(swap! errors conj (:name (meta (first t/*testing-vars*)))))
(defmethod t/report :summary [m])
(t/run-tests test-ns)
(println (json/generate-string
{:version 2
:status (if (and (empty? @fails)
(empty? @errors))
"pass" "fail")
:tests (into @passes @fails)
:message (when (seq @errors)
@errors)}
{:pretty true}))
(System/exit 0)