Description
Minimized code
The following two REPL tests
are failing on Windows due to EOL mismatches between the expected output and the actual output produced by a REPL snipplet. Concretely statement assertEquals(expected, actual)
does fail in 4 cases : line 58, line 60, line 160 and line 176.
Compilation output
> sbt -sbt-version 1.3.8 "compile; test"
[info] Loading settings for project dotty-multiline-build-build from build.sbt ...
[info] Loading project definition from W:\dotty-multiline\project\project
[...]
[error] Failed: Total 364, Failed 10, Errors 0, Passed 352, Skipped 2
[error] Failed tests:
[error] dotty.tools.repl.ReplCompilerTests <=======
[error] dotty.tools.repl.LoadTests <=======
[error] dotty.tools.dotc.CompilationTests
[error] dotty.tools.repl.ScriptedTests
[info] Passed: Total 75, Failed 0, Errors 0, Passed 75
[error] (dotty-compiler / Test / testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 1421 s (23:41), completed 20 Feb 2020 23:16:27
Expectation
> sbt -sbt-version 1.3.8 "compile; test"
[info] Loading settings for project dotty-multiline-build-build from build.sbt ...
[info] Loading project definition from W:\dotty-multiline\project\project
[...]
[error] Failed: Total 363, Failed 5, Errors 0, Passed 356, Skipped 2
[error] Failed tests:
[error] dotty.tools.dotc.CompilationTests
[error] dotty.tools.repl.ScriptedTests
[error] (dotty-compiler / Test / testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 1421 s (23:41), completed 20 Feb 2020 22:48:17
NB. Both tests dotc.CompilationTests
and repl.ScriptedTests
will be handled by another PR.
Solution
As a preamble, I'd like to mention that file repl.ReplCompilerTests.scala
uses in some test cases a workaround to that issue, namely function lines()
- which returns a list of lines (w/o line ending) - is used in two assertEquals
tests (line 57 and line 128) where two lists rather than two (multiline) strings are compared.
My solution is to replaced assertEquals
with assertMultilineEquals
in the above 4 cases.
Before submitting a PR, I'd like to get your feedback about the following two implementations :
Solution 1
String expected
keeps untouched (role similar to a check file).
object LoadTests {
// ... (some more code) ...
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 m = pattern.matcher(expected)
val actual0 =
if (m.find()) {
val expectedLineSep = m.group()
pattern.matcher(actual).replaceAll(expectedLineSep)
}
else
actual
assertEquals(expected, actual0)
}
}
Solution 2
Both strings are transformed ("brut force") and passed to assertEquals
.
object LoadTests {
// ... (some more code) ...
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)
}
}