From dc8a4d8f580bf70beef30385d80e6e4e9afeaae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Micheloud?= Date: Sat, 22 Feb 2020 15:05:28 +0100 Subject: [PATCH 1/2] Fix #8355: REPL tests : fix for two tests failing on Windows --- .../test/dotty/tools/repl/LoadTests.scala | 18 +++++++++++++---- .../dotty/tools/repl/ReplCompilerTests.scala | 20 +++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/compiler/test/dotty/tools/repl/LoadTests.scala b/compiler/test/dotty/tools/repl/LoadTests.scala index a94d94183f11..4770fc84f0b8 100644 --- a/compiler/test/dotty/tools/repl/LoadTests.scala +++ b/compiler/test/dotty/tools/repl/LoadTests.scala @@ -1,9 +1,10 @@ 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 { @@ -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 = @@ -82,4 +83,13 @@ object LoadTests { file } + private val pattern = Pattern.compile("\\r[\\n]?|\\n"); + + // Ensure 'expected' and 'actual' contain the same line separator(s). + private 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) + } + } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index e738d38a074a..a6c63ef787a6 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). + private 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) + } + +} From b6737a8f87580060634d99cc5f8c1810fdae8bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Micheloud?= Date: Sat, 22 Feb 2020 15:18:14 +0100 Subject: [PATCH 2/2] small code change to address review --- compiler/test/dotty/tools/repl/LoadTests.scala | 11 +---------- .../test/dotty/tools/repl/ReplCompilerTests.scala | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/test/dotty/tools/repl/LoadTests.scala b/compiler/test/dotty/tools/repl/LoadTests.scala index 4770fc84f0b8..6786f8da16b5 100644 --- a/compiler/test/dotty/tools/repl/LoadTests.scala +++ b/compiler/test/dotty/tools/repl/LoadTests.scala @@ -8,7 +8,7 @@ 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!" @@ -83,13 +83,4 @@ object LoadTests { file } - private val pattern = Pattern.compile("\\r[\\n]?|\\n"); - - // Ensure 'expected' and 'actual' contain the same line separator(s). - private 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) - } - } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index a6c63ef787a6..2d190836c707 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -190,7 +190,7 @@ object ReplCompilerTests { private val pattern = Pattern.compile("\\r[\\n]?|\\n"); // Ensure 'expected' and 'actual' contain the same line separator(s). - private def assertMultiLineEquals(expected: String, actual: String): Unit = { + 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)