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

This commit is contained in:
Aaron Bedra
2010-01-23 22:28:43 -05:00
parent 49e460a0b4
commit b9fa6742cf
5 changed files with 32 additions and 52 deletions

11
koans/about-asserts.clj Normal file
View File

@@ -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))))

View File

@@ -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)))))

View File

@@ -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)))
(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.")