A Gotcha: test.core/thrown?

Table of Contents

https://clojureverse.org/t/a-gotcha-test-core-thrown/5595/1

Clojure is generally such a pristine and sensible language, it took me some debugging time to find out why this was failing:

  (is
   (let [proctorless-rmap {:tester (:id tester)
                           :test (:id this-test)}]
     (thrown? Exception (xreg/register-for-exam proctorless-rmap)) "no proctor should fail"))
;; Unable to resolve symbol: thrown? in this context

Trying to solve this at the repl, I was stumped for quite a while by why I couldn’t locate the thrown? function with C-c C-. to locate function definitions. I checked my Clojure version, my syntax, and FINALLY the core documentation on clojure.test/is, which revealed that “thrown? is a special form” – hence the reason I couldn’t locate it as a function or macro itself.

On the plus side, I was able to use for the first time the strict parens function sp-convolute-sexp to rewrite this sensibly in one keystroke (after putting my cursor after the let’s vector bracket):

(testing "Registration"
    (let [proctorless-rmap {:tester (:id tester)
                            :test (:id this-test)}]
      (is (thrown? Exception (xreg/register-for-exam proctorless-rmap)) "no proctor should fail"))
    (is false "with proctor should pass")
    (is false "Should be an exam registered now"))

This is one more reason I generally dislike macros (yeah, I know that makes me a Lisp infidel…): they can break the syntactic consistency and tooling that go so beautifully with Lisp and be far harder to debug than Clojure usually is. At least I got to convolute, so it wasn’t a COMPLETE waste of 30 minutes.

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist