Skip to content

Commit 5027832

Browse files
committed
Added new tests
1 parent c878bd2 commit 5027832

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import org.jline.reader._
2626

2727
import scala.annotation.tailrec
2828
import scala.collection.JavaConverters._
29+
import scala.runtime.ZippedTraversable2
30+
2931

3032
/** The state of the REPL contains necessary bindings instead of having to have
3133
* mutation
@@ -95,13 +97,15 @@ class ReplDriver(settings: Array[String],
9597
// is called, we're in business
9698
resetToInitial()
9799

100+
final def runUntilQuit(): State = runUntilQuit(initState)
101+
98102
/** Run REPL with `state` until `:quit` command found
99103
*
100104
* This method is the main entry point into the REPL. Its effects are not
101105
* observable outside of the CLI, for this reason, most helper methods are
102106
* `protected final` to facilitate testing.
103107
*/
104-
final def runUntilQuit(): State = {
108+
final def runUntilQuit(initialState: State): State = {
105109
val terminal = new JLineTerminal()
106110

107111
/** Blockingly read a line, getting back a parse result */
@@ -127,7 +131,7 @@ class ReplDriver(settings: Array[String],
127131
else loop(interpret(res)(state))
128132
}
129133

130-
try withRedirectedOutput { loop(initState) }
134+
try withRedirectedOutput { loop(initialState) }
131135
finally terminal.close()
132136
}
133137

@@ -136,8 +140,14 @@ class ReplDriver(settings: Array[String],
136140
interpret(parsed)
137141
}
138142

143+
final def bindValues(bindPairs: ZippedTraversable2[String, Any]): State = {
144+
bindPairs.foldLeft(initState) {
145+
case (state, (name, value)) => bind(name, value)(state)
146+
}
147+
}
148+
139149
// TODO: i3007
140-
final def bind(name:String, value:Any)(implicit state: State): State = state
150+
private def bind(name:String, value:Any)(implicit state: State): State = state
141151

142152
private def withRedirectedOutput(op: => State): State =
143153
Console.withOut(out) { Console.withErr(out) { op } }

sbt-bridge/src/xsbt/ConsoleInterface.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ class ConsoleInterface {
3434
Array("-classpath", classpathString)
3535

3636
val driver = new ReplDriver(completeArgs, classLoader = Some(loader))
37-
val initState = driver.initState
38-
val s0 = (bindNames, bindValues).zipped.folLeft(initState) {
39-
case (state, (name, value)) => driver.bind(name, value)(state)
40-
}
37+
38+
val s0 = driver.bindValues((bindNames, bindValues).zipped)
4139
val s1 = driver.run(initialCommands)(s0)
42-
// handle failure during initialisation
40+
// TODO handle failure during initialisation
4341
val s2 = driver.runUntilQuit(s1)
44-
driver.run(s1)
42+
driver.run(cleanupCommands)(s2)
4543
}
4644
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
> run
22
> 'set initialCommands := "1 + 1" '
33
# FIXME: does not work on the CI
4-
#> console
4+
> console

0 commit comments

Comments
 (0)