aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-19 15:00:46 +0200
committeradamw <adam@warski.org>2017-07-19 15:00:46 +0200
commitcc475bfae8163836c89ea64726e5e5d4d2fa36d3 (patch)
treeec9c111a0955b7c710771b441e872d9ab7e64c0e
parent5aaac06c2d5ea122470ee7b27277ac0747e767d1 (diff)
downloadsttp-cc475bfae8163836c89ea64726e5e5d4d2fa36d3.tar.gz
sttp-cc475bfae8163836c89ea64726e5e5d4d2fa36d3.tar.bz2
sttp-cc475bfae8163836c89ea64726e5e5d4d2fa36d3.zip
Better non-compilation tests
-rw-r--r--build.sbt3
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala39
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala10
3 files changed, 39 insertions, 13 deletions
diff --git a/build.sbt b/build.sbt
index 248c62d..0c5da52 100644
--- a/build.sbt
+++ b/build.sbt
@@ -78,5 +78,6 @@ lazy val tests: Project = (project in file("tests"))
"com.typesafe.scala-logging" %% "scala-logging" % "3.5.0",
"com.github.pathikrit" %% "better-files" % "2.17.1",
"ch.qos.logback" % "logback-classic" % "1.2.3"
- ).map(_ % "test")
+ ).map(_ % "test"),
+ libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % "test"
) dependsOn (core, akkaHttpHandler)
diff --git a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
index 0d0c012..057ba9e 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
@@ -2,22 +2,37 @@ package com.softwaremill.sttp
import org.scalatest.{FlatSpec, Matchers}
+import scala.tools.reflect.ToolBoxError
+
class IllTypedTests extends FlatSpec with Matchers {
"compilation" should "fail when trying to stream using the default handler" in {
- """
- import akka.stream.scaladsl.Source
- import akka.util.ByteString
- import java.net.URI
- implicit val sttpHandler = HttpURLConnectionSttpHandler
- sttp.get(new URI("http://example.com")).response(asStream[Source[ByteString, Any]]).send()
- """ shouldNot typeCheck
+ val thrown = intercept[ToolBoxError] {
+ EvalScala(
+ """
+ import com.softwaremill.sttp._
+ import akka.stream.scaladsl.Source
+ import akka.util.ByteString
+ import java.net.URI
+ implicit val sttpHandler = HttpURLConnectionSttpHandler
+ sttp.get(new URI("http://example.com")).response(asStream[Source[ByteString, Any]]).send()
+ """)
+ }
+
+ thrown.getMessage should include(
+ "could not find implicit value for parameter handler: com.softwaremill.sttp.SttpHandler[R,akka.stream.scaladsl.Source[akka.util.ByteString,Any]]")
}
"compilation" should "fail when trying to send a request without giving an URL" in {
- """
- import java.net.URI
- implicit val sttpHandler = HttpURLConnectionSttpHandler
- sttp.send()
- """ shouldNot typeCheck
+ val thrown = intercept[ToolBoxError] {
+ EvalScala("""
+ import com.softwaremill.sttp._
+ import java.net.URI
+ implicit val sttpHandler = HttpURLConnectionSttpHandler
+ sttp.send()
+ """)
+ }
+
+ thrown.getMessage should include(
+ "This is a partial request, the method & url are not specified")
}
}
diff --git a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala
index bc7eccd..6d83848 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala
@@ -48,3 +48,13 @@ trait ForceWrapped extends ScalaFutures { this: Suite =>
def force()(implicit fwv: ForceWrappedValue[R]): T = fwv.force(wrapped)
}
}
+
+object EvalScala {
+ import scala.tools.reflect.ToolBox
+
+ def apply(code: String): Any = {
+ val m = scala.reflect.runtime.currentMirror
+ val tb = m.mkToolBox()
+ tb.eval(tb.parse(code))
+ }
+}