forked from lambdaisland/kaocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.clj
47 lines (41 loc) · 1.96 KB
/
load.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
(ns kaocha.load
(:refer-clojure :exclude [symbol])
(:require [kaocha.core-ext :refer :all]
[kaocha.testable :as testable]
[clojure.java.io :as io]
[lambdaisland.tools.namespace.find :as ctn-find]))
(set! *warn-on-reflection* true)
(def clj ctn-find/clj)
(def cljs ctn-find/cljs)
(defn ns-match? [ns-patterns ns-sym-or-error]
(or (ctn-find/reader-exception? ns-sym-or-error)
(some #(re-find % (name ns-sym-or-error)) ns-patterns)))
(defn find-test-nss [test-paths ns-patterns & [platform]]
(sequence (comp
(map io/file)
(mapcat #(ctn-find/find-namespaces-in-dir % platform))
(filter (partial ns-match? ns-patterns)))
test-paths))
(defn load-error-testable [file exception]
{::testable/type :kaocha.type/ns
::testable/id (keyword (str file))
::testable/desc (str "ns form could not be read in " file)
::testable/load-error exception
::testable/load-error-file (str file)
::testable/load-error-line 1
::testable/load-error-message (str "Failed reading ns form in " file "\n"
"Caused by: " (.getMessage ^Throwable exception))
:kaocha.ns/name 'kaocha.load-error})
(defn load-test-namespaces [testable ns-testable-fn & [platform]]
(let [test-paths (:kaocha/test-paths testable)
ns-patterns (map regex (:kaocha/ns-patterns testable))
ns-names (find-test-nss test-paths ns-patterns platform)
testables (map (fn [sym-or-error]
(if (ctn-find/reader-exception? sym-or-error)
(let [[_ file exception] sym-or-error]
(load-error-testable file exception))
(ns-testable-fn sym-or-error)))
ns-names)]
(assoc testable
:kaocha.test-plan/tests
(testable/load-testables testables))))