From 95c0e1872881d715e2cc6cc39659a4d751b12a10 Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Sun, 24 Jan 2010 11:04:27 -0500 Subject: [PATCH] it helps if you put the metadata in the right place. also make mediate-on a macro so that I could get at the metadata from the actual test --- koans/about-asserts.clj | 8 ++++---- koans/path_to_enlightenment.clj | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/koans/about-asserts.clj b/koans/about-asserts.clj index b62ef60..b6272cf 100644 --- a/koans/about-asserts.clj +++ b/koans/about-asserts.clj @@ -1,10 +1,10 @@ -(defn test-truth - #^{:zen "We shall contemplate truth by testing reality, via asserts."} +(defn #^{:zen "We shall contemplate truth by testing reality, via asserts."} + test-truth [] (assert false)) ;; This should be true -(defn test-assert-equality - #^{:zen "To understand reality, we must compare our expectations against reality."} +(defn #^{:zen "To understand reality, we must compare our expectations against reality."} + test-assert-equality [] (let [expected-value 0 actual-value (+ 1 1)] diff --git a/koans/path_to_enlightenment.clj b/koans/path_to_enlightenment.clj index dfa7046..3f221c1 100644 --- a/koans/path_to_enlightenment.clj +++ b/koans/path_to_enlightenment.clj @@ -1,12 +1,14 @@ (load "about-asserts") -(defn meditate-on +(defmacro meditate-on "Runs tests but exits if an assertion fails" - [test] - (try - (test) - (catch Throwable t - (println (str "Metadata zen\n" "test name failed")) + [test-function] + `(try + (~test-function) + (catch Throwable t# + (println (str (:zen (meta #'~test-function)) "\n" + (:name (meta #'~test-function)) + " returned " t#)) (System/exit 1)))) (meditate-on test-truth)