Skip to content

Commit fa31fb6

Browse files
committed
Enable Humane Test Output Compatibility
1 parent 5fe79eb commit fa31fb6

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# Initial version 1.0.0
1+
# Version 1.1.0 in progress
2+
3+
* If Paul Stadig's Humane Test Output is available (on the classpath), failure reporting is automatically made compatible with it. Expectations that use data structure "equality" (the `=?` extension to `is`) will produce "humane" output for failures, showing differences. #1
4+
5+
# Initial version 1.0.1

deps.edn

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{:aliases
22
{:test {:extra-paths ["test"]}
3+
:humane {:extra-deps {pjstadig/humane-test-output {:mvn/version "RELEASE"}}}
34
:runner
45
{:extra-deps {com.cognitect/test-runner
56
{:git/url "https://github.com/cognitect-labs/test-runner"

src/expectations/clojure/test.clj

+23-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
88
to clojure.test functionality.
99
1010
We do not support ClojureScript in clojure.test mode, sorry."
11-
(:require [clojure.string :as str]
11+
(:require [clojure.data :as data]
12+
[clojure.string :as str]
1213
[clojure.test :as t]))
1314

15+
(def humane-test-output?
16+
"If Humane Test Output is available, activate it, and enable compatibility
17+
of our =? with it."
18+
(try
19+
(require 'pjstadig.humane-test-output)
20+
((resolve 'pjstadig.humane-test-output/activate!))
21+
true
22+
(catch Throwable _)))
23+
1424
;; stub functions for :refer compatibility:
1525
(defn- bad-usage [s]
1626
`(throw (IllegalArgumentException.
@@ -30,16 +40,24 @@
3040
(let [[_ e a] form]
3141
`(let [e# ~e
3242
a# ~a
33-
r# (if (fn? e#) (e# a#) (= e# a#))]
43+
r# (if (fn? e#) (e# a#) (= e# a#))
44+
humane?# (and humane-test-output? (not (fn? e#)))]
3445
(if r#
3546
(t/do-report {:type :pass, :message ~msg,
3647
:expected '~form, :actual (if (fn? e#)
3748
(list '~e a#)
3849
a#)})
3950
(t/do-report {:type :fail, :message ~msg,
40-
:expected '~form, :actual (if (fn? e#)
41-
(list '~'not (list '~e a#))
42-
(list '~'not (list '~'=? e# a#)))}))
51+
:diffs (if humane?#
52+
[[a# (take 2 (data/diff e# a#))]]
53+
[])
54+
:expected (if humane?# e# '~form)
55+
:actual (cond (fn? e#)
56+
(list '~'not (list '~e a#))
57+
humane?#
58+
[a#]
59+
:else
60+
(list '~'not (list '~'=? e# a#)))}))
4361
r#)))
4462

4563
(defmacro ?

0 commit comments

Comments
 (0)