Permalink
Browse files

Add line numbers to failures

  • Loading branch information...
1 parent bf72766 commit 86439389f63fef512190552abd81aac00d549a85 @trptcolin trptcolin committed Feb 25, 2013
Showing with 17 additions and 6 deletions.
  1. +14 −5 src/koan_engine/koans.clj
  2. +3 −1 src/koan_engine/util.clj
View
@@ -27,13 +27,22 @@
true
(catch Exception e
(println)
- (println "Problem in" file-path)
- (println "---------------------")
- (println "Assertion failed!")
(let [actual-error (or (.getCause e) e)
message (or (.getMessage actual-error)
- (.toString actual-error))]
- (println (.replaceFirst message "^Assert failed: " "")))
+ (.toString actual-error))
+ ; TODO: use ex-info or something to clean this up, once we're
+ ; upgraded to clojure 1.4+
+ line (when-let [groups (first (re-seq #"^\[LINE (\d+)\] "
+ message))]
+ (last groups))]
+ (println "Problem in"
+ (str file-path
+ (when line (str ":" line))))
+ (println "---------------------")
+ (println "Assertion failed!")
+ (println (.replaceFirst
+ (.replaceFirst message "^Assert failed: " "")
+ "^\\[LINE \\d+\\] " "")))
false))))
(defn namaste []
View
@@ -35,7 +35,9 @@
([x message]
`(try (safe-assert ~x ~message)
(catch Throwable e#
- (throw (Exception. (str '~message "\n" '~x )
+ (throw (Exception. (str ~(when-let [line (:line (meta x))]
+ (str "[LINE " line "] "))
+ '~message "\n" '~x)
e#))))))
(defn read-project []

0 comments on commit 8643938

Please sign in to comment.