aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-03-31 11:20:48 +0200
committerodersky <odersky@gmail.com>2016-03-31 11:20:48 +0200
commit5bd08d437c1365bd8a81cb1b6b9801b443fde96b (patch)
treee2be21f89de19da9b7ce2ea2391c7cc300f4c515 /test
parent8cafcb9455103c34b6ce4344b58ca472a3a1f034 (diff)
parentef8c1968b2ea407c5b2ddca2fef00eb922e81f8e (diff)
downloaddotty-5bd08d437c1365bd8a81cb1b6b9801b443fde96b.tar.gz
dotty-5bd08d437c1365bd8a81cb1b6b9801b443fde96b.tar.bz2
dotty-5bd08d437c1365bd8a81cb1b6b9801b443fde96b.zip
Merge pull request #1182 from dotty-staging/repl-fixes
Repl fixes and tests
Diffstat (limited to 'test')
-rw-r--r--test/dotc/tests.scala2
-rw-r--r--test/test/CompilerTest.scala17
-rw-r--r--test/test/TestREPL.scala47
3 files changed, 65 insertions, 1 deletions
diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala
index d6bafe6be..48242f2d1 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/"
@@ -112,6 +113,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..d01038c43
--- /dev/null
+++ b/test/test/TestREPL.scala
@@ -0,0 +1,47 @@
+package test
+
+import dotty.tools.dotc.repl._
+import dotty.tools.dotc.core.Contexts.Context
+import collection.mutable
+import java.io.StringWriter
+
+/** A subclass of REPL used for testing.
+ * It takes a transcript of a REPL session in `script`. The transcript
+ * starts with the first input prompt `scala> ` and ends with `scala> :quit` and a newline.
+ * Invoking `process()` on the `TestREPL` runs all input lines and
+ * collects then interleaved with REPL output in a string writer `out`.
+ * Invoking `check()` checks that the collected output matches the original
+ * `script`.
+ */
+class TestREPL(script: String) extends REPL {
+
+ private val out = new StringWriter()
+
+ override lazy val config = new REPL.Config {
+ 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(config.prompt))
+ if (transcript.toString != script) {
+ println("input differs from transcript:")
+ println(transcript)
+ assert(false)
+ }
+ }
+} \ No newline at end of file