From be505f6066f9d69c8cd8bbff0439a8867d32395e Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 18 Oct 2014 07:57:18 -0700 Subject: Make global-showdef a DirectTest The test test/files/run/global-showdef.scala was outputting to the cwd instead of the test output dir. Good behavior is now inherited from DirectTest. Test frameworks, of any ilk or capability, rock. --- test/files/run/global-showdef.scala | 50 +++++++++++++------------------------ 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'test/files/run') diff --git a/test/files/run/global-showdef.scala b/test/files/run/global-showdef.scala index 1d4891fd1f..bbad123d01 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" + + override def code = """ package foo.bar class Bippy { @@ -32,39 +31,26 @@ 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 foreach (x => run("-Xshow-class", x)) + objects foreach (x => run("-Xshow-object", x)) } - 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) - } } -- cgit v1.2.3 From 6233c305f88c5c4116e51371380a184eab26f653 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 18 Oct 2014 08:38:47 -0700 Subject: Reduce compiles for global-showdef test You can only show one class or object at a time, but we can show one of each to reduce the compilations for this test. It seems the original issue happened because the test started to create class files after SI-8217. So, also stop compile after typer, because why stress the kitteh. --- test/files/run/global-showdef.check | 8 ++++---- test/files/run/global-showdef.scala | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'test/files/run') 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 bbad123d01..276fcc1e7c 100644 --- a/test/files/run/global-showdef.scala +++ b/test/files/run/global-showdef.scala @@ -2,7 +2,7 @@ import scala.tools.partest.DirectTest import scala.tools.nsc.util.stringFromStream object Test extends DirectTest { - override def extraSettings: String = "-usejavacp -Yshow:typer" + override def extraSettings: String = "-usejavacp -Yshow:typer -Ystop-after:typer" override def code = """ package foo.bar @@ -41,8 +41,10 @@ object Bippy { def run(args: String*) = slurp(args: _*).lines filter interesting foreach println - classes foreach (x => run("-Xshow-class", x)) - objects foreach (x => run("-Xshow-object", x)) + classes.zipAll(objects, "", "") foreach { + case (c, "") => run("-Xshow-class", c) + case (c, o) => run("-Xshow-class", c, "-Xshow-object", o) + } } // slurp the compilation result -- cgit v1.2.3