From b9fa6742cfdfc8611a0aff6ef47351b0ad8f05a1 Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Sat, 23 Jan 2010 22:28:43 -0500 Subject: [PATCH] lLt's not use clojure.test. The runner can be much simpler and provide better output. I am putting the zen message as metadata on each function. The 'runner' exits on the first failure now --- build.xml | 22 ---------------------- koans/about-asserts.clj | 11 +++++++++++ koans/about_asserts_test.clj | 12 ------------ koans/path_to_enlightenment.clj | 30 ++++++++++++------------------ path_to_enlightenment | 9 +++++++++ 5 files changed, 32 insertions(+), 52 deletions(-) delete mode 100644 build.xml create mode 100644 koans/about-asserts.clj delete mode 100644 koans/about_asserts_test.clj create mode 100755 path_to_enlightenment diff --git a/build.xml b/build.xml deleted file mode 100644 index e34ac4f..0000000 --- a/build.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - functional-koans - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/koans/about-asserts.clj b/koans/about-asserts.clj new file mode 100644 index 0000000..b62ef60 --- /dev/null +++ b/koans/about-asserts.clj @@ -0,0 +1,11 @@ +(defn test-truth + #^{:zen "We shall contemplate truth by testing reality, via asserts."} + [] + (assert false)) ;; This should be true + +(defn test-assert-equality + #^{:zen "To understand reality, we must compare our expectations against reality."} + [] + (let [expected-value 0 + actual-value (+ 1 1)] + (assert (= expected-value actual-value)))) diff --git a/koans/about_asserts_test.clj b/koans/about_asserts_test.clj deleted file mode 100644 index 78b2705..0000000 --- a/koans/about_asserts_test.clj +++ /dev/null @@ -1,12 +0,0 @@ -(ns about-asserts-test - (:use clojure.test)) - -(deftest test-truth - (testing "We shall contemplate truth by testing reality, via asserts." - (assert false))) ;; This should be true - -(deftest test-assert-equality - (testing "To understand reality, we must compare our expectations against reality." - (let [expected-value 0 - actual-value (+ 1 1)] - (is (= expected-value actual-value))))) \ No newline at end of file diff --git a/koans/path_to_enlightenment.clj b/koans/path_to_enlightenment.clj index 70789e4..dfa7046 100644 --- a/koans/path_to_enlightenment.clj +++ b/koans/path_to_enlightenment.clj @@ -1,20 +1,14 @@ -(use 'clojure.contrib.find-namespaces - 'clojure.test) +(load "about-asserts") -(def exit-code (atom 0)) +(defn meditate-on + "Runs tests but exits if an assertion fails" + [test] + (try + (test) + (catch Throwable t + (println (str "Metadata zen\n" "test name failed")) + (System/exit 1)))) -(defn find-tests [] - (filter - #(re-find #"-test" (str %)) (find-namespaces-in-dir (java.io.File. ".")))) - -(defn require-tests [] - - (doseq [test (find-tests)] - (require test))) - -(require-tests) -(let [results (apply merge-with + (map test-ns (find-tests)))] - (if (or (> (results :fail) 0) - (> (results :error) 0)) - (System/exit -1) - (System/exit 0))) \ No newline at end of file +(meditate-on test-truth) +(meditate-on test-assert-equality) +(println "You have achieved clojure zen. Go out into the universe and spread your newfound knowledge.") diff --git a/path_to_enlightenment b/path_to_enlightenment new file mode 100755 index 0000000..e7c5a1a --- /dev/null +++ b/path_to_enlightenment @@ -0,0 +1,9 @@ +#!/bin/sh + +CLASSPATH=koans + +for f in lib/*.jar; do + CLASSPATH=$CLASSPATH:$f +done + +java -cp $CLASSPATH clojure.main -i koans/path_to_enlightenment.clj