-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
warnUnused is reporting on Assertions #134
Comments
Hmm thanks for the report - I think this is due to the addition of |
I think |
Do people write FP tests/test assertions? 😅 I'm probably just going to find a way to override/disable this flag if I can rather than approach the new set of 500+ errors in the |
For anyone else in the same boat who wants to disable the
The You could maybe try and only do this for your Test profiles to see if your main code body can benefit from it. In my case we have some places where we had to use Java libraries without Scala wrappers that mean this flag causes more hassle than its worth. |
Reporting the same here. We have multiple test cases with multiple assertions in it, so the change in #115 is hurting us quite bad :) Since we operate with a lot of smaller projects, upgrading the plugin and duplicating the workaround @henricook provided is not ideal. Not sure what would be the desired behaviour from sbt-tpolecat point of view... edit: the suggestion below by armanbilge is not really where we want to go - as we use both FP and OOP style :) |
It's not that crazy, something like this: for {
foo <- doFoo()
_ <- IO(assert(...))
_ <- IO(assert(...))
} yield () |
Btw, @som-snytt gave some advice in the Scala Discord, about how to silence this warning for specific classes.
|
I will make improvements for 2.13.11, so let me know if there is a useful heuristic here. It is certainly reasonable to make checks in Test less strict, but also "tests are code," etc. |
Yes, with libs like munit-cats-effect. |
With ScalaTest async testing + CE they often look like this: val assertion = for {
_ <- doSomething
result <- doSomethingElse
} yield result shouldBe someKnownValue
assertion.unsafeToFuture() |
What @henricook suggests is a totally fine way to go about disabling bits of sbt-tpolecat, although you can also use the settings DSL to do this now if you just want a one-liner, e.g. Test / tpolecatExcludeOptions += ScalacOptions.warnNonUnitStatement |
FYI, this is also triggering for Spec2/Scala 2.13 unit tests such as:
I get:
|
I took a look, and If you want to use ScalaTest this way, write your "block of asserts" as a tuple of expressions:
or use |
I've added a (perhaps slightly too prominent) warning about this to the README now - so let's close this :D |
I also had this issue and the warning in the Readme was useful, thanks for that. However, I was still having an extra issue with IntelliJ. I guess the IntelliJ SBT plugin does not parse the
More about warning suppression here: https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html No need to comment or fix anything else. Just jotting this down in case anyone else runs into it. |
This is a great fix for Intellij/Scala2 but appears be unworkable in Scala3 currently. Possibly we'll get more information in this issue: scala/scala3#18804 |
I commented on the issue. I didn't try anything out, but if it's fixed on 3.4.1, you can lobby for backport to LTS, which stands for Lobbied something. |
Hello, since 0.4.2 I am seeing Scalatest tests reporting unused on assertions that aren't the final value in a test, e.g.
I have tried disabling scalaFix in case it was conflicting but no change.
Is this intended behaviour?
The text was updated successfully, but these errors were encountered: