diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-10 13:11:36 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-10 13:11:36 -0700 |
commit | 7125dc3e2c8e996f956bba08201c24e458391c12 (patch) | |
tree | 6df29e6d117b4f52ac45069c2e777184096712f7 | |
parent | 3946e12f0aa6ed39c1969772feda3d72b9367572 (diff) | |
parent | 72298b838354e621b2fed61734d394d5befa0708 (diff) | |
download | scala-7125dc3e2c8e996f956bba08201c24e458391c12.tar.gz scala-7125dc3e2c8e996f956bba08201c24e458391c12.tar.bz2 scala-7125dc3e2c8e996f956bba08201c24e458391c12.zip |
Merge pull request #2697 from som-snytt/issue/6419-repl-save
SI-6419 Repl save session command
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ILoop.scala | 7 | ||||
-rw-r--r-- | test/files/run/repl-save.check | 18 | ||||
-rw-r--r-- | test/files/run/repl-save.scala | 16 |
3 files changed, 41 insertions, 0 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala index dc5183fdf6..ccc9621fad 100644 --- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala @@ -222,6 +222,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) nullary("quit", "exit the interpreter", () => Result(keepRunning = false, None)), nullary("replay", "reset execution and replay all previous commands", replay), nullary("reset", "reset the repl to its initial state, forgetting all session entries", resetCommand), + cmd("save", "<path>", "save replayable session to a file", saveCommand), shCommand, cmd("settings", "[+|-]<options>", "+enable/-disable flags, set compiler options", changeSettings), nullary("silent", "disable/enable automatic printing of results", verbosity), @@ -600,6 +601,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) Result(keepRunning = true, shouldReplay) } + def saveCommand(filename: String): Result = ( + if (filename.isEmpty) echo("File name is required.") + else if (replayCommandStack.isEmpty) echo("No replay commands in session") + else File(filename).printlnAll(replayCommands: _*) + ) + def addClasspath(arg: String): Unit = { val f = File(arg).normalize if (f.exists) { diff --git a/test/files/run/repl-save.check b/test/files/run/repl-save.check new file mode 100644 index 0000000000..7ed769278f --- /dev/null +++ b/test/files/run/repl-save.check @@ -0,0 +1,18 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> val i = 7 +i: Int = 7 + +scala> val j = 8 +j: Int = 8 + +scala> i * j +res0: Int = 56 + +scala> :save repl-save-run.obj/session.repl + +scala> +val i = 7 +val j = 8 +i * j diff --git a/test/files/run/repl-save.scala b/test/files/run/repl-save.scala new file mode 100644 index 0000000000..465aff225b --- /dev/null +++ b/test/files/run/repl-save.scala @@ -0,0 +1,16 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = s""" + |val i = 7 + |val j = 8 + |i * j + |:save $saveto + """.stripMargin.trim + def saveto = testOutput / "session.repl" + + override def show() = { + super.show() + Console print saveto.toFile.slurp + } +} |