aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/dotc/tests.scala2
-rw-r--r--test/test/CompilerTest.scala17
-rw-r--r--test/test/TestREPL.scala40
-rw-r--r--tests/repl/import.check11
-rw-r--r--tests/repl/multilines.check33
-rw-r--r--tests/repl/onePlusOne.check3
6 files changed, 105 insertions, 1 deletions
diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala
index 457116feb..062625c23 100644
--- a/test/dotc/tests.scala
+++ b/test/dotc/tests.scala
@@ -46,6 +46,7 @@ class tests extends CompilerTest {
val negDir = testsDir + "neg/"
val runDir = testsDir + "run/"
val newDir = testsDir + "new/"
+ val replDir = testsDir + "repl/"
val sourceDir = "./src/"
val dottyDir = sourceDir + "dotty/"
@@ -109,6 +110,7 @@ class tests extends CompilerTest {
@Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes)
@Test def new_all = compileFiles(newDir, twice)
+ @Test def repl_all = replFiles(replDir)
@Test def neg_all = compileFiles(negDir, verbose = true, compileSubDirs = false)
@Test def neg_typedIdents() = compileDir(negDir, "typedIdents")
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index ef2f719fc..1ca836133 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -5,12 +5,12 @@ import dotty.tools.dotc.{Main, Bench, Driver}
import dotty.tools.dotc.reporting.Reporter
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.config.CompilerCommand
+import dotty.tools.io.PlainFile
import scala.collection.mutable.ListBuffer
import scala.reflect.io.{ Path, Directory, File => SFile, AbstractFile }
import scala.tools.partest.nest.{ FileManager, NestUI }
import scala.annotation.tailrec
import java.io.{ RandomAccessFile, File => JFile }
-import dotty.tools.io.PlainFile
import org.junit.Test
@@ -205,7 +205,22 @@ abstract class CompilerTest {
}
}
+ def replFile(prefix: String, fileName: String): Unit = {
+ val path = s"$prefix$fileName"
+ val f = new PlainFile(path)
+ val repl = new TestREPL(new String(f.toCharArray))
+ repl.process(Array[String]())
+ repl.check()
+ }
+ def replFiles(path: String): Unit = {
+ val dir = Directory(path)
+ val fileNames = dir.files.toArray.map(_.jfile.getName).filter(_ endsWith ".check")
+ for (name <- fileNames) {
+ log(s"testing $path$name")
+ replFile(path, name)
+ }
+ }
// ========== HELPERS =============
diff --git a/test/test/TestREPL.scala b/test/test/TestREPL.scala
new file mode 100644
index 000000000..a9978cdde
--- /dev/null
+++ b/test/test/TestREPL.scala
@@ -0,0 +1,40 @@
+package test
+
+import dotty.tools.dotc.repl._
+import dotty.tools.dotc.core.Contexts.Context
+import collection.mutable
+import java.io.StringWriter
+
+
+class TestREPL(script: String) extends REPL {
+
+ private val prompt = "scala> "
+ private val continuationPrompt = " | "
+
+ private val out = new StringWriter()
+ override val output = new NewLinePrintWriter(out)
+
+ override def input(implicit ctx: Context) = new InteractiveReader {
+ val lines = script.lines
+ def readLine(prompt: String): String = {
+ val line = lines.next
+ if (line.startsWith(prompt) || line.startsWith(continuationPrompt)) {
+ output.println(line)
+ line.drop(prompt.length)
+ }
+ else readLine(prompt)
+ }
+ val interactive = false
+ }
+
+ def check() = {
+ out.close()
+ val printed = out.toString
+ val transcript = printed.drop(printed.indexOf(prompt))
+ if (transcript.toString != script) {
+ println("input differs from transcript:")
+ println(transcript)
+ assert(false)
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/repl/import.check b/tests/repl/import.check
new file mode 100644
index 000000000..ccaa52190
--- /dev/null
+++ b/tests/repl/import.check
@@ -0,0 +1,11 @@
+scala> import collection.mutable._
+import collection.mutable._
+scala> val buf = new ListBuffer[Int]
+buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
+scala> buf += 22
+res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(22)
+scala> buf ++= List(1, 2, 3)
+res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(22, 1, 2, 3)
+scala> buf.toList
+res2: scala.collection.immutable.List[Int] = List(22, 1, 2, 3)
+scala> :quit
diff --git a/tests/repl/multilines.check b/tests/repl/multilines.check
new file mode 100644
index 000000000..3bc32707e
--- /dev/null
+++ b/tests/repl/multilines.check
@@ -0,0 +1,33 @@
+scala> val x = """alpha
+ |
+ | omega"""
+x: String =
+alpha
+
+omega
+scala> val y = """abc
+ | |def
+ | |ghi
+ | """.stripMargin
+y: String =
+abc
+def
+ghi
+
+scala> val z = {
+ | def square(x: Int) = x * x
+ | val xs = List(1, 2, 3)
+ | square(xs)
+ | }
+<console>:8: error: type mismatch:
+ found : scala.collection.immutable.List[Int](xs)
+ required: Int
+ square(xs)
+ ^
+scala> val z = {
+ | def square(x: Int) = x * x
+ | val xs = List(1, 2, 3)
+ | xs.map(square)
+ | }
+z: scala.collection.immutable.List[Int] = List(1, 4, 9)
+scala> :quit
diff --git a/tests/repl/onePlusOne.check b/tests/repl/onePlusOne.check
new file mode 100644
index 000000000..9db6e6817
--- /dev/null
+++ b/tests/repl/onePlusOne.check
@@ -0,0 +1,3 @@
+scala> 1+1
+res0: Int = 2
+scala> :quit