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 1 commit
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
18 changes: 14 additions & 4 deletions compiler/test/dotty/tools/repl/LoadTests.scala
Original file line number Diff line number Diff line change
@@ -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 {
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 All @@ -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 = {
Copy link
Member

@smarter smarter Feb 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this method in two file, could you use ReplCompilerTests.assertMultiLineEquals in this file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me if having a dependency between LoadTests and ReplCompilerTests is ok for you !

val expected0 = pattern.matcher(expected).replaceAll(System.lineSeparator)
val actual0 = pattern.matcher(actual).replaceAll(System.lineSeparator)
assertEquals(expected0, actual0)
}

}
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).
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)
}

}