Use indented output.

This commit is contained in:
Paul Stadig 2014-03-26 21:08:04 -04:00
parent c017760acf
commit 8ad500acf4
3 changed files with 45 additions and 50 deletions

View file

@ -19,37 +19,31 @@
You get this: You get this:
: FAIL in (a-test) (humane_test_output_test.clj:7) : FAIL in (a-test) (humane_test_output_test.clj:7)
: FIXME, I fail. : FIXME, I fail.
: expected: : expected: {:another-key "and another value",
: {:another-key "and another value",
: :foo :bar, : :foo :bar,
: :something "a long string?", : :something "a long string?",
: :baz :quux} : :baz :quux}
: : actual: {:fo :bar}
: actual: : diff: {:baz :quux,
: {:another-key "and another value",
: :something "a long string?", : :something "a long string?",
: :fo :bar, : :foo :bar,
: :baz :quux} : :another-key "and another value"}
:
: diff:
: {:foo :bar}
: {:fo :bar} : {:fo :bar}
: :
: FAIL in (a-test) (humane_test_output_test.clj:11) : FAIL in (a-test) (humane_test_output_test.clj:10)
: FIXME, I fail. : FIXME, I fail.
: expected: : expected: {:foo :bar, :baz :quux}
: {:foo :bar, :baz :quux} : actual: {:fo :bar, :baz :quux}
: diff: {:foo :bar}
: {:fo :bar}
: actual: {:foo :bar, :baz :quux}
: diff: nil
: nil
: :
: actual: : FAIL in (a-test) (humane_test_output_test.clj:13)
: ({:foo :bar, :baz :quux} {:fo :bar, :baz :quux})
:
: FAIL in (a-test) (humane_test_output_test.clj:14)
: FIXME, I fail. : FIXME, I fail.
: expected: : expected: (list? foo)
: (list? foo) : actual: (not
:
: actual:
: (not
: (list? : (list?
: {:another-key "and another value", : {:another-key "and another value",
: :foo :bar, : :foo :bar,

View file

@ -1,6 +1,6 @@
(ns pjstadig.humane-test-output (ns pjstadig.humane-test-output
(:use [clojure.data] (:use [clojure.data]
[clojure.pprint :only [get-pretty-writer pprint pprint-indent pprint-logical-block write]] [clojure.pprint :only [get-pretty-writer pprint]]
[clojure.test])) [clojure.test]))
(defmethod assert-expr '= [msg [_ a & more]] (defmethod assert-expr '= [msg [_ a & more]]
@ -10,26 +10,28 @@
(if result# (if result#
(do-report {:type :pass, :message ~msg, (do-report {:type :pass, :message ~msg,
:expected a#, :actual more#}) :expected a#, :actual more#})
(do-report (merge {:type :fail, :message ~msg, (do-report {:type :fail, :message ~msg,
:expected a#, :actual more#} :expected a#, :actual more#,
(if (= (count more#) 1) :diffs (zipmap more# (map #(take 2 (diff a# %)) more#))}))
{:actual (first more#)
:diff (take 2 (diff a# (first more#)))}
{:actual more#}))))
result#)) result#))
(defmethod clojure.test/report :fail (defmethod clojure.test/report :fail
[{:keys [type expected actual diff message] :as event}] [{:keys [type expected actual diffs message] :as event}]
(with-test-out (with-test-out
(inc-report-counter :fail) (inc-report-counter :fail)
(println "\nFAIL in" (testing-vars-str event)) (println "\nFAIL in" (testing-vars-str event))
(when (seq *testing-contexts*) (println (testing-contexts-str))) (when (seq *testing-contexts*) (println (testing-contexts-str)))
(when message (println message)) (when message (println message))
(println "expected:") (binding [*out* (get-pretty-writer *out*)]
(print "expected: ")
(pprint expected) (pprint expected)
(println "\nactual:") (if (seq diffs)
(doseq [[actual [a b]] diffs]
(print " actual: ")
(pprint actual) (pprint actual)
(when-let [[a b] diff] (print " diff: ")
(println "\ndiff:")
(pprint a) (pprint a)
(pprint b)))) (print " ")
(pprint b))
(do (print " actual: ")
(pprint actual))))))

View file

@ -6,8 +6,7 @@
(testing "FIXME, I fail." (testing "FIXME, I fail."
(is (= {:foo :bar :baz :quux :something "a long string?" (is (= {:foo :bar :baz :quux :something "a long string?"
:another-key "and another value"} :another-key "and another value"}
{:fo :bar :baz :quux :something "a long string?" {:fo :bar}))
:another-key "and another value"}))
(is (= {:foo :bar :baz :quux} {:foo :bar :baz :quux} {:fo :bar :baz :quux})) (is (= {:foo :bar :baz :quux} {:foo :bar :baz :quux} {:fo :bar :baz :quux}))
(let [foo {:foo :bar :baz :quux :something "a long string?" (let [foo {:foo :bar :baz :quux :something "a long string?"
:another-key "and another value"}] :another-key "and another value"}]