diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 5b2e8f6..ab2c642 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -162,8 +162,23 @@ (defn fill-in-answers [text koan sym] (replace-with text sym (answers-for koan sym))) +(defn ensure-failing-tests [] + (let [wtr (java.io.PrintWriter. (java.io.ByteArrayOutputStream.))] + (binding [path-to-enlightenment/handle-problem (constantly nil) + clojure.test/*test-out* wtr] + (dorun + (map + (fn [koan] + (let [form (koan-text koan) + result (load-string form)] + (when (= :pass result) + (println (str "\n" koan ".clj is passing without filling in the blanks"))))) + + ordered-koans))))) + (defn run [] (try + (ensure-failing-tests) (dorun (map (fn [koan] @@ -173,7 +188,7 @@ (fill-in-answers koan "___")))) ordered-koans)) - (println "\nThe answer key checks out!") + (println "\nAll tests pass when the answers are filled in.") (catch Exception e (println "\nAnswer sheet fail: " e) diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index f70bf52..bc29c25 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -6,13 +6,17 @@ (def __ :fill-in-the-blank) (def ___ (fn [& args] __)) +(defn ^:dynamic handle-problem [] + (System/exit 0)) + (defmacro meditations [& forms] (let [pairs (partition 2 forms)] `(do ~@(map (fn [[doc# code#]] - `(when-not (is ~code# ~doc#) - (System/exit 0))) + `(if (is ~code# ~doc#) + :pass + (handle-problem))) pairs)))) (def ordered-koans