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

View File

@ -1,22 +0,0 @@
<project name="functional-koans" default="test">
<description>
functional-koans
</description>
<path id="classpath">
<path location="src"/>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="test" description="Run tests">
<java fork="true" classname="clojure.main" failonerror="true">
<classpath>
<path refid="classpath"/>
<path location="koans"/>
</classpath>
<arg value="koans/path_to_enlightenment.clj"/>
</java>
</target>
</project>

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 (load "about-asserts")
'clojure.test)
(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 [] (meditate-on test-truth)
(filter (meditate-on test-assert-equality)
#(re-find #"-test" (str %)) (find-namespaces-in-dir (java.io.File. ".")))) (println "You have achieved clojure zen. Go out into the universe and spread your newfound knowledge.")
(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)))

9
path_to_enlightenment Executable file
View File

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