diff options
author | Martin Odersky <odersky@gmail.com> | 2016-03-17 16:19:03 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-03-18 12:25:47 +0100 |
commit | e1fb19412c5dcc722e7df24e543aadf03a463c9a (patch) | |
tree | 15c3732fba37b8b609c09b0632edd63fd0b59f77 /test/test | |
parent | 57bde5b5c31b76c687649848bbe2207ebeb7a57d (diff) | |
download | dotty-e1fb19412c5dcc722e7df24e543aadf03a463c9a.tar.gz dotty-e1fb19412c5dcc722e7df24e543aadf03a463c9a.tar.bz2 dotty-e1fb19412c5dcc722e7df24e543aadf03a463c9a.zip |
Add REPL tests
Diffstat (limited to 'test/test')
-rw-r--r-- | test/test/CompilerTest.scala | 17 | ||||
-rw-r--r-- | test/test/TestREPL.scala | 40 |
2 files changed, 56 insertions, 1 deletions
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 |