summaryrefslogtreecommitdiff
path: root/test/files/run/constrained-types.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-04-05 01:48:31 +0000
committerPaul Phillips <paulp@improving.org>2011-04-05 01:48:31 +0000
commite50fbcc3b32d4d65deb98a06c644894d3561c81c (patch)
tree182009f58959df2f676a73c9bb33fc18bbfcead2 /test/files/run/constrained-types.scala
parente06244cb55797d9928a52a22a548d547555be733 (diff)
downloadscala-e50fbcc3b32d4d65deb98a06c644894d3561c81c.tar.gz
scala-e50fbcc3b32d4d65deb98a06c644894d3561c81c.tar.bz2
scala-e50fbcc3b32d4d65deb98a06c644894d3561c81c.zip
Enhancing the repl-testing code by turning it i...
Enhancing the repl-testing code by turning it into a transcript producing machine. "Here's some code." "Here's a transcript!" "Good day to you, sir!" "No, good day to YOU!" These changes are awesome. Look at the checkfile diffs for god's sake, they'll make you weep with joy. No review.
Diffstat (limited to 'test/files/run/constrained-types.scala')
-rw-r--r--test/files/run/constrained-types.scala146
1 files changed, 67 insertions, 79 deletions
diff --git a/test/files/run/constrained-types.scala b/test/files/run/constrained-types.scala
index 86fcaade6e..5f7eb7adde 100644
--- a/test/files/run/constrained-types.scala
+++ b/test/files/run/constrained-types.scala
@@ -3,103 +3,91 @@
* of DeBruijn's . It runs the test using the interpreter so that
* the resulting annotated types can be printed out.
*/
-import scala.tools.nsc._
-import java.io._
-import scala.Console
+import scala.tools.nsc.Settings
+import scala.tools.partest.ReplTest
-object Test {
+object Test extends ReplTest {
+ def code = """
- val testCode = List(
- "class Annot(obj: Any) extends annotation.Annotation with annotation.TypeConstraint",
+class Annot(obj: Any) extends annotation.Annotation with annotation.TypeConstraint
- """class A {
- | val x = "hello"
- | val y: Int @Annot(x) = 10
- | override def toString = "an A"
- |} """,
-
-
-
- "val a = new A",
-
- """val y = a.y // should rewrite "this.x" to "a.x" """,
-
-
- "var a2 = new A",
- "val y2 = a2.y // should drop the annotation",
-
-
- """object Stuff {
- | val x = "hello"
- | val y : Int @Annot(x) = 10
- |}""",
-
- "val y = Stuff.y // should rewrite the annotation",
+class A {
+ val x = "hello"
+ val y: Int @Annot(x) = 10
+ override def toString = "an A"
+}
- """class B {
- | val y: Int @Annot(Stuff.x) = 10
- | override def toString = "a B"
- |}""",
+val a = new A
+val y = a.y // should rewrite "this.x" to "a.x"
+var a2 = new A
+val y2 = a2.y // should drop the annotation
- "val b = new B",
- "val y = b.y // should keep the annotation",
+object Stuff {
+ val x = "hello"
+ val y : Int @Annot(x) = 10
+}
+val y = Stuff.y // should rewrite the annotation
- "def m(x: String): String @Annot(x) = x",
- "val three = \"three\"",
- "val three2 = m(three:three.type) // should change x to three",
- "var four = \"four\"",
- "val four2 = m(four) // should have an existential bound",
- "val four3 = four2 // should have the same type as four2",
+class B {
+ val y: Int @Annot(Stuff.x) = 10
+ override def toString = "a B"
+}
- """val stuff = m("stuff") // should not crash""",
+val b = new B
+val y = b.y // should keep the annotation
+def m(x: String): String @Annot(x) = x
+
+val three = "three"
+val three2 = m(three:three.type) // should change x to three
+var four = "four"
+val four2 = m(four) // should have an existential bound
+val four3 = four2 // should have the same type as four2
+val stuff = m("stuff") // should not crash
+
+class peer extends annotation.Annotation // should not crash
+
+class NPE[T <: NPE[T] @peer] // should not crash
+
+def m = {
+ val x = "three"
+ val y : String @Annot(x) = x
+ y
+} // x should not escape the local scope with a narrow type
+
+def n(y: String) = {
+ def m(x: String) : String @Annot(x) = {
+ (if (x == "")
+ m("default")
+ else
+ x)
+ }
+ m("stuff".stripMargin)
+} // x should be existentially bound
- """class peer extends annotation.Annotation // should not crash""", // reported by Manfred Stock
- """class NPE[T <: NPE[T] @peer] // should not crash""", // reported by Manfred Stock
+class rep extends annotation.Annotation { }
- """def m = {
- | val x = "three"
- | val y : String @Annot(x) = x
- | y
- |} // x should not escape the local scope with a narrow type""",
+object A { val x = "hello" : String @ rep }
- """def n(y: String) = {
- | def m(x: String) : String @Annot(x) = {
- | (if (x == "")
- | m("default")
- | else
- | x)
- | }
- | m("stuff".stripMargin)
- |} // x should be existentially bound""",
+val y = a.x // should drop the annotation
- "class rep extends annotation.Annotation",
- """object A { val x = "hello" : String @ rep }""",
- "val y = a.x // should drop the annotation",
+val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
- "val x = 3 : Int @Annot(e+f+g+h) //should have a graceful error message",
+class Where(condition: Boolean) extends annotation.Annotation
- "class Where(condition: Boolean) extends annotation.Annotation",
- "val x : Int @Where(self > 0 && self < 100) = 3"
- ).map(_.stripMargin)
+val x : Int @Where(self > 0 && self < 100) = 3
+"""
+ override def settings: Settings = {
+ val s = new Settings
- def main(args: Array[String]) {
- val settings = new Settings
- settings.Xexperimental.value = true
- settings.selfInAnnots.value = true
- settings.deprecation.value = true
+ s.Xexperimental.value = true
+ s.selfInAnnots.value = true
+ s.deprecation.value = true
// when running that compiler, give it a scala-library to the classpath
- settings.classpath.value = System.getProperty("java.class.path")
-
- val interp = new Interpreter(settings)
+ s.classpath.value = sys.props("java.class.path")
- for (cmd <- testCode) {
- println(cmd)
- interp.interpret(cmd)
- println()
- println("-----")
- }
+ s
}
}