io.github.frenchy64.fully-satisfies.uncaught-testing-contexts
Drop-in replacements for `clojure.test/{deftest,testing}` that (when used
together) enhances uncaught exception error messages with the (most likely)
testing context it was thrown from.
Example:
(deftest my-test
(testing "foo"
(doseq [v [1 2 3]]
(testing v
(assert (= 1 v))))))
With clojure.test/{deftest,testing} 1.10.3 (notice `foo 2` is not mentioned):
user=> (test-var #'my-test)
;ERROR in (my-test)
;Uncaught exception, not in assertion.
;expected: nil
;actual: java.lang.AssertionError: Assert failed: false
;...
With {deftest,testing} in this namespace (notice `foo 2` is mentioned):
user=> (test-var #'my-test)
;ERROR in (my-test)
;Uncaught exception, possibly thrown in testing context: foo 2
;expected: nil
;actual: java.lang.AssertionError: Assert failed: false
;...
*exceptional-testing-contexts*
dynamic
-run-test-body
(-run-test-body f)
For libraries that mimic clojure.test's API. f
should be a thunk that runs the test.
deftest
macro
(deftest & args)
deftest+report-uncaught-contexts
macro
(deftest+report-uncaught-contexts name & body)
Like clojure.test/deftest, except swallows uncaught exceptions
and reports them as test errors (with improved error messages via
*exceptional-testing-contexts*). This is normally done by `test-var`,
with an unhelpful error message.
Use in conjunction with `testing` in this namespace.
record-uncaught-exception-contexts
(record-uncaught-exception-contexts e)
Call when an exception is thrown in a testing context
to record the most likely *testing-contexts* to report
in *exceptional-testing-contexts*.
report-uncaught-exception
(report-uncaught-exception e)
Report an uncaught exception using *exceptional-testing-contexts* to
guess the most helpful message.
testing
macro
(testing & args)
testing+record-uncaught-contexts
macro
(testing+record-uncaught-contexts string & body)
Like clojure.test/testing, except records testing contexts on
uncaught exceptions.
Use in conjunction with `deftest` in this namespace.