Skip to content

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

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

Closed
michelou opened this issue Feb 21, 2020 · 2 comments
Closed

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

michelou opened this issue Feb 21, 2020 · 2 comments

Comments

@michelou
Copy link
Contributor

michelou commented Feb 21, 2020

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

}
@smarter
Copy link
Member

smarter commented Feb 21, 2020

Solution 2 looks fine to me.

smarter added a commit that referenced this issue Feb 22, 2020
Fix #8355: REPL tests : fix for two tests failing on Windows
@som-snytt
Copy link
Contributor

PSA for \R supported by Java's Pattern.


\R | Any Unicode linebreak sequence, is equivalent to      \u000D\u000A\|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]
-- | --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants