-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.boot
85 lines (72 loc) · 3.14 KB
/
build.boot
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
77
78
79
80
81
82
83
84
85
(set-env!
:source-paths #{"test"}
:resource-paths #{"spec"}
:dependencies '[[org.clojure/clojure "1.9.0"]
[camel-snake-kebab "0.4.0"]
[junit/junit "4.12"]
[org.clojure/clojurescript "1.9.946"]
[org.concordion/concordion "2.1.0"]
[radicalzephyr/boot-junit "0.2.1"]
[radicalzephyr/cljunit "0.2.0"]
[zprint "0.4.2"]
[clojure-future-spec "1.9.0-alpha17"]
[backtick "0.3.4"]
[me.raynes/conch "0.8.0"]
[http-kit "2.2.0"]])
(require '[radicalzephyr.boot-junit :refer (junit)])
(require '[boot.pod :as pod])
(require '[boot.util :as util])
(require '[clojure.string :as str])
(def pod-deps
'[[radicalzephyr/cljunit "0.2.0"]])
(defn- init [fresh-pod]
(pod/with-eval-in fresh-pod
(require '[cljunit.core :refer [run-tests-in-classes]])))
(defn- construct-class-name [prefix path]
(let [path-seq (-> path
(str/replace prefix "")
(str/replace #"\.md$" "")
(str/split #"/"))]
(->> path-seq
(remove empty?)
(interpose ".")
(apply str))))
(defn- path->class-name [class-name]
(let [prefix (str (tmp-dir class-name))
file (tmp-file class-name)]
(construct-class-name prefix (str file))))
(deftask concordion
"Run the concordion with jUnit test runner."
[c class-names CLASSNAME #{str} "The set of Java class names to run tests from."
p packages PACKAGE #{str} "The set of package names to run tests from."]
(let [worker-pods (pod/pod-pool (update-in (get-env) [:dependencies] into pod-deps)
:init init)
tgt (tmp-dir!)
cd (clojure.java.io/file tgt "concordion")]
(cleanup (worker-pods :shutdown))
(with-pre-wrap fileset
(let [worker-pod (worker-pods :refresh)
spec-files (by-ext [".md"] (input-files fileset))
class-files (by-ext [".class"] (output-files fileset))
all-class-names (map path->class-name spec-files)]
(when-not (seq class-files)
(util/warn "No .class files found in `output-files`, did you forget to run `aot` or `javac`?\n"))
(if-let [result (try
(.mkdirs cd)
(pod/with-eval-in worker-pod
(System/setProperty "concordion.output.dir" ~(.getPath cd))
(run-tests-in-classes '~all-class-names
:classes ~class-names
:packages ~packages))
(catch ClassNotFoundException e
(util/warn "Could not load class: %s...\n" (.getMessage e))
{:failures 1}))]
(when (> (:failures result) 0)
(throw (ex-info "Some tests failed or errored" {})))
(util/warn "Nothing was tested.")))
(-> fileset (add-asset tgt) commit!))))
(deftask test
"Compile and run my concordion tests."
[]
(comp (aot :all true)
(concordion)))