From 6948ed6ec82d56caacf2f77e84b52a0ff35722e9 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Tue, 8 Feb 2011 15:51:05 -0600 Subject: [PATCH] Find tests that pass too easily in test run. --- src/path_to_answer_sheet.clj | 17 ++++++++++++++++- src/path_to_enlightenment.clj | 8 ++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) 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