cursive
cursive copied to clipboard
thrown? cannot be resolved
When using Clojure Test, the thrown? test is incorrectly flagged as "cannot be resolved"
Example
(deftest xyz (is (thrown? Exception (... exception raising code ... ))))
Yes, I'm planning to fix this case. I need to add some indexing on multimethods (which is what is
is using under the hood).
same for thrown-with-msg?
.
:+1:
Any update on this? Lots of unresolved symbols look somewhat ugly in the tests.
+1 @dignati Although to be fair, it's even worse than looking ugly in tests, because code analysis reports these "unresolved" symbols as warnings, which you will see regularly if you either manually kick off code analysis, or you commit via IntelliJ with the "Perform code analysis" checkbox; in this case, if any of the files you're committing include thrown?
or thrown-with-msg?
in their source, you'll get the warning popup, which can perhaps lead to ignoring warnings in your code due to regular false negatives.
hello any news ?
yeah, would be great to see this resolved
3 years, bug is still here
Would be great to have this bug fixed.
5 years and still no fix. Is there any movement on this?
Abandon hope all ye who enter here
Wow! I still have hope. It's 2020. Come on....
Any possible workaround for this in the meantime?
Not a blocker; can still build & run tests but would be nice to see a fix.
A related thing. First parameter to thrown?
is also marked as cannot be resolved.
Here :import for ParameterNotFoundException
is marked as unused, and it's usage in thrown? is marked as not resolved.
(ns foo.some-ns
(:require [clojure.test :refer :all])
(:import (com.amazonaws.services.simplesystemsmanagement.model ParameterNotFoundException)))
(deftest some-test
(testing "foo"
(is (thrown? ParameterNotFoundException
(do-something)))))
It looks like the issue is that thrown?
is not a function or macro. It's merely a symbol that that is treated specially by the is
macro. You can see the definition here. In other words, Cursive is reporting the symbol resolution failure the way it does for other macros that introduce new symbols.
The current solution is to disable symbol resolution for the offending macro using https://github.com/cursive-ide/cursive/issues/2417. The downside is that you lose all symbol resolution within an is
expression.
A better solution will come with https://github.com/cursive-ide/cursive/issues/147.
Workaround:
(declare thrown? thrown-with-msg?)
We have a generic test-harness
NS, which we include into every test NS, which has that declaration, what @serioga mentioned.
We have also added (:require [our.test-harness :refer :all])
to the Settings→Editor→File and Code Templates→{Clojure,ClojureScript,CLJC} Test Namespace
(documented here) template, to make sure we never see this warning.
The matcher combinators lib works this around by shipping with such declarations built-in here: https://github.com/nubank/matcher-combinators/blob/master/src/cljc/matcher_combinators/test.cljc#L22-L30
It would be nice to see some built-in solution from Cursive too.