summaryrefslogtreecommitdiff
path: root/cask/test
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-07-26 11:58:04 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-07-26 11:58:04 +0800
commitcdc254b077235efc8a1ad1158d2a0245730262c6 (patch)
tree9358e692a252cd7a14b1ebd8a1c626983a935977 /cask/test
parent9326dfd92a9fc120c2cdd892575486193281fb26 (diff)
downloadcask-cdc254b077235efc8a1ad1158d2a0245730262c6.tar.gz
cask-cdc254b077235efc8a1ad1158d2a0245730262c6.tar.bz2
cask-cdc254b077235efc8a1ad1158d2a0245730262c6.zip
Provide proper compilation error messages around mis-used decorators and add compileError tests
Diffstat (limited to 'cask/test')
-rw-r--r--cask/test/src/test/cask/FailureTests.scala53
1 files changed, 53 insertions, 0 deletions
diff --git a/cask/test/src/test/cask/FailureTests.scala b/cask/test/src/test/cask/FailureTests.scala
new file mode 100644
index 0000000..fcfed79
--- /dev/null
+++ b/cask/test/src/test/cask/FailureTests.scala
@@ -0,0 +1,53 @@
+package test.cask
+
+import cask.model.ParamContext
+import utest._
+
+object FailureTests extends TestSuite {
+ class myDecorator extends cask.Routes.Decorator {
+ def getParamValues(ctx: ParamContext) = Map("extra" -> 31337)
+ }
+ val tests = Tests{
+
+ 'mismatchedDecorators - {
+ utest.compileError("""
+ object Decorated extends cask.MainRoutes{
+ @cask.get("/hello/:world")
+ def hello(world: String)(extra: Int) = world + extra
+ initialize()
+ }
+ """).msg ==>
+ "Endpoint hello's number of parameter lists (2) doesn't match number of decorators (1)"
+
+ utest.compileError("""
+ object Decorated extends cask.MainRoutes{
+ @myDecorator()
+ @cask.get("/hello/:world")
+ def hello(world: String)= world
+ initialize()
+ }
+ """).msg ==>
+ "Endpoint hello's number of parameter lists (1) doesn't match number of decorators (2)"
+
+ utest.compileError("""
+ object Decorated extends cask.MainRoutes{
+ @cask.get("/hello/:world")
+ @myDecorator()
+ def hello(world: String)(extra: Int)= world
+ initialize()
+ }
+ """).msg ==>
+ "Last annotation applied to a function must be an instance of Endpoint, not test.cask.FailureTests.myDecorator"
+
+ utest.compileError("""
+ object Decorated extends cask.MainRoutes{
+ @cask.get("/hello/:world")
+ @cask.get("/hello/:world")
+ def hello(world: String)(extra: Int)= world
+ initialize()
+ }
+ """).msg ==>
+ "You can only apply one Endpoint annotation to a function, not 2 in cask.endpoints.get, cask.endpoints.get"
+ }
+ }
+}