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

master
Aaron Bedra 15 years ago
parent 49e460a0b4
commit b9fa6742cf

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

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

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

@ -1,20 +1,14 @@
(use 'clojure.contrib.find-namespaces
'clojure.test)
(def exit-code (atom 0))
(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)))
(load "about-asserts")
(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))))
(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.")

@ -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
Loading…
Cancel
Save