commit | author | age
|
919581
|
1 |
(binding [*compile-files* true] |
KM |
2 |
(require 'clojure.test)) |
|
3 |
|
|
4 |
(ns test-runner |
|
5 |
(:require [clojure.test :as t])) |
|
6 |
|
|
7 |
(when-not (.exists (java.io.File. "classes")) |
|
8 |
(.. (java.io.File. "classes") mkdir)) |
|
9 |
|
|
10 |
(defmulti emacs-report :type) |
|
11 |
|
04e874
|
12 |
(defmethod emacs-report :fail |
919581
|
13 |
[m] |
KM |
14 |
(t/with-test-out |
04e874
|
15 |
(when-let [source-file (some-> t/*testing-vars* |
KM |
16 |
first |
|
17 |
meta |
|
18 |
:file)] |
2c210a
|
19 |
(println (str "FAIL:" source-file ":" (:line m) ":" (t/testing-vars-str m) ":" (t/testing-contexts-str) ":" (:message m "FAIL"))) |
KM |
20 |
(println (str "FAIL-CONTINUE:EXPECTED:" (pr-str (:expected m)))) |
|
21 |
(println (str "FAIL-CONTINUE:ACTUAL:" (pr-str (:actual m))))))) |
04e874
|
22 |
|
KM |
23 |
(defmethod emacs-report :error |
|
24 |
[m] |
|
25 |
(when-let [source-file (some-> t/*testing-vars* |
|
26 |
first |
|
27 |
meta |
|
28 |
:file)] |
2c210a
|
29 |
(println (str "ERROR:" source-file ":" (:line m) ":" (t/testing-vars-str m) ":" (t/testing-contexts-str) ":" (:message m "FAIL"))) |
KM |
30 |
(println (str "ERROR-CONTINUE:EXPECTED:" (pr-str (:expected m)))) |
|
31 |
(println (str "ERROR-CONTINUE:ACTUAL:" |
|
32 |
(if (instance? Throwable (:actual m)) |
|
33 |
(ex-message (:actual m)) |
|
34 |
(pr-str (:actual m))))))) |
04e874
|
35 |
|
KM |
36 |
(defmethod emacs-report :default |
|
37 |
[_]) |
919581
|
38 |
|
9ae31a
|
39 |
(defn- clj-file? [f] |
KM |
40 |
(re-matches #"^.*\.cljs?$" (.getName f))) |
|
41 |
|
|
42 |
(defn -main [& {:strs [-test-file] :or {-test-file "test"}}] |
919581
|
43 |
(binding [*compile-files* true] |
KM |
44 |
(compile 'test-runner) |
9ae31a
|
45 |
(println "Detecting test files in" -test-file) |
KM |
46 |
(let [test-files (->> -test-file |
f5c518
|
47 |
(java.io.File.) |
KM |
48 |
(file-seq) |
|
49 |
(filter (memfn isFile)) |
9ae31a
|
50 |
(filter clj-file?) |
f5c518
|
51 |
(map (memfn getAbsolutePath)) |
KM |
52 |
(set))] |
|
53 |
(println "Loading test files...") |
|
54 |
(run! load-file test-files) |
|
55 |
(let [test-namespaces (->> (all-ns) |
|
56 |
(mapcat ns-publics) |
|
57 |
(map (comp meta second)) |
|
58 |
(filter :test) |
|
59 |
(filter (comp test-files :file)) |
|
60 |
(map :ns) |
|
61 |
(set))] |
|
62 |
(println "Running tests on:" (map ns-name test-namespaces)) |
|
63 |
(System/exit (if (pos? (reduce (fn [total-fails n] |
|
64 |
(with-redefs [t/report emacs-report] |
|
65 |
(let [results (t/run-tests n)] |
|
66 |
(+ total-fails |
|
67 |
(:fail results 0) |
|
68 |
(:error results 0))))) |
|
69 |
0 |
|
70 |
test-namespaces)) |
|
71 |
1 |
|
72 |
0)))))) |