Skip to content

Commit a09914c

Browse files
committed
Test possible quasiquote runtime failures
1 parent b9a900e commit a09914c

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import org.scalacheck._, Prop._, Gen._, Arbitrary._
2+
import scala.reflect.runtime.universe._, Flag._
3+
4+
object RuntimeErrorProps extends QuasiquoteProperties("errors") {
5+
def testFails[T](block: =>T) = test {
6+
assertThrows[IllegalArgumentException] {
7+
block
8+
}
9+
}
10+
11+
property("default param anon function") = testFails {
12+
val param = q"val x: Int = 1"
13+
q"{ $param => x + 1 }"
14+
}
15+
16+
property("non-casedef case") = testFails {
17+
val x = q"x"
18+
q"foo match { case $x }"
19+
}
20+
21+
property("non-new annotation") = testFails {
22+
val annot = q"foo"
23+
q"@$annot def foo"
24+
}
25+
26+
property("non-valdef param") = testFails {
27+
val param = q"foo"
28+
q"def foo($param)"
29+
}
30+
31+
property("non-valdef class param") = testFails {
32+
val param = q"foo"
33+
q"class Foo($param)"
34+
}
35+
36+
property("non-typedef type param") = testFails {
37+
val tparam = tq"T"
38+
q"class C[$tparam]"
39+
}
40+
41+
property("non-definition refine stat") = testFails {
42+
val stat = q"foo"
43+
tq"Foo { $stat }"
44+
}
45+
46+
property("non-definition early def") = testFails {
47+
val stat = q"foo"
48+
q"class Foo extends { $stat } with Bar"
49+
}
50+
51+
property("type apply for definition") = testFails {
52+
val defn = q"def foo"
53+
q"$defn[foo]"
54+
}
55+
56+
property("non-val selftype") = testFails {
57+
val foo = q"foo"
58+
q"class Foo { $foo => }"
59+
}
60+
61+
property("for empty enums") = testFails {
62+
val enums = List.empty[Tree]
63+
q"for(..$enums) 0"
64+
}
65+
66+
property("for starts with non-from enum") = testFails {
67+
val enums = fq"foo = bar" :: Nil
68+
q"for(..$enums) 0"
69+
}
70+
71+
property("for inlalid enum") = testFails {
72+
val enums = q"foo" :: Nil
73+
q"for(..$enums) 0"
74+
}
75+
}

test/files/scalacheck/quasiquotes/Test.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object Test extends Properties("quasiquotes") {
1010
include(LiftableProps)
1111
include(UnliftableProps)
1212
include(ErrorProps)
13+
include(RuntimeErrorProps)
1314
include(DefinitionConstructionProps)
1415
include(DefinitionDeconstructionProps)
1516
include(DeprecationProps)

0 commit comments

Comments
 (0)