From fdaa0a7a0178eab124d65f96e872c07c4400c94a Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 28 Feb 2011 21:23:59 +0000 Subject: Break 9 tests, fix 9 tests, realize you broke t... Break 9 tests, fix 9 tests, realize you broke the test you checked in between +9 and -9. Fix that and generalize the repl tests a little. I think we're all the way there. No review. --- src/partest/scala/tools/partest/ReplTest.scala | 19 +++++++++++++++++++ test/files/jvm/interpreter.scala | 17 ++++++----------- test/files/run/bug3376.scala | 9 +++------ test/files/run/bug4285.check | 9 ++++++--- test/files/run/bug4285.scala | 13 +++++++------ 5 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 src/partest/scala/tools/partest/ReplTest.scala diff --git a/src/partest/scala/tools/partest/ReplTest.scala b/src/partest/scala/tools/partest/ReplTest.scala new file mode 100644 index 0000000000..232d605bb0 --- /dev/null +++ b/src/partest/scala/tools/partest/ReplTest.scala @@ -0,0 +1,19 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2011 LAMP/EPFL + * @author Paul Phillips + */ + +package scala.tools.partest + +import scala.tools.nsc.interpreter.ILoop + +/** A trait for testing repl code. It drops the first line + * of output because the real repl prints a version number. + */ +abstract class ReplTest extends App { + def code: String + def eval() = (ILoop run code).lines drop 1 + def show() = eval() foreach println + + show() +} diff --git a/test/files/jvm/interpreter.scala b/test/files/jvm/interpreter.scala index 70ad900305..752a129950 100644 --- a/test/files/jvm/interpreter.scala +++ b/test/files/jvm/interpreter.scala @@ -1,11 +1,8 @@ import scala.tools.nsc._ -import java.io.{BufferedReader, StringReader, PrintWriter, - Writer, OutputStreamWriter} +import scala.tools.partest.ReplTest -import interpreter.ILoop - -object Test { - val testCodeString = +object Test extends ReplTest { + def code = // basics 3+4 def gcd(x: Int, y: Int): Int = {{ @@ -146,11 +143,7 @@ def f(e: Exp) = e match {{ // non-exhaustive warning here .text - def main(args: Array[String]) { - // This drops the first line of output because the repl - // prints a version number. - (ILoop run testCodeString).lines drop 1 foreach println - + def appendix() = { val settings = new Settings settings.classpath.value = sys.props("java.class.path") val interp = new Interpreter(settings) @@ -160,4 +153,6 @@ def f(e: Exp) = e match {{ // non-exhaustive warning here interp.interpret("\"after reset\"") interp.interpret("plusOne(5) // should be undefined now") } + + appendix() } diff --git a/test/files/run/bug3376.scala b/test/files/run/bug3376.scala index 5cff50185c..e2c94e5072 100644 --- a/test/files/run/bug3376.scala +++ b/test/files/run/bug3376.scala @@ -1,16 +1,13 @@ import scala.tools.nsc.interpreter._ +import scala.tools.partest.ReplTest -object Test { +object Test extends ReplTest { class M[@specialized T] { } - val code = """ + def code = """ |class M[@specialized T] { override def toString = "mmm" } |val m1 = new M[Int]() |val m2 = new M[Float]() |val m3 = new M[String]() |""".stripMargin - - def main(args: Array[String]): Unit = { - (ILoop run code).lines drop 1 foreach println - } } diff --git a/test/files/run/bug4285.check b/test/files/run/bug4285.check index 6f906f80a6..5a3c9811c3 100644 --- a/test/files/run/bug4285.check +++ b/test/files/run/bug4285.check @@ -1,9 +1,12 @@ -Welcome to Scala version 2.9.0.r24351-b20110228153004 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22). Type in expressions to have them evaluated. Type :help for more information. +scala> +scala> x: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7) + +scala> y: scala.collection.mutable.WrappedArray[Int] = WrappedArray(2, 4, 6, 8, 10, 12, 14) + scala> 56 -x: Array[Int] = Array(2, 4, 6, 8, 10, 12, 14) -y: scala.collection.mutable.WrappedArray[Int] = WrappedArray(2, 4, 6, 8, 10, 12, 14) scala> +scala> diff --git a/test/files/run/bug4285.scala b/test/files/run/bug4285.scala index 9e89b13a3a..1d9afcaf3d 100644 --- a/test/files/run/bug4285.scala +++ b/test/files/run/bug4285.scala @@ -1,7 +1,8 @@ -object Test { - def main(args: Array[String]): Unit = { - println(scala.tools.nsc.interpreter.ILoop.run("val x = Array(1,2,3,4,5,6,7) ; val y = x transform (_ * 2) ; println(y.sum)")) - } +import scala.tools.partest.ReplTest +object Test extends ReplTest { + def code = """ + |val x = Array(1,2,3,4,5,6,7) + |val y = x transform (_ * 2) + |println(y.sum) + """.stripMargin } - - -- cgit v1.2.3