File tree 4 files changed +26
-17
lines changed
4 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -28,4 +28,5 @@ syntax: glob
28
28
.cake /
29
29
.lein-failures
30
30
.lein-deps-sum
31
+ .lein-repl-history
31
32
autodoc /**
Original file line number Diff line number Diff line change 4
4
(def __ :fill-in-the-blank )
5
5
(def ___ (fn [& args] __))
6
6
7
+ (defn ensure-valid-meditation [doc-expression-pairs]
8
+ (doseq [[doc expression] doc-expression-pairs]
9
+ (when-not (string? doc)
10
+ (throw (ex-info (str " Meditations must be alternating doc/expression pairs\n "
11
+ " Expected " doc " to be a documentation string" )
12
+ {:line (:line (meta doc))}))))
13
+ doc-expression-pairs )
14
+
7
15
(defmacro meditations [& forms]
8
- (let [pairs (partition 2 forms)
16
+ (let [pairs (ensure-valid-meditation ( partition 2 forms) )
9
17
tests (map (fn [[doc# code#]]
10
18
`(u/fancy-assert ~code# ~doc#))
11
19
pairs)]
Original file line number Diff line number Diff line change 21
21
(first more)
22
22
(recur more)))))
23
23
24
+ (defn report-error [file-path line error]
25
+ (let [message (or (.getMessage error) (.toString error))]
26
+ (println " \n Now meditate upon"
27
+ (str file-path
28
+ (when line (str " :" line))))
29
+ (println " ---------------------" )
30
+ (println " Assertion failed!" )
31
+ (println (.replaceFirst message " ^Assert failed: " " " ))))
32
+
24
33
(defn tests-pass? [dojo-path file-path]
25
34
(u/with-dojo [dojo-path]
26
35
(print " Considering" (str file-path " ..." ))
27
36
(println )
28
37
(flush )
29
38
(try (load-file file-path)
30
39
true
40
+ (catch clojure.lang.ExceptionInfo ei
41
+ (report-error file-path (:line (ex-data ei)) ei)
42
+ false )
31
43
(catch Throwable e
32
- (let [message (or (.getMessage e) (.toString e))
33
- ; TODO: use ex-info or something to clean this up
34
- line (when-let [groups (first (re-seq #"^\[ LINE (\d +)\] "
35
- message))]
36
- (last groups))]
37
- (println " \n Now meditate upon"
38
- (str file-path
39
- (when line (str " :" line))))
40
- (println " ---------------------" )
41
- (println " Assertion failed!" )
42
- (println (.replaceFirst
43
- (.replaceFirst message " ^Assert failed: " " " )
44
- " ^\\ [LINE \\ d+\\ ] " " " )))
44
+
45
+ (report-error file-path nil e)
45
46
false ))))
46
47
47
48
(defn namaste []
Original file line number Diff line number Diff line change 35
35
([x message]
36
36
`(try (safe-assert ~x ~message)
37
37
(catch Throwable e#
38
- (throw (Exception. (str ~(when-let [line (:line (meta x))]
39
- (str " [LINE " line " ] " ))
40
- '~message " \n " '~x)))))))
38
+ (throw (ex-info (str '~message " \n " '~x)
39
+ {:line (:line (meta '~x))}))))))
41
40
42
41
(defn read-project []
43
42
(let [rdr (clojure.lang.LineNumberingPushbackReader.
You can’t perform that action at this time.
0 commit comments