diff --git a/compiler/test/dotty/tools/repl/LoadTests.scala b/compiler/test/dotty/tools/repl/LoadTests.scala index a94d94183f11..6786f8da16b5 100644 --- a/compiler/test/dotty/tools/repl/LoadTests.scala +++ b/compiler/test/dotty/tools/repl/LoadTests.scala @@ -1,13 +1,14 @@ package dotty.tools.repl -import java.nio.file.{ Path, Files } +import java.nio.file.{Path, Files} import java.util.Comparator +import java.util.regex.Pattern -import org.junit.{ Test, BeforeClass, AfterClass } +import org.junit.{Test, BeforeClass, AfterClass} import org.junit.Assert.assertEquals class LoadTests extends ReplTest { - import LoadTests._ + import LoadTests._, ReplCompilerTests._ @Test def helloworld = loadTest( file = """|def helloWorld = "Hello, World!" @@ -55,9 +56,9 @@ class LoadTests extends ReplTest { def loadTest(file: String, defs: String, runCode: String, output: String) = eval(s":load ${writeFile(file)}").andThen { implicit s => - assertEquals(defs, storedOutput()) + assertMultiLineEquals(defs, storedOutput()) run(runCode) - assertEquals(output, storedOutput()) + assertMultiLineEquals(output, storedOutput()) } private def eval(code: String): State = diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index e738d38a074a..2d190836c707 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -1,9 +1,12 @@ package dotty.tools.repl +import java.util.regex.Pattern + import org.junit.Assert.{assertTrue => assert, _} import org.junit.{Ignore, Test} class ReplCompilerTests extends ReplTest { + import ReplCompilerTests._ private def lines() = storedOutput().trim.linesIterator.toList @@ -157,7 +160,7 @@ class ReplCompilerTests extends ReplTest { |} """.stripMargin) } .andThen { implicit state => - assertEquals( + assertMultiLineEquals( """// defined trait Ord |// defined object IntOrd""".stripMargin, storedOutput().trim @@ -173,7 +176,7 @@ class ReplCompilerTests extends ReplTest { @Test def testSingletonPrint = fromInitialState { implicit state => run("""val a = "hello"; val x: a.type = a""") - assertEquals("val a: String = hello\nval x: a.type = hello", storedOutput().trim) + assertMultiLineEquals("val a: String = hello\nval x: a.type = hello", storedOutput().trim) } @Test def i6574 = fromInitialState { implicit state => @@ -181,3 +184,16 @@ class ReplCompilerTests extends ReplTest { assertEquals("val a: 1 | 0 = 1", storedOutput().trim) } } + +object ReplCompilerTests { + + private val pattern = Pattern.compile("\\r[\\n]?|\\n"); + + // Ensure 'expected' and 'actual' contain the same line separator(s). + def assertMultiLineEquals(expected: String, actual: String): Unit = { + val expected0 = pattern.matcher(expected).replaceAll(System.lineSeparator) + val actual0 = pattern.matcher(actual).replaceAll(System.lineSeparator) + assertEquals(expected0, actual0) + } + +}