summaryrefslogtreecommitdiff
path: root/src/partest-extras/scala/tools/partest
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-09-05 22:15:46 -0700
committerSom Snytt <som.snytt@gmail.com>2013-09-06 13:48:08 -0700
commit06c1c7855510ce31e43356407b95979e1e3813f1 (patch)
tree7ee9fc4b453e5539c8423e6b690b525c63128cb2 /src/partest-extras/scala/tools/partest
parent6dd565ff9b73a3ebc8f702e01d46eca78b423dd9 (diff)
downloadscala-06c1c7855510ce31e43356407b95979e1e3813f1.tar.gz
scala-06c1c7855510ce31e43356407b95979e1e3813f1.tar.bz2
scala-06c1c7855510ce31e43356407b95979e1e3813f1.zip
SI-7805 REPL -i startup
Tested with a ReplTest that loads an include script. ReplTests can choose to be `Welcoming` and keep a normalized welcome message in their check transcript. One recent SessionTest is updated to use the normalizing API.
Diffstat (limited to 'src/partest-extras/scala/tools/partest')
-rw-r--r--src/partest-extras/scala/tools/partest/ReplTest.scala24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/partest-extras/scala/tools/partest/ReplTest.scala b/src/partest-extras/scala/tools/partest/ReplTest.scala
index 38662c34b5..a728e8bdef 100644
--- a/src/partest-extras/scala/tools/partest/ReplTest.scala
+++ b/src/partest-extras/scala/tools/partest/ReplTest.scala
@@ -9,8 +9,8 @@ import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.ILoop
import java.lang.reflect.{ Method => JMethod, Field => JField }
-/** A trait for testing repl code. It drops the first line
- * of output because the real repl prints a version number.
+/** A class for testing repl code.
+ * It filters the line of output that mentions a version number.
*/
abstract class ReplTest extends DirectTest {
// override to transform Settings object immediately before the finish
@@ -22,14 +22,32 @@ abstract class ReplTest extends DirectTest {
s.Xnojline.value = true
transformSettings(s)
}
+ def welcoming: Boolean = false
+ lazy val welcome = "(Welcome to Scala) version .*".r
+ def normalize(s: String) = s match {
+ case welcome(w) => w
+ case s => s
+ }
+ def unwelcoming(s: String) = s match {
+ case welcome(w) => false
+ case _ => true
+ }
def eval() = {
val s = settings
log("eval(): settings = " + s)
- ILoop.runForTranscript(code, s).lines drop 1
+ //ILoop.runForTranscript(code, s).lines drop 1 // not always first line
+ val lines = ILoop.runForTranscript(code, s).lines
+ if (welcoming) lines map normalize
+ else lines filter unwelcoming
}
def show() = eval() foreach println
}
+/** Retain and normalize the welcome message. */
+trait Welcoming { this: ReplTest =>
+ override def welcoming = true
+}
+
/** Run a REPL test from a session transcript.
* The `session` should be a triple-quoted String starting
* with the `Type in expressions` message and ending