dissoc

A Significant clojure.test Enhancement

I’d wager any Clojure programmer has come across CLJ-2525. You know, when your test fixture throws an error and doesn’t mention any of your testing strings? Just “Uncaught exception, not in assertion”, leaving you momentarily dumbfounded about which fixture or doseq branch caused it? That. I’m guessing I’ve triggered this hundreds of times.

Who knows how many times Alex Miller (the issue reporter) has witnessed it, given that he probably conducts yearly Clojure workshops. Surely this is something everyone hits in their first week (hour?) of Clojure. I think it’s a brilliant observation. Update: Alex tells me he forwarded this issue from someone else.

Well, I’m proposing a fix. It’s heuristic-based, so I need feedback before I propose it upstream. It also introduces a new internal variable to clojure.test, which may need to be leveraged by libraries that wrap or reimplement clojure.test like test.chuck. The latter (unresolved) point is why I’ve sat on this for a year.

Here’s how to use it.

  1. Pull in my utility library fully-satisfies.
  2. Replace calls to clojure.test/{deftest,testing} to the same vars in io.github.frenchy64.fully-satisfies.uncaught-testing-contexts.

Here’s what to expect:

(deftest my-test
  (testing "please, just tell me what went wrong"
    (testing "please"
      (throw (Exception.)))
    (testing "pretty please?"
      (throw (Exception.)))))

; before
;ERROR in (my-test)
;Uncaught exception, not in assertion.

; after
;ERROR in (my-test)
;Uncaught exception, possibly thrown in testing context:
; please, just tell me what went wrong please

Please submit feedback here, especially any enthusiasm to encourage me to propose this upstream already. Any tool makers that would be affected by this change also please get in touch with your thoughts.

08 Sep 2022