0

I am getting the following compiler error as I switched on the compiler flags as per sbt-toplecat.

await(myService(request).value).isLeft shouldBe true

Now compiler complains:

discarded non-Unit value
await(myService(request).value).isLeft shouldBe true
                                       ^

This shouldBe matcher is from Scalatest:

    def shouldBe(right: Any): Assertion = {
      if (!areEqualComparingArraysStructurally(leftSideValue, right)) {
        val (leftee, rightee) = Suite.getObjectsForFailureMessage(leftSideValue, right)
        val localPrettifier = prettifier // Grabbing a local copy so we don't attempt to serialize AnyShouldWrapper (since first param to indicateFailure is a by-name)
        indicateFailure(FailureMessages.wasNotEqualTo(localPrettifier, leftee, rightee), None, pos)t
      }
      else indicateSuccess(FailureMessages.wasEqualTo(prettifier, leftSideValue, right))
    }

What do I need to do to resolve this? Obviously the assertion will be true or false so I always get a non-Unit value which is then discarded.

Mojo
  • 1,152
  • 1
  • 8
  • 16

1 Answers1

1

Consider relaxing compiler flags for test confguration as this code is not run in production. Maybe simply explicitly set few flags you might like for test configuraiton like so

Test / scalacOptions := Seq(
  // few flags I want for tests
)
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • do you mean to say that nothing can be done about this due to way scalatest works? – Mojo Jun 04 '20 at 14:07
  • @Mojo Please provide example source code of full test. This should not really be an issue in ScalaTest. It is likely that somewhere you have put `Unit` return type whilst it should really be `Assertion` return type. – Mario Galic Jun 04 '20 at 14:20