Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 4447998

Browse files
som-snyttadriaanm
authored andcommitted
SI-4594 Repl settings command
A settings command for the rest of us. The usual command line options are used, except that boolean flags are enabled with +flag and disabled with -flag. ``` scala> :settings +deprecation scala> new BigInt(java.math.BigInteger.TEN) { } <console>:8: warning: inheritance from class BigInt in package math is deprecated: This class will me made final. new BigInt(java.math.BigInteger.TEN) { } ^ res0: BigInt = 10 scala> :settings -deprecation scala> new BigInt(java.math.BigInteger.TEN) { } res1: BigInt = 10 ``` Multivalue "colon" options can be reset by supplying no values after the colon. This behavior is different from the command line. ``` scala> 1 toString warning: there were 1 feature warning(s); re-run with -feature for details res0: String = 1 scala> :settings -language:postfixOps scala> 1 toString res1: String = 1 scala> :settings -d = . -encoding = UTF-8 -explaintypes = false -language = List(postfixOps) -nowarn = false scala> :settings -language: scala> :settings -d = . -encoding = UTF-8 -explaintypes = false -language = List() -nowarn = false ```
1 parent d2c6945 commit 4447998

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

scala/tools/partest/ReplTest.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package scala.tools.partest
77

88
import scala.tools.nsc.Settings
99
import scala.tools.nsc.interpreter.ILoop
10+
import scala.tools.partest.nest.FileUtil
1011
import java.lang.reflect.{ Method => JMethod, Field => JField }
1112

1213
/** A trait for testing repl code. It drops the first line
@@ -29,3 +30,15 @@ abstract class ReplTest extends DirectTest {
2930
}
3031
def show() = eval() foreach println
3132
}
33+
34+
abstract class SessionTest extends ReplTest with FileUtil {
35+
def session: String
36+
override final def code = expected filter (_.startsWith(prompt)) map (_.drop(prompt.length)) mkString "\n"
37+
def expected = session.stripMargin.lines.toList
38+
final def prompt = "scala> "
39+
override def show() = {
40+
val out = eval().toList
41+
if (out.size != expected.size) Console println s"Expected ${expected.size} lines, got ${out.size}"
42+
if (out != expected) Console print compareContents(expected, out, "expected", "actual")
43+
}
44+
}

0 commit comments

Comments
 (0)