commit c017760acfa686f51068d207f93bc8cfb6a80090 Author: Paul Stadig Date: Wed Mar 26 17:54:35 2014 -0400 Initial commit. diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..b28c64c --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,9 @@ +((nil + (fill-column . 80) + (whitespace-line-column . nil)) + (clojure-mode + (clojure-test-ns-segment-position . 1) + (eval ignore-errors + (require 'whitespace) + (whitespace-mode 0) + (whitespace-mode 1)))) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1405021 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/checkouts/ +/classes/ +/lib/ +/native/ +/target/ +/.lein-deps-sum +/.lein-failures +/.lein-repl-history +/.nrepl-history +/pom.xml +*jar diff --git a/README.org b/README.org new file mode 100644 index 0000000..6c9e700 --- /dev/null +++ b/README.org @@ -0,0 +1,61 @@ +#+STARTUP: hidestars showall +* Humane test output for clojure.test + Instead of this: + : FAIL in (a-test) (humane_test_output_test.clj:7) + : FIXME, I fail. + : expected: (= {:foo :bar, :baz :quux, :something "a long string?", :another-key "and another value"} {:fo :bar, :baz :quux, :something "a long string?", :another-key "and another value"}) + : actual: (not (= {:another-key "and another value", :foo :bar, :something "a long string?", :baz :quux} {:another-key "and another value", :something "a long string?", :fo :bar, :baz :quux})) + : + : FAIL in (a-test) (humane_test_output_test.clj:11) + : FIXME, I fail. + : expected: (= {:foo :bar, :baz :quux} {:foo :bar, :baz :quux} {:fo :bar, :baz :quux}) + : actual: (not (= {:foo :bar, :baz :quux} {:foo :bar, :baz :quux} {:fo :bar, :baz :quux})) + : + : FAIL in (a-test) (humane_test_output_test.clj:14) + : FIXME, I fail. + : expected: (list? foo) + : actual: (not (list? {:another-key "and another value", :foo :bar, :something "a long string?", :baz :quux})) + + You get this: + : FAIL in (a-test) (humane_test_output_test.clj:7) + : FIXME, I fail. + : expected: + : {:another-key "and another value", + : :foo :bar, + : :something "a long string?", + : :baz :quux} + : + : actual: + : {:another-key "and another value", + : :something "a long string?", + : :fo :bar, + : :baz :quux} + : + : diff: + : {:foo :bar} + : {:fo :bar} + : + : FAIL in (a-test) (humane_test_output_test.clj:11) + : FIXME, I fail. + : expected: + : {:foo :bar, :baz :quux} + : + : actual: + : ({:foo :bar, :baz :quux} {:fo :bar, :baz :quux}) + : + : FAIL in (a-test) (humane_test_output_test.clj:14) + : FIXME, I fail. + : expected: + : (list? foo) + : + : actual: + : (not + : (list? + : {:another-key "and another value", + : :foo :bar, + : :something "a long string?", + : :baz :quux})) +** License + : Copyright © Paul Stadig. All rights reserved. + : + : Distributed under the Eclipse Public License, the same as Clojure. diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..ad6d479 --- /dev/null +++ b/project.clj @@ -0,0 +1,6 @@ +(defproject pjstadig/humane-test-output "0.1.0-SNAPSHOT" + :description "Humane test output for clojure.test" + :url "http://github.com/pjstadig/humane-test-output/" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.5.1"]]) diff --git a/src/pjstadig/humane_test_output.clj b/src/pjstadig/humane_test_output.clj new file mode 100644 index 0000000..19bf37b --- /dev/null +++ b/src/pjstadig/humane_test_output.clj @@ -0,0 +1,35 @@ +(ns pjstadig.humane-test-output + (:use [clojure.data] + [clojure.pprint :only [get-pretty-writer pprint pprint-indent pprint-logical-block write]] + [clojure.test])) + +(defmethod assert-expr '= [msg [_ a & more]] + `(let [a# ~a + more# (list ~@more) + result# (apply = a# more#)] + (if result# + (do-report {:type :pass, :message ~msg, + :expected a#, :actual more#}) + (do-report (merge {:type :fail, :message ~msg, + :expected a#, :actual more#} + (if (= (count more#) 1) + {:actual (first more#) + :diff (take 2 (diff a# (first more#)))} + {:actual more#})))) + result#)) + +(defmethod clojure.test/report :fail + [{:keys [type expected actual diff message] :as event}] + (with-test-out + (inc-report-counter :fail) + (println "\nFAIL in" (testing-vars-str event)) + (when (seq *testing-contexts*) (println (testing-contexts-str))) + (when message (println message)) + (println "expected:") + (pprint expected) + (println "\nactual:") + (pprint actual) + (when-let [[a b] diff] + (println "\ndiff:") + (pprint a) + (pprint b)))) diff --git a/test/pjstadig/humane_test_output_test.clj b/test/pjstadig/humane_test_output_test.clj new file mode 100644 index 0000000..ab21392 --- /dev/null +++ b/test/pjstadig/humane_test_output_test.clj @@ -0,0 +1,14 @@ +(ns pjstadig.humane-test-output-test + (:use [clojure.test] + [pjstadig.humane-test-output])) + +(deftest a-test + (testing "FIXME, I fail." + (is (= {:foo :bar :baz :quux :something "a long string?" + :another-key "and another value"} + {:fo :bar :baz :quux :something "a long string?" + :another-key "and another value"})) + (is (= {:foo :bar :baz :quux} {:foo :bar :baz :quux} {:fo :bar :baz :quux})) + (let [foo {:foo :bar :baz :quux :something "a long string?" + :another-key "and another value"}] + (is (list? foo)))))