summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-02-04 08:29:20 +0000
committerPaul Phillips <paulp@improving.org>2011-02-04 08:29:20 +0000
commit25a2d721899881ff8dde28d6975648a0bad769f5 (patch)
tree7f697a0dd0cce0c0acc51a80e39af786091c80bb /test
parent9dc772f1636e181b3d038eba9ae2f5d1a8359386 (diff)
downloadscala-25a2d721899881ff8dde28d6975648a0bad769f5.tar.gz
scala-25a2d721899881ff8dde28d6975648a0bad769f5.tar.bz2
scala-25a2d721899881ff8dde28d6975648a0bad769f5.zip
After discovering #3376 was fixed I gave in and...
After discovering #3376 was fixed I gave in and tried to write a test. Now that the fiddling is over you can write repl tests without creating 5000 streams and settings. Look at test/files/run/bug3376.scala or jvm/interpreter.scala to see. Test case closes #3376, no review.
Diffstat (limited to 'test')
-rw-r--r--test/files/jvm/interpreter.scala42
-rw-r--r--test/files/run/bug3376.check13
-rw-r--r--test/files/run/bug3376.scala16
3 files changed, 36 insertions, 35 deletions
diff --git a/test/files/jvm/interpreter.scala b/test/files/jvm/interpreter.scala
index 2c2756828b..70ad900305 100644
--- a/test/files/jvm/interpreter.scala
+++ b/test/files/jvm/interpreter.scala
@@ -2,6 +2,8 @@ import scala.tools.nsc._
import java.io.{BufferedReader, StringReader, PrintWriter,
Writer, OutputStreamWriter}
+import interpreter.ILoop
+
object Test {
val testCodeString = <code>
// basics
@@ -144,43 +146,13 @@ def f(e: Exp) = e match {{ // non-exhaustive warning here
</code>.text
- /** A writer that skips the first line of text. The first
- * line of interpreter output is skipped because it includes
- * a version number. */
- class Skip1Writer(writer: Writer) extends Writer {
- var seenNL = false
-
- def write(cbuf: Array[Char], off: Int, len: Int) {
- if (seenNL)
- writer.write(cbuf, off, len)
- else {
- val slice : Array[Char] = cbuf.slice(off, off+len)
- val i = slice.indexOf('\n')
- if (i >= 0) {
- seenNL = true
- writer.write(slice, i+1, slice.length-(i+1))
- } else {
- // skip it
- }
- }
- }
-
- def close() { writer.close() }
- def flush() { writer.flush() }
- }
-
-
def main(args: Array[String]) {
- val input = new BufferedReader(new StringReader(testCodeString))
- val output = new PrintWriter(
- new Skip1Writer(new OutputStreamWriter(Console.out)))
- val repl = new InterpreterLoop(input, output)
- val settings = new Settings
- // when running that compiler, give it a scala-library to the classpath
- settings.classpath.value = System.getProperty("java.class.path")
- repl.main(settings)
- println()
+ // This drops the first line of output because the repl
+ // prints a version number.
+ (ILoop run testCodeString).lines drop 1 foreach println
+ val settings = new Settings
+ settings.classpath.value = sys.props("java.class.path")
val interp = new Interpreter(settings)
interp.interpret("def plusOne(x: Int) = x + 1")
interp.interpret("plusOne(5)")
diff --git a/test/files/run/bug3376.check b/test/files/run/bug3376.check
new file mode 100644
index 0000000000..7286096022
--- /dev/null
+++ b/test/files/run/bug3376.check
@@ -0,0 +1,13 @@
+Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala>
+scala> defined class M
+
+scala> m1: M[Int] = mmm
+
+scala> m2: M[Float] = mmm
+
+scala> m3: M[String] = mmm
+
+scala>
diff --git a/test/files/run/bug3376.scala b/test/files/run/bug3376.scala
new file mode 100644
index 0000000000..5cff50185c
--- /dev/null
+++ b/test/files/run/bug3376.scala
@@ -0,0 +1,16 @@
+import scala.tools.nsc.interpreter._
+
+object Test {
+ class M[@specialized T] { }
+
+ val 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
+ }
+}