cursive icon indicating copy to clipboard operation
cursive copied to clipboard

thrown? cannot be resolved

Open mtruyens opened this issue 11 years ago • 19 comments

When using Clojure Test, the thrown? test is incorrectly flagged as "cannot be resolved"

Example

(deftest xyz (is (thrown? Exception (... exception raising code ... ))))

mtruyens avatar Jan 12 '14 13:01 mtruyens

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).

cursive-ide avatar Jan 12 '14 20:01 cursive-ide

same for thrown-with-msg?.

ikitommi avatar Jan 31 '15 15:01 ikitommi

:+1:

marcomorain avatar Jan 15 '16 13:01 marcomorain

Any update on this? Lots of unresolved symbols look somewhat ugly in the tests.

lenaschoenburg avatar Feb 25 '16 08:02 lenaschoenburg

+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.

jnape avatar Mar 28 '16 21:03 jnape

hello any news ?

marco-m avatar Sep 02 '17 11:09 marco-m

yeah, would be great to see this resolved

madvas avatar Dec 13 '17 07:12 madvas

3 years, bug is still here

ai212983 avatar Jan 09 '18 17:01 ai212983

Would be great to have this bug fixed.

brjann avatar Nov 06 '18 11:11 brjann

5 years and still no fix. Is there any movement on this?

dillonredding avatar Sep 18 '19 13:09 dillonredding

Abandon hope all ye who enter here

ai212983 avatar Nov 05 '19 20:11 ai212983

Wow! I still have hope. It's 2020. Come on....

bluiska avatar Jan 02 '20 10:01 bluiska

Any possible workaround for this in the meantime?

NPException avatar Feb 01 '20 10:02 NPException

Not a blocker; can still build & run tests but would be nice to see a fix.

Lambeaux avatar Apr 21 '20 20:04 Lambeaux

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)))))

jsyrjala avatar Sep 10 '20 07:09 jsyrjala

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.

aneilbaboo avatar Oct 07 '20 15:10 aneilbaboo

image

raymcdermott avatar Jun 09 '23 09:06 raymcdermott

Workaround:

(declare thrown? thrown-with-msg?)

serioga avatar Jun 09 '23 10:06 serioga

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.

onetom avatar Mar 11 '24 08:03 onetom