diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/global-showdef.check | 8 | ||||
-rw-r--r-- | test/files/run/global-showdef.scala | 52 | ||||
-rw-r--r-- | test/files/run/t4950.check | 9 | ||||
-rw-r--r-- | test/files/run/t4950.scala | 12 | ||||
-rw-r--r-- | test/junit/scala/reflect/internal/PrintersTest.scala | 7 |
5 files changed, 52 insertions, 36 deletions
diff --git a/test/files/run/global-showdef.check b/test/files/run/global-showdef.check index 4c2fd41a1a..4ac96b4315 100644 --- a/test/files/run/global-showdef.check +++ b/test/files/run/global-showdef.check @@ -1,14 +1,14 @@ <<-- class foo.bar.Bippy after phase 'typer' -->> def showdefTestMemberClass1: Int +<<-- object foo.bar.Bippy after phase 'typer' -->> + def showdefTestMemberObject2: String <<-- type foo.bar.Bippy.BippyType after phase 'typer' -->> def showdefTestMemberType1: Unit +<<-- object foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> + def showdefTestMemberObject1: String <<-- type foo.bar.Bippy.BippyType after phase 'typer' -->> def showdefTestMemberType2: Unit <<-- class foo.bar.Bippy.Boppity after phase 'typer' -->> def showdefTestMemberClass2: Int <<-- class foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> def showdefTestMemberClass3: Int -<<-- object foo.bar.Bippy after phase 'typer' -->> - def showdefTestMemberObject2: String -<<-- object foo.bar.Bippy.Boppity.Boo after phase 'typer' -->> - def showdefTestMemberObject1: String diff --git a/test/files/run/global-showdef.scala b/test/files/run/global-showdef.scala index 1d4891fd1f..276fcc1e7c 100644 --- a/test/files/run/global-showdef.scala +++ b/test/files/run/global-showdef.scala @@ -1,11 +1,10 @@ -import scala.tools.nsc._ -import scala.reflect.io.AbstractFile +import scala.tools.partest.DirectTest import scala.tools.nsc.util.stringFromStream -import scala.reflect.internal.util.{ SourceFile, BatchSourceFile } -import scala.tools.nsc.reporters.ConsoleReporter -object Test { - val src: SourceFile = new BatchSourceFile("src", """ +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp -Yshow:typer -Ystop-after:typer" + + override def code = """ package foo.bar class Bippy { @@ -32,39 +31,28 @@ object Bippy { def showdefTestMemberObject2 = "abc" } - """) + """ + + override def show(): Unit = { + val classes = List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") + val objects = List("Bippy", "Bippy#Boppity#Boo") + + def interesting(line: String) = (line contains "def showdefTestMember") || (line startsWith "<<-- ") - def mkCompiler(args: String*) = { - val settings = new Settings() - val command = new CompilerCommand("-usejavacp" :: args.toList, settings) + def run(args: String*) = slurp(args: _*).lines filter interesting foreach println - new Global(settings) + classes.zipAll(objects, "", "") foreach { + case (c, "") => run("-Xshow-class", c) + case (c, o) => run("-Xshow-class", c, "-Xshow-object", o) + } } - def slurp(body: => Unit): String = stringFromStream { stream => + // slurp the compilation result + def slurp(args: String*): String = stringFromStream { stream => Console.withOut(stream) { Console.withErr(stream) { - body + compile(args: _*) } } } - def lines(args: String*): List[String] = { - val output = slurp { - val compiler = mkCompiler(args: _*) - val run = new compiler.Run() - run.compileSources(List(src)) - } - output.lines.toList - } - def showClass(name: String) = lines("-Yshow:typer", "-Xshow-class", name) - def showObject(name: String) = lines("-Yshow:typer", "-Xshow-object", name) - - def show(xs: List[String]) = { - xs filter (x => (x contains "def showdefTestMember") || (x startsWith "<<-- ")) foreach println - } - - def main(args: Array[String]) { - show(List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") flatMap showClass) - show(List("Bippy", "Bippy#Boppity#Boo") flatMap showObject) - } } diff --git a/test/files/run/t4950.check b/test/files/run/t4950.check new file mode 100644 index 0000000000..3f3a302b62 --- /dev/null +++ b/test/files/run/t4950.check @@ -0,0 +1,9 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> val 1 = 2 +scala.MatchError: 2 (of class java.lang.Integer) + +scala> val List(1) = List(1) + +scala> :quit diff --git a/test/files/run/t4950.scala b/test/files/run/t4950.scala new file mode 100644 index 0000000000..cef06027bf --- /dev/null +++ b/test/files/run/t4950.scala @@ -0,0 +1,12 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + // Filter out the abbreviated stacktrace "... X elided" + // because the number seems to differ between versions/platforms/... + override def show = eval() filterNot (_ contains "elided") foreach println + def code = +""" +val 1 = 2 +val List(1) = List(1) +""" +} diff --git a/test/junit/scala/reflect/internal/PrintersTest.scala b/test/junit/scala/reflect/internal/PrintersTest.scala index ca9b4671b2..7043c26d5e 100644 --- a/test/junit/scala/reflect/internal/PrintersTest.scala +++ b/test/junit/scala/reflect/internal/PrintersTest.scala @@ -354,6 +354,13 @@ trait ClassPrintTests { | def y = "test" |}""") + @Test def testClassConstructorModifiers = assertPrintedCode("class X private (x: scala.Int)") + + @Test def testClassConstructorModifierVisibility = assertPrintedCode(sm""" + |object A { + | class X protected[A] (x: scala.Int) + |}""") + @Test def testClassWithPublicParams = assertPrintedCode("class X(val x: scala.Int, val s: scala.Predef.String)") @Test def testClassWithParams1 = assertPrintedCode("class X(x: scala.Int, s: scala.Predef.String)") |