summaryrefslogtreecommitdiff
path: root/src/partest-extras
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-09-02 08:55:49 -0700
committerSom Snytt <som.snytt@gmail.com>2013-09-02 18:59:15 -0700
commit20b7ae6b8839be6593d1a3ca31ac938bb3431f25 (patch)
tree570ab5a0c251898531167112c903c4f2526b49af /src/partest-extras
parent534ced4885e75d89025d569cc2cbc2da8ed45cab (diff)
downloadscala-20b7ae6b8839be6593d1a3ca31ac938bb3431f25.tar.gz
scala-20b7ae6b8839be6593d1a3ca31ac938bb3431f25.tar.bz2
scala-20b7ae6b8839be6593d1a3ca31ac938bb3431f25.zip
SI-7781 Comments to SessionTest
Also, it would be nice if code and expected results were calculated lazily. That would allow tests with infinite code but which terminate on various conditions.
Diffstat (limited to 'src/partest-extras')
-rw-r--r--src/partest-extras/scala/tools/partest/ReplTest.scala21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/partest-extras/scala/tools/partest/ReplTest.scala b/src/partest-extras/scala/tools/partest/ReplTest.scala
index 54d1d04a02..38662c34b5 100644
--- a/src/partest-extras/scala/tools/partest/ReplTest.scala
+++ b/src/partest-extras/scala/tools/partest/ReplTest.scala
@@ -36,13 +36,24 @@ abstract class ReplTest extends DirectTest {
* after the final `prompt`, including the last space.
*/
abstract class SessionTest extends ReplTest {
+ /** Session transcript, as a triple-quoted, multiline, marginalized string. */
def session: String
- override final def code = expected filter (_.startsWith(prompt)) map (_.drop(prompt.length)) mkString "\n"
- def expected = session.stripMargin.lines.toList
+
+ /** Expected output, as an iterator. */
+ def expected = session.stripMargin.lines
+
+ /** Code is the command list culled from the session (or the expected session output).
+ * Would be nicer if code were lazy lines.
+ */
+ override final def code = expected filter (_ startsWith prompt) map (_ drop prompt.length) mkString "\n"
+
final def prompt = "scala> "
+
+ /** Default test is to compare expected and actual output and emit the diff on a failed comparison. */
override def show() = {
- val out = eval().toList
- if (out.size != expected.size) Console println s"Expected ${expected.size} lines, got ${out.size}"
- if (out != expected) Console print nest.FileManager.compareContents(expected, out, "expected", "actual")
+ val evaled = eval().toList
+ val wanted = expected.toList
+ if (evaled.size != wanted.size) Console println s"Expected ${wanted.size} lines, got ${evaled.size}"
+ if (evaled != wanted) Console print nest.FileManager.compareContents(wanted, evaled, "expected", "actual")
}
}