Skip to content

akka-http ScalatestRouteTest example doesn't compile after update to 2.12.5 #10800

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

Closed
SeriousSoftware opened this issue Mar 23, 2018 · 11 comments

Comments

@SeriousSoftware
Copy link

After updating in sbt the scalaVersion from 2.12.4 to 2.12.5 the compiler reports an "value should is not a member of String" or "value shouldEqual is not a member of String" error.

This source code is here given.

The symptom manifests itself typically at the version bump.

@SethTisue
Copy link
Member

SethTisue commented Mar 23, 2018

are you on Java 9 or 10, and is there a "macro implementation not found" message somewhere in the full trace of your attempt? if so, it's scala/scala-dev#480 and you need to downgrade to Java 8 or wait for 2.12.6

this information is now in the 2.12.5 blog post and release notes (it wasn't, initially)

@SeriousSoftware
Copy link
Author

I am running the compiler ina Java 9 environment, but the compiler reports only the errors as a compile error on the should/shouldEqual ScalaTest keywords and terminates normally.

Error message is "macro implementation not found" is not shown.

@SethTisue
Copy link
Member

can you link to a complete log of the entire compilation session?

@SeriousSoftware
Copy link
Author

SeriousSoftware commented Mar 23, 2018

import org.scalatest.{ Matchers, WordSpec }
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.http.scaladsl.server._
import Directives._

class FullTestKitExampleSpec extends WordSpec with Matchers with ScalatestRouteTest {

  val smallRoute =
    get {
      pathSingleSlash {
        complete {
          "Captain on the bridge!"
        }
      } ~
      path("ping") {
        complete("PONG!")
      }
    }

  "The service" should {

    "return a greeting for GET requests to the root path" in {
      // tests:
      Get() ~> smallRoute ~> check {
        responseAs[String] shouldEqual "Captain on the bridge!"
      }
    }

    "return a 'PONG!' response for GET requests to /ping" in {
      // tests:
      Get("/ping") ~> smallRoute ~> check {
        responseAs[String] shouldEqual "PONG!"
      }
    }

    "leave GET requests to other paths unhandled" in {
      // tests:
      Get("/kermit") ~> smallRoute ~> check {
        handled shouldBe false
      }
    }

    "return a MethodNotAllowed error for PUT requests to the root path" in {
      // tests:
      Put() ~> Route.seal(smallRoute) ~> check {
        status shouldEqual StatusCodes.MethodNotAllowed
        responseAs[String] shouldEqual "HTTP method not allowed, supported methods: GET"
      }
    }
  }
}

Results in:

[info] Compiling 1 Scala source to C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\target\scala-2.12\test-classes ...
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\src\test\scala\org\apache\olingo\example\FullTestKitExampleSpec.scala:35:17: value should is not a member of String
[error]   "The service" should {
[error]                 ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\src\test\scala\org\apache\olingo\example\FullTestKitExampleSpec.scala:40:28: value shouldEqual is not a member of String
[error]         responseAs[String] shouldEqual "Captain on the bridge!"
[error]                            ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\src\test\scala\org\apache\olingo\example\FullTestKitExampleSpec.scala:47:28: value shouldEqual is not a member of String
[error]         responseAs[String] shouldEqual "PONG!"
[error]                            ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\src\test\scala\org\apache\olingo\example\FullTestKitExampleSpec.scala:54:17: value shouldBe is not a member of Boolean
[error]         handled shouldBe false
[error]                 ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\src\test\scala\org\apache\olingo\example\FullTestKitExampleSpec.scala:61:16: value shouldEqual is not a member of akka.http.scaladsl.model.StatusCode
[error]         status shouldEqual StatusCodes.MethodNotAllowed
[error]                ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\akka-http-olingo-extension0\src\test\scala\org\apache\olingo\example\FullTestKitExampleSpec.scala:62:28: value shouldEqual is not a member of String
[error]         responseAs[String] shouldEqual "HTTP method not allowed, supported methods: GET"
[error]                            ^
[error] 6 errors found
[error] (Test / compileIncremental) Compilation failed
[


Using scalatest 3.0.+

@SethTisue
Copy link
Member

I'm not able to reproduce the problem:

sbt:si-10800> show scalaVersion
[info] 2.12.5
sbt:si-10800> compile
[info] Updating ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/tisue/tmp/SI-10800/target/scala-2.12/classes ...
[info] Done compiling.
[success] Total time: 2 s, completed Mar 23, 2018 12:42:23 PM

here are the files I'm using: https://gist.github.com/SethTisue/8a0b12bff642393049caae9e6f98883c

@SeriousSoftware
Copy link
Author

Result of your code in my Java 9.0.4 system:

[new-folder-2-]> show scalaVersion
[info] 2.12.5
[new-folder-2-]> compile
[info] Compiling 1 Scala source to C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\target\scala-2.12\classes ...
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\S.scala:21:17: value should is not a member of String
[error]   "The service" should {
[error]                 ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\S.scala:26:28: value shouldEqual is not a member of String
[error]         responseAs[String] shouldEqual "Captain on the bridge!"
[error]                            ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\S.scala:33:28: value shouldEqual is not a member of String
[error]         responseAs[String] shouldEqual "PONG!"
[error]                            ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\S.scala:40:17: value shouldBe is not a member of Boolean
[error]         handled shouldBe false
[error]                 ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\S.scala:47:16: value shouldEqual is not a member of akka.http.scaladsl.model.StatusCode
[error]         status shouldEqual StatusCodes.MethodNotAllowed
[error]                ^
[error] C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\S.scala:48:28: value shouldEqual is not a member of String
[new-folder-2-][error]         responseAs[String] shouldEqual "HTTP method not allowed, supported methods: GET"
> [error]                            ^
[error] 6 errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed 2018-03-23T20:00 W12

Any idea?

@SeriousSoftware
Copy link
Author

Modified scalaVersion:

[new-folder-2-]> show scalaVersion
[info] 2.12.4
[new-folder-2-]> compile
[info] Updating ...
[info] Done updating.
[info] Compiling 1 Scala source to C:\Users\FransAdm.LAPTOP-M05O0II\IdeaProjects\New folder (2)\target\scala-2.12\classes ...
[info] Done compiling.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:/C:/Users/FransAdm.LAPTOP-M05O0II/.sbt/boot/scala-2.12.4/org.scala-sbt/sbt/1.1.0/protobuf-java-3.3.1.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[success] Total time: 11 s, completed 2018-03-23T20:22 W12

@SethTisue
Copy link
Member

perhaps there is some Windows specific issue here. (I’m on MacOS.)

@hrhino
Copy link

hrhino commented Mar 26, 2018

I can reproduce this on OS X, and it is indeed yet another manifestation of scala/scala-dev#480. (The telltale phrase from that ticket doesn't show up because the failure to load the macro is suppressed by the implicit view search, so you get the generic "a is not a member of B" message instead.)

With -Ymacro-debug-verbose you see:

sbt:wat> compile
[info] Compiling 1 Scala source to /Users/hhoughton/tmp/wat/target/scala-2.12/classes ...
...
macroExpand: expander = scala.tools.nsc.typechecker.Macros$DefMacroExpander@2b21a2d6, expandee = Select[1](Select[2](This[3](TypeName("source")), org.scalactic.source.Position#22484), TermName("here")#46214)
[1] TypeRef(ThisType(org.scalactic.source#16474), org.scalactic.source.Position#22483, List())
[2] SingleType(ThisType(org.scalactic.source#16474), org.scalactic.source.Position#22484)
[3] ThisType(org.scalactic.source#16474), desugared = ()
looking for macro implementation: macro method here
resolving macro implementation as org.scalactic.source.PositionMacro$.genPosition (isBundle = false)
macro runtime failed to load: java.lang.NullPointerException
macro expansion has failed: macro implementation not found: here
(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
undetParam added: type T
undetParam inferred: type T as String
[error] /Users/hhoughton/tmp/wat/src/main/scala/S.scala:21:17: value should is not a member of String
[error]   "The service" should {
[error]                 ^

So (as Seth said) you should either use java 8 or wait for 2.12.6 (which is currently targeted for 9 April, last I heard).

@SethTisue
Copy link
Member

thanks Harrison. (I wonder what I did wrong when trying to reproduce it, but oh well.)

@floatastic
Copy link

Happened to me just now, but it's working if instead of Matchers you import Matchers._.

@SethTisue, maybe you're IDE aded that import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants