diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 66a2ea3..b234faf 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -1,8 +1,7 @@ (ns path-to-answer-sheet (:use [runner.koans :only [ordered-koans]] [path-to-enlightenment :only [meditations __ ___]] - [clojure.string :only [join split trim]] - [clojure.test :only [*test-out*]])) + [clojure.string :only [join split trim]])) (def answers {"equalities" {"__" [true @@ -216,17 +215,23 @@ (println (str "\n" koan ".clj is passing without filling in the blanks"))) (defn ensure-failing-without-answers [] - (binding [clojure.test/*test-out* - (java.io.PrintWriter. (java.io.ByteArrayOutputStream.))] - (if (every? - (fn [koan] - (let [form (koan-text koan) - result (load-string form)] - (if result - (print-non-failing-error koan) - :pass))) - ordered-koans) - (println "\nTests all fail before the answers are filled in.")))) + (if (every? + (fn [koan] + (let [form (koan-text koan) + fake-err (java.io.PrintStream. (java.io.ByteArrayOutputStream.)) + real-err System/err + result (try + (System/setErr fake-err) + (load-string form) + true + (catch AssertionError e false) + (catch Exception e false) + (finally (System/setErr real-err)))] + (if result + (print-non-failing-error koan) + :pass))) + ordered-koans) + (println "\nTests all fail before the answers are filled in."))) (defn ensure-passing-with-answers [] (try diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index bc68f89..6f6a32a 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -1,18 +1,15 @@ (ns path-to-enlightenment (:use [runner.freshness :only [setup-freshener]]) (:require [clojure.set] - [clojure.string] - [clojure.test])) + [clojure.string])) (def __ :fill-in-the-blank) (def ___ (fn [& args] __)) (defmacro meditations [& forms] - (let [pairs (conj (partition 2 forms) - ["Bootstrap for file/line reporting" - '(clojure.test/is (= 0 0))]) + (let [pairs (partition 2 forms) tests (map (fn [[doc# code#]] - `(clojure.test/is ~code# ~doc#)) + `(assert ~code# ~doc#)) pairs)] `(and ~@tests))) diff --git a/src/runner/koans.clj b/src/runner/koans.clj index a09a0c1..3435eec 100644 --- a/src/runner/koans.clj +++ b/src/runner/koans.clj @@ -42,7 +42,12 @@ (load-file file-path) (catch Exception e (println) - (println e) + (println "Problem in " file-path) + (println "---------------------") + (println "Assertion failed!") + (println (.replaceFirst (.getMessage (.getCause e)) + "^Assert failed: " + "")) false))) (defn namaste []