Skip to content

Commit f51bf1b

Browse files
authored
Merge pull request #8356 from michelou/dotty-multiline
Fix #8355: REPL tests : fix for two tests failing on Windows
2 parents 228e593 + b6737a8 commit f51bf1b

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package dotty.tools.repl
22

3-
import java.nio.file.{ Path, Files }
3+
import java.nio.file.{Path, Files}
44
import java.util.Comparator
5+
import java.util.regex.Pattern
56

6-
import org.junit.{ Test, BeforeClass, AfterClass }
7+
import org.junit.{Test, BeforeClass, AfterClass}
78
import org.junit.Assert.assertEquals
89

910
class LoadTests extends ReplTest {
10-
import LoadTests._
11+
import LoadTests._, ReplCompilerTests._
1112

1213
@Test def helloworld = loadTest(
1314
file = """|def helloWorld = "Hello, World!"
@@ -55,9 +56,9 @@ class LoadTests extends ReplTest {
5556

5657
def loadTest(file: String, defs: String, runCode: String, output: String) =
5758
eval(s":load ${writeFile(file)}").andThen { implicit s =>
58-
assertEquals(defs, storedOutput())
59+
assertMultiLineEquals(defs, storedOutput())
5960
run(runCode)
60-
assertEquals(output, storedOutput())
61+
assertMultiLineEquals(output, storedOutput())
6162
}
6263

6364
private def eval(code: String): State =

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package dotty.tools.repl
22

3+
import java.util.regex.Pattern
4+
35
import org.junit.Assert.{assertTrue => assert, _}
46
import org.junit.{Ignore, Test}
57

68
class ReplCompilerTests extends ReplTest {
9+
import ReplCompilerTests._
710

811
private def lines() =
912
storedOutput().trim.linesIterator.toList
@@ -157,7 +160,7 @@ class ReplCompilerTests extends ReplTest {
157160
|}
158161
""".stripMargin) }
159162
.andThen { implicit state =>
160-
assertEquals(
163+
assertMultiLineEquals(
161164
"""// defined trait Ord
162165
|// defined object IntOrd""".stripMargin,
163166
storedOutput().trim
@@ -173,11 +176,24 @@ class ReplCompilerTests extends ReplTest {
173176

174177
@Test def testSingletonPrint = fromInitialState { implicit state =>
175178
run("""val a = "hello"; val x: a.type = a""")
176-
assertEquals("val a: String = hello\nval x: a.type = hello", storedOutput().trim)
179+
assertMultiLineEquals("val a: String = hello\nval x: a.type = hello", storedOutput().trim)
177180
}
178181

179182
@Test def i6574 = fromInitialState { implicit state =>
180183
run("val a: 1 | 0 = 1")
181184
assertEquals("val a: 1 | 0 = 1", storedOutput().trim)
182185
}
183186
}
187+
188+
object ReplCompilerTests {
189+
190+
private val pattern = Pattern.compile("\\r[\\n]?|\\n");
191+
192+
// Ensure 'expected' and 'actual' contain the same line separator(s).
193+
def assertMultiLineEquals(expected: String, actual: String): Unit = {
194+
val expected0 = pattern.matcher(expected).replaceAll(System.lineSeparator)
195+
val actual0 = pattern.matcher(actual).replaceAll(System.lineSeparator)
196+
assertEquals(expected0, actual0)
197+
}
198+
199+
}

0 commit comments

Comments
 (0)