Improve clojurescript output formatting
This commit is contained in:
parent
a36032da5a
commit
ae2962fd72
2 changed files with 105 additions and 137 deletions
|
@ -2,7 +2,8 @@
|
|||
#?(:clj (:use [clojure.test]))
|
||||
(:require #?@(:clj [[clojure.pprint :as pp]]
|
||||
:cljs [[cljs.pprint :as pp :include-macros true]
|
||||
[cljs.test :refer [inc-report-counter! testing-vars-str testing-contexts-str get-current-env]]])))
|
||||
[cljs.test :refer [inc-report-counter! testing-vars-str testing-contexts-str get-current-env]]]))
|
||||
#?(:cljs (:import [goog.string StringBuffer])))
|
||||
|
||||
(defn- print-seq [aseq]
|
||||
(pp/pprint-logical-block
|
||||
|
@ -39,24 +40,48 @@
|
|||
:cljs (:testing-contexts (get-current-env)))
|
||||
(println (testing-contexts-str)))
|
||||
(when message (println message))
|
||||
(binding [*out* (pp/get-pretty-writer *out*)]
|
||||
(let [print-expected (fn [actual]
|
||||
(print "expected: ")
|
||||
(pp/pprint expected)
|
||||
(print " actual: ")
|
||||
(pp/pprint actual))]
|
||||
(if (seq diffs)
|
||||
(doseq [[actual [a b]] diffs]
|
||||
(print-expected actual)
|
||||
(print " diff:")
|
||||
(if a
|
||||
(do (print " - ")
|
||||
(pp/pprint a)
|
||||
(print " + "))
|
||||
(print " + "))
|
||||
(when b
|
||||
(pp/pprint b)))
|
||||
(print-expected actual)))))
|
||||
#?(:clj (binding [*out* (pp/get-pretty-writer *out*)]
|
||||
(let [print-expected (fn [actual]
|
||||
(print "expected: ")
|
||||
(pp/pprint expected)
|
||||
(print " actual: ")
|
||||
(pp/pprint actual))]
|
||||
(if (seq diffs)
|
||||
(doseq [[actual [a b]] diffs]
|
||||
(print-expected actual)
|
||||
(print " diff:")
|
||||
(if a
|
||||
(do (print " - ")
|
||||
(pp/pprint a)
|
||||
(print " + "))
|
||||
(print " + "))
|
||||
(when b
|
||||
(pp/pprint b)))
|
||||
(print-expected actual))))
|
||||
:cljs (let [sb (StringBuffer.)]
|
||||
(binding [*out* (pp/get-pretty-writer (StringBufferWriter. sb))]
|
||||
(let [print-expected (fn [actual]
|
||||
(-write *out* "expected: ")
|
||||
(pp/pprint expected *out*)
|
||||
(-write *out* " actual: ")
|
||||
(pp/pprint actual *out*)
|
||||
(*print-fn* (str sb))
|
||||
(.clear sb)
|
||||
)]
|
||||
(if (seq diffs)
|
||||
(doseq [[actual [a b]] diffs]
|
||||
(print-expected actual)
|
||||
(-write *out* " diff:")
|
||||
(if a
|
||||
(do (-write *out* " - ")
|
||||
(pp/pprint a *out*)
|
||||
(-write *out* " + "))
|
||||
(-write *out* " + "))
|
||||
(when b
|
||||
(pp/pprint b *out*))
|
||||
(*print-fn* (str sb))
|
||||
(.clear sb))
|
||||
(print-expected actual)))))))
|
||||
|
||||
(defn define-fail-report []
|
||||
#?(:clj (defmethod report :fail [& args]
|
||||
|
|
179
test/fixtures/test_output_cljs
vendored
179
test/fixtures/test_output_cljs
vendored
|
@ -5,163 +5,106 @@ Testing pjstadig.humane-test-output.formatting-test
|
|||
|
||||
FAIL in (t-formatting) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL
|
||||
expected:
|
||||
{:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
expected: {:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
actual: {:fo :bar}
|
||||
|
||||
actual:
|
||||
{:fo :bar}
|
||||
|
||||
diff:
|
||||
-
|
||||
{:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
|
||||
+
|
||||
{:fo :bar}
|
||||
diff: - {:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
+ {:fo :bar}
|
||||
|
||||
|
||||
FAIL in (t-formatting) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL
|
||||
expected:
|
||||
{:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
expected: {:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
actual: {:foo :bar}
|
||||
|
||||
actual:
|
||||
{:foo :bar}
|
||||
|
||||
diff:
|
||||
-
|
||||
{:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
|
||||
+
|
||||
|
||||
FAIL in (t-formatting) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL
|
||||
expected:
|
||||
{:foo :bar}
|
||||
|
||||
actual:
|
||||
{:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
|
||||
diff:
|
||||
+
|
||||
{:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
diff: - {:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
|
||||
|
||||
FAIL in (t-formatting) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL
|
||||
expected:
|
||||
{:foo :bar, :baz :quux}
|
||||
expected: {:foo :bar}
|
||||
actual: {:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
|
||||
actual:
|
||||
{:foo :bar, :baz :quux}
|
||||
|
||||
diff:
|
||||
+
|
||||
expected:
|
||||
{:foo :bar, :baz :quux}
|
||||
|
||||
actual:
|
||||
{:fo :bar, :baz :quux}
|
||||
|
||||
diff:
|
||||
-
|
||||
{:foo :bar}
|
||||
|
||||
+
|
||||
{:fo :bar}
|
||||
|
||||
expected:
|
||||
{:foo :bar, :baz :quux}
|
||||
|
||||
actual:
|
||||
{:fo :bar, :baz :quux}
|
||||
|
||||
diff:
|
||||
-
|
||||
{:foo :bar}
|
||||
|
||||
+
|
||||
{:fo :bar}
|
||||
diff: + {:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}
|
||||
|
||||
|
||||
FAIL in (t-formatting) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL
|
||||
expected:
|
||||
(list? foo)
|
||||
expected: {:foo :bar, :baz :quux}
|
||||
actual: {:foo :bar, :baz :quux}
|
||||
|
||||
actual:
|
||||
(not
|
||||
(list?
|
||||
{:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}))
|
||||
|
||||
diff: + expected: {:foo :bar, :baz :quux}
|
||||
actual: {:fo :bar, :baz :quux}
|
||||
|
||||
diff: - {:foo :bar}
|
||||
+ {:fo :bar}
|
||||
|
||||
expected: {:foo :bar, :baz :quux}
|
||||
actual: {:fo :bar, :baz :quux}
|
||||
|
||||
diff: - {:foo :bar}
|
||||
+ {:fo :bar}
|
||||
|
||||
|
||||
FAIL in (t-formatting) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL
|
||||
expected: (list? foo)
|
||||
actual: (not
|
||||
(list?
|
||||
{:foo :bar,
|
||||
:baz :quux,
|
||||
:something "a long string?",
|
||||
:another-key "and another value"}))
|
||||
|
||||
|
||||
FAIL in (t-macro-wrapping) (:)
|
||||
|
||||
THIS ONE SHOULD ALSO FAIL
|
||||
expected:
|
||||
(clojure.core/= 1 2)
|
||||
|
||||
actual:
|
||||
(not (clojure.core/= 1 2))
|
||||
expected: (clojure.core/= 1 2)
|
||||
actual: (not (clojure.core/= 1 2))
|
||||
|
||||
|
||||
Testing pjstadig.humane-test-output.records-test
|
||||
|
||||
FAIL in (t-records) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL these should not print as plain maps
|
||||
expected:
|
||||
#pjstadig.humane-test-output.records-test.ARecord{:foo :foo}
|
||||
expected: #pjstadig.humane-test-output.records-test.ARecord{:foo :foo}
|
||||
actual: #pjstadig.humane-test-output.records-test.ARecord{:foo :bar}
|
||||
|
||||
actual:
|
||||
#pjstadig.humane-test-output.records-test.ARecord{:foo :bar}
|
||||
|
||||
diff:
|
||||
-
|
||||
{:foo :foo}
|
||||
|
||||
+
|
||||
{:foo :bar}
|
||||
diff: - {:foo :foo}
|
||||
+ {:foo :bar}
|
||||
|
||||
|
||||
FAIL in (t-records) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL there should be a diff here
|
||||
expected:
|
||||
#pjstadig.humane-test-output.records-test.ARecord{:foo :foo}
|
||||
expected: #pjstadig.humane-test-output.records-test.ARecord{:foo :foo}
|
||||
actual: {:foo :foo}
|
||||
|
||||
actual:
|
||||
{:foo :foo}
|
||||
|
||||
diff:
|
||||
+
|
||||
|
||||
FAIL in (t-records) (:)
|
||||
THESE TESTS ARE INTENDED TO FAIL and here
|
||||
expected:
|
||||
#pjstadig.humane-test-output.records-test.ARecord{:foo :foo}
|
||||
expected: #pjstadig.humane-test-output.records-test.ARecord{:foo :foo}
|
||||
actual: #pjstadig.humane-test-output.records-test.BRecord{:foo :foo}
|
||||
|
||||
actual:
|
||||
#pjstadig.humane-test-output.records-test.BRecord{:foo :foo}
|
||||
|
||||
diff:
|
||||
+
|
||||
|
||||
Ran 4 tests containing 10 assertions.
|
||||
9 failures, 0 errors.
|
||||
|
|
Loading…
Reference in a new issue