summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-08-16 11:41:53 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-08-16 11:41:53 -0700
commit63bce12e94eb4480823627d6328f74befa421bbf (patch)
tree9d4f6b762467e9af15c1d886e7f37caad9064911 /test
parent01f2c2ac45a15312bd45193fd6302b7b01de9db7 (diff)
parent417718b7f68cb3a5c596a96cd351709a1ca18a7b (diff)
downloadscala-63bce12e94eb4480823627d6328f74befa421bbf.tar.gz
scala-63bce12e94eb4480823627d6328f74befa421bbf.tar.bz2
scala-63bce12e94eb4480823627d6328f74befa421bbf.zip
Merge pull request #2830 from densh/topic/stats-parsing-2
updated SI-7331, SI-6843, SI-7731, parser entry point refactoring, assertThrows utility function
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/quasiquotes-syntax-error-position.check32
-rw-r--r--test/files/neg/quasiquotes-syntax-error-position.scala15
-rw-r--r--test/files/run/t7331a.check2
-rw-r--r--test/files/run/t7331a.scala10
-rw-r--r--test/files/run/t7331b.check3
-rw-r--r--test/files/run/t7331b.scala11
-rw-r--r--test/files/run/t7331c.check3
-rw-r--r--test/files/run/t7331c.scala11
-rw-r--r--test/files/scalacheck/quasiquotes/ErrorProps.scala6
-rw-r--r--test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala67
-rw-r--r--test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala5
-rw-r--r--test/junit/scala/tools/testing/AssertThrowsTest.scala34
-rw-r--r--test/junit/scala/tools/testing/AssertUtil.scala19
13 files changed, 208 insertions, 10 deletions
diff --git a/test/files/neg/quasiquotes-syntax-error-position.check b/test/files/neg/quasiquotes-syntax-error-position.check
new file mode 100644
index 0000000000..3bd813b1bb
--- /dev/null
+++ b/test/files/neg/quasiquotes-syntax-error-position.check
@@ -0,0 +1,32 @@
+quasiquotes-syntax-error-position.scala:5: error: '=' expected but identifier found.
+ q"def $a f"
+ ^
+quasiquotes-syntax-error-position.scala:6: error: illegal start of simple expression
+ q"$a("
+ ^
+quasiquotes-syntax-error-position.scala:7: error: '}' expected but end of quote found.
+ q"class $t { def foo = $a"
+ ^
+quasiquotes-syntax-error-position.scala:8: error: '.' expected but splicee found.
+ q"import $t $t"
+ ^
+quasiquotes-syntax-error-position.scala:9: error: illegal start of definition
+ q"package p"
+ ^
+quasiquotes-syntax-error-position.scala:10: error: ';' expected but '@' found.
+ q"foo@$a"
+ ^
+quasiquotes-syntax-error-position.scala:11: error: case classes without a parameter list are not allowed;
+use either case objects or case classes with an explicit `()' as a parameter list.
+ q"case class A"
+ ^
+quasiquotes-syntax-error-position.scala:12: error: identifier expected but ']' found.
+ tq"$t => $t $t]"
+ ^
+quasiquotes-syntax-error-position.scala:13: error: end of quote expected but 'case' found.
+ cq"pattern => body ; case pattern2 =>"
+ ^
+quasiquotes-syntax-error-position.scala:14: error: ')' expected but end of quote found.
+ pq"$a(bar"
+ ^
+10 errors found
diff --git a/test/files/neg/quasiquotes-syntax-error-position.scala b/test/files/neg/quasiquotes-syntax-error-position.scala
new file mode 100644
index 0000000000..b97af52cfc
--- /dev/null
+++ b/test/files/neg/quasiquotes-syntax-error-position.scala
@@ -0,0 +1,15 @@
+import scala.reflect.runtime.universe._
+object test extends App {
+ val a = TermName("a")
+ val t = TypeName("t")
+ q"def $a f"
+ q"$a("
+ q"class $t { def foo = $a"
+ q"import $t $t"
+ q"package p"
+ q"foo@$a"
+ q"case class A"
+ tq"$t => $t $t]"
+ cq"pattern => body ; case pattern2 =>"
+ pq"$a(bar"
+} \ No newline at end of file
diff --git a/test/files/run/t7331a.check b/test/files/run/t7331a.check
new file mode 100644
index 0000000000..a59b400344
--- /dev/null
+++ b/test/files/run/t7331a.check
@@ -0,0 +1,2 @@
+source-<toolbox>,line-1,offset=0
+2 \ No newline at end of file
diff --git a/test/files/run/t7331a.scala b/test/files/run/t7331a.scala
new file mode 100644
index 0000000000..1851945e63
--- /dev/null
+++ b/test/files/run/t7331a.scala
@@ -0,0 +1,10 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.ToolBox
+
+object Test extends App {
+ val tb = cm.mkToolBox()
+ val tree = tb.parse("x")
+ println(tree.pos)
+ println(tree.pos.source.content.length)
+} \ No newline at end of file
diff --git a/test/files/run/t7331b.check b/test/files/run/t7331b.check
new file mode 100644
index 0000000000..7034a95a3f
--- /dev/null
+++ b/test/files/run/t7331b.check
@@ -0,0 +1,3 @@
+reflective compilation has failed:
+
+')' expected but eof found.
diff --git a/test/files/run/t7331b.scala b/test/files/run/t7331b.scala
new file mode 100644
index 0000000000..052656d11b
--- /dev/null
+++ b/test/files/run/t7331b.scala
@@ -0,0 +1,11 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.{ToolBox, ToolBoxError}
+
+object Test extends App {
+ val tb = cm.mkToolBox()
+ try tb.parse("f(x")
+ catch {
+ case ToolBoxError(msg, _) => println(msg)
+ }
+} \ No newline at end of file
diff --git a/test/files/run/t7331c.check b/test/files/run/t7331c.check
new file mode 100644
index 0000000000..fd3ac1d9ef
--- /dev/null
+++ b/test/files/run/t7331c.check
@@ -0,0 +1,3 @@
+ClassDef(Modifiers(), TypeName("C"), List(), Template(List(Select(Ident(scala), TypeName("AnyRef"))), emptyValDef, List(DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))))))
+source-<toolbox>,line-1,offset=6
+NoPosition
diff --git a/test/files/run/t7331c.scala b/test/files/run/t7331c.scala
new file mode 100644
index 0000000000..75873afcd0
--- /dev/null
+++ b/test/files/run/t7331c.scala
@@ -0,0 +1,11 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.ToolBox
+
+object Test extends App {
+ val tb = cm.mkToolBox()
+ val tree = tb.parse("class C").asInstanceOf[ClassDef]
+ println(showRaw(tree))
+ println(tree.pos)
+ println(tree.impl.self.pos)
+} \ No newline at end of file
diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/files/scalacheck/quasiquotes/ErrorProps.scala
index 044a332a04..b9e69e0e88 100644
--- a/test/files/scalacheck/quasiquotes/ErrorProps.scala
+++ b/test/files/scalacheck/quasiquotes/ErrorProps.scala
@@ -188,12 +188,6 @@ object ErrorProps extends QuasiquoteProperties("errors") {
val q"$m1 $m2 def foo" = EmptyTree
""")
- property("can't parse more than one casedef") = fails(
- "Can't parse more than one casedef, consider generating a match tree instead",
- """
- cq"1 => 2 case 3 => 5"
- """)
-
// // Make sure a nice error is reported in this case
// { import Flag._; val mods = NoMods; q"lazy $mods val x: Int" }
} \ No newline at end of file
diff --git a/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala b/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala
new file mode 100644
index 0000000000..355771bf04
--- /dev/null
+++ b/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala
@@ -0,0 +1,67 @@
+package scala.tools.nsc
+package symtab
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+import scala.tools.testing.AssertUtil.assertThrows
+import scala.reflect.internal.util.OffsetPosition
+
+@RunWith(classOf[JUnit4])
+class CannotHaveAttrsTest {
+ object symbolTable extends SymbolTableForUnitTesting {
+ object CHA extends CannotHaveAttrs {
+ def canEqual(that: Any): Boolean = ???
+ def productArity: Int = ???
+ def productElement(n: Int): Any = ???
+ }
+ val attrlessTrees = List(CHA, EmptyTree, emptyValDef, pendingSuperCall)
+ }
+ import symbolTable._
+
+ @Test
+ def canHaveAttrsIsFalse =
+ attrlessTrees.foreach { t =>
+ assertFalse(t.canHaveAttrs)
+ }
+
+ @Test
+ def defaultPosAssignment =
+ attrlessTrees.foreach { t =>
+ assertEquals(t.pos, NoPosition)
+ t.pos = NoPosition
+ assertEquals(t.pos, NoPosition)
+ t.setPos(NoPosition)
+ assertEquals(t.pos, NoPosition)
+ }
+
+ @Test
+ def defaultTpeAssignment =
+ attrlessTrees.foreach { t =>
+ assertEquals(t.tpe, NoType)
+ t.tpe = NoType
+ assertEquals(t.tpe, NoType)
+ t.setType(NoType)
+ assertEquals(t.tpe, NoType)
+ }
+
+ @Test
+ def nonDefaultPosAssignmentFails = {
+ val pos = new OffsetPosition(null, 0)
+ attrlessTrees.foreach { t =>
+ assertThrows[IllegalArgumentException] { t.pos = pos }
+ assertThrows[IllegalArgumentException] { t.setPos(pos) }
+ }
+ }
+
+ @Test
+ def nonDefaultTpeAssignmentFails = {
+ val tpe = typeOf[Int]
+ attrlessTrees.foreach { t =>
+ assertThrows[IllegalArgumentException] { t.tpe = tpe }
+ assertThrows[IllegalArgumentException] { t.setType(tpe) }
+ }
+ }
+}
diff --git a/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala b/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
index 537cb93ef3..11e955a4bb 100644
--- a/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
+++ b/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
@@ -9,17 +9,15 @@ import org.junit.runners.JUnit4
@RunWith(classOf[JUnit4])
class SymbolTableTest {
- private def createSymbolTable: SymbolTable = new SymbolTableForUnitTesting
+ object symbolTable extends SymbolTableForUnitTesting
@Test
def initDefinitions = {
- val symbolTable = createSymbolTable
symbolTable.definitions.init()
}
@Test
def basicSubTypeCheck = {
- val symbolTable = createSymbolTable
symbolTable.definitions.init()
val listClassTpe = symbolTable.definitions.ListClass.tpe
val seqClassTpe = symbolTable.definitions.SeqClass.tpe
@@ -32,7 +30,6 @@ class SymbolTableTest {
*/
@Test
def customClassesSubTypeCheck: Unit = {
- val symbolTable = createSymbolTable
import symbolTable._
symbolTable.definitions.init()
val rootClass = symbolTable.rootMirror.RootClass
diff --git a/test/junit/scala/tools/testing/AssertThrowsTest.scala b/test/junit/scala/tools/testing/AssertThrowsTest.scala
new file mode 100644
index 0000000000..a70519e63c
--- /dev/null
+++ b/test/junit/scala/tools/testing/AssertThrowsTest.scala
@@ -0,0 +1,34 @@
+package scala.tools
+package testing
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import AssertUtil.assertThrows
+
+@RunWith(classOf[JUnit4])
+class AssertThrowsTest {
+ class Foo extends Exception
+ class SubFoo extends Foo
+ class Bar extends Exception
+
+ @Test
+ def catchFoo = assertThrows[Foo] { throw new Foo }
+
+ @Test
+ def catchSubclass = assertThrows[Foo] { throw new SubFoo }
+
+ @Test
+ def rethrowBar =
+ assertTrue("exception wasn't rethrown", {
+ try {
+ assertThrows[Foo] { throw new Bar }
+ false
+ } catch {
+ case bar: Bar => true
+ case e: Throwable => fail(s"expected Bar but got $e"); false
+ }
+ })
+
+} \ No newline at end of file
diff --git a/test/junit/scala/tools/testing/AssertUtil.scala b/test/junit/scala/tools/testing/AssertUtil.scala
new file mode 100644
index 0000000000..9efac64a97
--- /dev/null
+++ b/test/junit/scala/tools/testing/AssertUtil.scala
@@ -0,0 +1,19 @@
+package scala.tools
+package testing
+
+/** This module contains additional higher-level assert statements
+ * that are ultimately based on junit.Assert primitives.
+ */
+object AssertUtil {
+ /** Check if exception T (or a subclass) was thrown during evaluation of f.
+ * If any other exception or throwable is found instead it will be re-thrown.
+ */
+ def assertThrows[T <: Exception](f: => Any)(implicit manifest: Manifest[T]): Unit =
+ try f
+ catch {
+ case e: Exception =>
+ val clazz = manifest.erasure.asInstanceOf[Class[T]]
+ if (!clazz.isAssignableFrom(e.getClass))
+ throw e
+ }
+} \ No newline at end of file