Skip to content

Commit 4b266a2

Browse files
committed
Fix #1369 Print a newline after interpreted commands
Added ScriptedTests which keep the original output and input instead of cutting end of line whitespaces Added a test case for Unit
1 parent 547c577 commit 4b266a2

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class ReplDriver(settings: Array[String],
196196
val newState = compile(parsed)
197197
.withHistory(parsed.sourceCode :: state.history)
198198
.newRun(compiler, rootCtx)
199-
out.println() // Prints newline after commands, also fixes #1369
199+
out.println("") // Prints newline after commands, also fixes #1369
200200
newState
201201

202202
case SyntaxErrors(src, errs, _) =>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
scala> () // The test runner also adds a newline that's why there is one more newline in this test
2+
3+
4+
scala> (); (); ();
5+
6+

compiler/test/dotty/tools/repl/ScriptedTests.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ class ScriptedTests extends ReplTest with MessageRendering {
2020
dir.listFiles
2121
}
2222

23-
private def testFile(f: JFile): Unit = {
23+
def filterEmpties(line: String): List[String] =
24+
line.replaceAll("""(?m)\s+$""", "") match {
25+
case "" => Nil
26+
case nonEmptyLine => nonEmptyLine :: Nil
27+
}
28+
29+
def noChange(line: String): List[String] = List(line)
30+
31+
private def testFile(changeLines: String => List[String])(f: JFile): Unit = {
2432
val prompt = "scala>"
2533
val lines = Source.fromFile(f).getLines.buffered
2634

@@ -53,14 +61,9 @@ class ScriptedTests extends ReplTest with MessageRendering {
5361
throw ex
5462
}
5563

56-
def filterEmpties(line: String): List[String] =
57-
line.replaceAll("""(?m)\s+$""", "") match {
58-
case "" => Nil
59-
case nonEmptyLine => nonEmptyLine :: Nil
60-
}
6164

6265
val expectedOutput =
63-
Source.fromFile(f).getLines.flatMap(filterEmpties).mkString("\n")
66+
Source.fromFile(f).getLines.flatMap(changeLines).mkString("\n")
6467
val actualOutput = {
6568
resetToInitial()
6669
init()
@@ -71,7 +74,7 @@ class ScriptedTests extends ReplTest with MessageRendering {
7174
buf.append(out)
7275
nstate
7376
}
74-
buf.flatMap(filterEmpties).mkString("\n")
77+
buf.flatMap(changeLines).mkString("\n")
7578
}
7679

7780
if (expectedOutput != actualOutput) {
@@ -84,7 +87,9 @@ class ScriptedTests extends ReplTest with MessageRendering {
8487
}
8588
}
8689

87-
@Test def replTests = scripts("/repl").foreach(testFile)
90+
@Test def replTests = scripts("/repl").foreach(testFile(filterEmpties))
91+
92+
@Test def replWhitespaceTests = scripts("/repl-whitespace-sensitive").foreach(testFile(noChange))
8893

89-
@Test def typePrinterTests = scripts("/type-printer").foreach(testFile)
94+
@Test def typePrinterTests = scripts("/type-printer").foreach(testFile(filterEmpties))
9095
}

0 commit comments

Comments
 (0)