diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-12-09 17:32:07 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-12-11 02:42:29 +0100 |
commit | a09914ca9f7b65e839fddaeb88d318bec52245b8 (patch) | |
tree | 9249bcdc9f41dc11b45ed1f1f12090d1835f2b02 /test/files | |
parent | b9a900e5d2f32b87149f7bd4cc7531f327abf5be (diff) | |
download | scala-a09914ca9f7b65e839fddaeb88d318bec52245b8.tar.gz scala-a09914ca9f7b65e839fddaeb88d318bec52245b8.tar.bz2 scala-a09914ca9f7b65e839fddaeb88d318bec52245b8.zip |
Test possible quasiquote runtime failures
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala | 75 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/Test.scala | 1 |
2 files changed, 76 insertions, 0 deletions
diff --git a/test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala b/test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala new file mode 100644 index 0000000000..a3b6137f68 --- /dev/null +++ b/test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala @@ -0,0 +1,75 @@ +import org.scalacheck._, Prop._, Gen._, Arbitrary._ +import scala.reflect.runtime.universe._, Flag._ + +object RuntimeErrorProps extends QuasiquoteProperties("errors") { + def testFails[T](block: =>T) = test { + assertThrows[IllegalArgumentException] { + block + } + } + + property("default param anon function") = testFails { + val param = q"val x: Int = 1" + q"{ $param => x + 1 }" + } + + property("non-casedef case") = testFails { + val x = q"x" + q"foo match { case $x }" + } + + property("non-new annotation") = testFails { + val annot = q"foo" + q"@$annot def foo" + } + + property("non-valdef param") = testFails { + val param = q"foo" + q"def foo($param)" + } + + property("non-valdef class param") = testFails { + val param = q"foo" + q"class Foo($param)" + } + + property("non-typedef type param") = testFails { + val tparam = tq"T" + q"class C[$tparam]" + } + + property("non-definition refine stat") = testFails { + val stat = q"foo" + tq"Foo { $stat }" + } + + property("non-definition early def") = testFails { + val stat = q"foo" + q"class Foo extends { $stat } with Bar" + } + + property("type apply for definition") = testFails { + val defn = q"def foo" + q"$defn[foo]" + } + + property("non-val selftype") = testFails { + val foo = q"foo" + q"class Foo { $foo => }" + } + + property("for empty enums") = testFails { + val enums = List.empty[Tree] + q"for(..$enums) 0" + } + + property("for starts with non-from enum") = testFails { + val enums = fq"foo = bar" :: Nil + q"for(..$enums) 0" + } + + property("for inlalid enum") = testFails { + val enums = q"foo" :: Nil + q"for(..$enums) 0" + } +} diff --git a/test/files/scalacheck/quasiquotes/Test.scala b/test/files/scalacheck/quasiquotes/Test.scala index 0253533248..7a26fa4923 100644 --- a/test/files/scalacheck/quasiquotes/Test.scala +++ b/test/files/scalacheck/quasiquotes/Test.scala @@ -10,6 +10,7 @@ object Test extends Properties("quasiquotes") { include(LiftableProps) include(UnliftableProps) include(ErrorProps) + include(RuntimeErrorProps) include(DefinitionConstructionProps) include(DefinitionDeconstructionProps) include(DeprecationProps) |