From 7934203799ccd7c99a1623cd765ad42271fc3796 Mon Sep 17 00:00:00 2001 From: Eugene Melekhov Date: Tue, 25 Sep 2018 11:18:35 +0300 Subject: [PATCH 1/2] Fix #5158: Take into account Windows line endings --- compiler/test/dotty/tools/repl/ReplCompilerTests.scala | 7 +++++-- compiler/test/dotty/tools/repl/ScriptedTests.scala | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index efe6876c269b..7a748b3e29a6 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -51,7 +51,7 @@ class ReplCompilerTests extends ReplTest { "val res1: Int = 20" ) - assertEquals(expected, storedOutput().split("\n").toList) + assertEquals(expected, lines()) } @Test def testImportMutable = @@ -122,6 +122,9 @@ class ReplCompilerTests extends ReplTest { ) run(source) - assertEquals(expected, storedOutput().split("\n").toList) + assertEquals(expected, lines()) } + + private def lines() = storedOutput().trim().lines.toList + } diff --git a/compiler/test/dotty/tools/repl/ScriptedTests.scala b/compiler/test/dotty/tools/repl/ScriptedTests.scala index 090d49949d08..78ba60aba8dd 100644 --- a/compiler/test/dotty/tools/repl/ScriptedTests.scala +++ b/compiler/test/dotty/tools/repl/ScriptedTests.scala @@ -67,7 +67,7 @@ class ScriptedTests extends ReplTest with MessageRendering { val buf = new ArrayBuffer[String] inputRes.foldLeft(initialState) { (state, input) => val (out, nstate) = evaluate(state, input, prompt) - buf.append(out) + buf.append(out.replace("\r","")) nstate } buf.flatMap(filterEmpties).mkString("\n") From 4271728b2588145e006e4670188c66705ddeb4ec Mon Sep 17 00:00:00 2001 From: Eugene Melekhov Date: Thu, 27 Sep 2018 14:08:23 +0300 Subject: [PATCH 2/2] Fix #5158: Use system dependent line separator --- compiler/test/dotty/tools/repl/ScriptedTests.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/test/dotty/tools/repl/ScriptedTests.scala b/compiler/test/dotty/tools/repl/ScriptedTests.scala index 78ba60aba8dd..3936702e4499 100644 --- a/compiler/test/dotty/tools/repl/ScriptedTests.scala +++ b/compiler/test/dotty/tools/repl/ScriptedTests.scala @@ -44,7 +44,7 @@ class ScriptedTests extends ReplTest with MessageRendering { def evaluate(state: State, input: String, prompt: String) = try { val nstate = run(input.drop(prompt.length))(state) - val out = input + "\n" + storedOutput() + val out = (input :: storedOutput().trim().lines.toList).mkString(System.lineSeparator()) (out, nstate) } catch { @@ -60,17 +60,17 @@ class ScriptedTests extends ReplTest with MessageRendering { } val expectedOutput = - Source.fromFile(f).getLines().flatMap(filterEmpties).mkString("\n") + Source.fromFile(f).getLines().flatMap(filterEmpties).mkString(System.lineSeparator) val actualOutput = { resetToInitial() val inputRes = extractInputs(prompt) val buf = new ArrayBuffer[String] inputRes.foldLeft(initialState) { (state, input) => val (out, nstate) = evaluate(state, input, prompt) - buf.append(out.replace("\r","")) + buf.append(out) nstate } - buf.flatMap(filterEmpties).mkString("\n") + buf.flatMap(filterEmpties).mkString(System.lineSeparator) } if (expectedOutput != actualOutput) {