Skip to content

Fix #8355: REPL tests : fix for two tests failing on Windows #8356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/test/dotty/tools/repl/LoadTests.scala
Original file line number Diff line number Diff line change
@@ -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!"
Expand Down Expand Up @@ -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 =
Expand Down
20 changes: 18 additions & 2 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -157,7 +160,7 @@ class ReplCompilerTests extends ReplTest {
|}
""".stripMargin) }
.andThen { implicit state =>
assertEquals(
assertMultiLineEquals(
"""// defined trait Ord
|// defined object IntOrd""".stripMargin,
storedOutput().trim
Expand All @@ -173,11 +176,24 @@ 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 =>
run("val a: 1 | 0 = 1")
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)
}

}