Throwing an exception in a test fixture is reported in a reasonable way.
Cider crashes with the exception (lein):
Exception in thread "nRepl-session-ed5a944b-ef91-4e42-ac3e-75bf00fb04d6" java.lang.NullPointerException
at clojure.lang.Symbol.intern(Symbol.java:59)
at clojure.core$symbol.invokeStatic(core.clj:579)
at clojure.core$symbol.invoke(core.clj:574)
at cider.nrepl.middleware.test$report_fixture_error.invokeStatic(test.clj:183)
at cider.nrepl.middleware.test$report_fixture_error.invoke(test.clj:173)
at cider.nrepl.middleware.test$test_vars.invokeStatic(test.clj:220)
at cider.nrepl.middleware.test$test_vars.invoke(test.clj:209)
at cider.nrepl.middleware.test$test_ns.invokeStatic(test.clj:231)
at cider.nrepl.middleware.test$test_ns.invoke(test.clj:222)
at cider.nrepl.middleware.test$test_var_query.invokeStatic(test.clj:242)
at cider.nrepl.middleware.test$test_var_query.invoke(test.clj:235)
at cider.nrepl.middleware.test$handle_test_var_query_op$fn__6270$fn__6271.invoke(test.clj:280)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:657)
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1965)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1965)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at cider.nrepl.middleware.test$handle_test_var_query_op$fn__6270.invoke(test.clj:272)
at clojure.lang.AFn.run(AFn.java:22)
at nrepl.middleware.session$session_exec$main_loop__1045$fn__1049.invoke(session.clj:171)
at nrepl.middleware.session$session_exec$main_loop__1045.invoke(session.clj:170)
at clojure.lang.AFn.run(AFn.java:22)
at java.lang.Thread.run(Thread.java:748)
or (deps.edn):
Exception in thread "nRepl-session-2a7d802b-27a1-436e-8879-658a09ad58b8" java.lang.IllegalArgumentException: no conversion to symbol
at clojure.core$symbol.invokeStatic(core.clj:596)
at clojure.core$symbol.invoke(core.clj:589)
at cider.nrepl.middleware.test$report_fixture_error.invokeStatic(test.clj:183)
at cider.nrepl.middleware.test$report_fixture_error.invoke(test.clj:173)
at cider.nrepl.middleware.test$test_vars.invokeStatic(test.clj:220)
at cider.nrepl.middleware.test$test_vars.invoke(test.clj:209)
at cider.nrepl.middleware.test$test_ns.invokeStatic(test.clj:231)
at cider.nrepl.middleware.test$test_ns.invoke(test.clj:222)
at cider.nrepl.middleware.test$test_var_query.invokeStatic(test.clj:242)
at cider.nrepl.middleware.test$test_var_query.invoke(test.clj:235)
at cider.nrepl.middleware.test$handle_test_var_query_op$fn__5941$fn__5942.invoke(test.clj:280)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:665)
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at cider.nrepl.middleware.test$handle_test_var_query_op$fn__5941.invoke(test.clj:272)
at clojure.lang.AFn.run(AFn.java:22)
at nrepl.middleware.session$session_exec$main_loop__1036$fn__1040.invoke(session.clj:171)
at nrepl.middleware.session$session_exec$main_loop__1036.invoke(session.clj:170)
at clojure.lang.AFn.run(AFn.java:22)
at java.lang.Thread.run(Thread.java:748)
Create a new project with either:
clj -A:new app nrepl-test/app
or
lein new app nrepl-test
Open the test file test/nrepl_test/core_test.clj (in the lein project) with emacs.
Add a fixture that throws an exception like so:
(defn setup []
(throw (Exception. "whoopsie")))
(use-fixtures :each setup)
(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
M-x cider-jack-in-clj
M-x cider-auto-test-mode
M-x cider-eval-buffer
Your REPL has now crashed with the above exception and does not accept further input.
(lein)
;; Connected to nREPL server - nrepl://localhost:40425
;; CIDER 0.23.0 (Lima), nREPL 0.6.0
;; Clojure 1.9.0, Java 13.0.1
(deps)
;; Connected to nREPL server - nrepl://localhost:42241
;; CIDER 0.23.0 (Lima), nREPL 0.6.0
;; Clojure 1.10.1, Java 13.0.1
lein 2.9.1
26.3
Arch Linux, up-to-date as of 1/20/2019
Ohhhhh dear.... it seems trying to build a simplified example... well I done oversimplified. My above example can be fixed by making my setup function take an argument. You know, like a fixture is supposed to.
(defn setup [f]
(throw err)
(f))
Ooops.
Ok actual problem. If the exception thrown is was not originally generated in the test fixture, but is instead being re-thrown (in other words, the setup does not actually appear in the exceptions stacktrace) it crashes cider. Interestingly the actual exception is the same. The reason this is happening in my case is because the fixture is doing a bunch of work with Aleph, and is re-throwing an exception that came from a completely different thread.
A simple way to reproduce the error is:
(defn generate-err []
(Exception. "Oops"))
(def err (generate-err))
(defn setup [f]
(throw err)
(f))
(use-fixtures :each setup)
(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
I'm like 90% sure I'm reporting a real problem this time.
Most helpful comment
Ohhhhh dear.... it seems trying to build a simplified example... well I done oversimplified. My above example can be fixed by making my setup function take an argument. You know, like a fixture is supposed to.
Ooops.
Ok actual problem. If the exception thrown is was not originally generated in the test fixture, but is instead being re-thrown (in other words, the
setupdoes not actually appear in the exceptions stacktrace) it crashes cider. Interestingly the actual exception is the same. The reason this is happening in my case is because the fixture is doing a bunch of work with Aleph, and is re-throwing an exception that came from a completely different thread.A simple way to reproduce the error is:
I'm like 90% sure I'm reporting a real problem this time.