diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-01-12 01:24:42 +0000 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-01-12 01:24:42 +0000 |
commit | d99887a0f17ea5103a8611f94ed1dadad4f40803 (patch) | |
tree | a06d977956b7c61403096a365fb6822341d4c15f /src/clojure | |
parent | b1317c05bbac70c4303d1da4125e4d38fb766a04 (diff) |
test_is.clj: better source line numbers with new "file-position"
Diffstat (limited to 'src/clojure')
-rw-r--r-- | src/clojure/contrib/test_is.clj | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/clojure/contrib/test_is.clj b/src/clojure/contrib/test_is.clj index b6c5944e..f649467f 100644 --- a/src/clojure/contrib/test_is.clj +++ b/src/clojure/contrib/test_is.clj @@ -89,15 +89,22 @@ ;; These are used in assert-expr methods. Rebind "report" to plug in ;; your own test-reporting framework. +(defn file-position + "Returns a vector [filename line-number] for the nth call up the + stack." + [n] + (let [s (nth (.getStackTrace (new java.lang.Throwable)) n)] + [(.getFileName s) (.getLineNumber s)])) + (defn testing-vars-str "Returns a string representation of the current test. Renders names in *testing-vars* as a list, then the source file and line of - current test." + current assertion." [] - (str ;;(ns-name (:ns (meta (first *testing-vars*)))) "/ " - (reverse (map #(:name (meta %)) *testing-vars*)) - " (" (:file (meta (first *testing-vars*))) - ":" (:line (meta (first *testing-vars*))) ")")) + (let [[file line] (file-position 4)] + (str ;;(ns-name (:ns (meta (first *testing-vars*)))) "/ " + (reverse (map #(:name (meta %)) *testing-vars*)) + " (" file ":" line ")"))) (defn testing-contexts-str "Returns a string representation of the current test context. Joins |