I finally found the root cause of the test failure...
# strikt
d
I finally found the root cause of the test failures. It turns out that they are valid failures that shouldn't pass whenever the
line.separator
system property is anything other than
\n
. This is because raw / triple-quoted strings are hard-coded to always be compiled with
\n
line separators so they can't possibly match output that uses the
line.separator
system property. I didn't find any official documentation about this but found this: https://stackoverflow.com/questions/48933641/kotlin-add-carriage-return-into-multiline-string#:~:text=Kotlin%20multiline%20strings%20are%20always,separator%22))%20. and also found that the Kotlin standard library hardcoded
\n
in the
reindent
function (which is used by the
trimIndent
&
trimMargin
functions that are used throughout the tests): https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/text/Indent.kt#:~:text=.joinTo(StringBuild[…]eEstimate)%2C%20%22%5Cn%22) So this brings up 2 issues: 1. The github action to run on windows doesn't seem to represent a regular windows environment. Perhaps something is overwriting the
line.separator
system property. 2. Either the
EOL
value in
DefaultResultWriter
should be set to
\n
(which makes the tests pass) or all the tests that assert against multi-line triple-quoted strings need to be fixed.
There are 115 test failures on Windows. I recommend getting the github action that runs on Windows to fail first before fixing the root cause in order to prevent this issue from reoccurring in the future.
c
maybe best to put this into a github issue. this page says that windows-latest is a windows-server-2022. Maybe we should print the line separator at the beginning of the test run. https://github.com/actions/runner-images
d
It looks like the
windows-latest
image is actually using
Linux
. I added this assertion in a test:
Copy code
expectThat(System.getProperty("os.name")).startsWith("Windows")
and it failed on the
windows-latest
image with this error:
Copy code
▼ Expect that "Linux":
      ✗ starts with "Windows"
              found "Linux"
Commit: https://github.com/daniel-rusu/strikt/commit/7478142d725bf635ebe595b92655d8029b09c2da Task failure on
windows-latest
(on line 980): https://github.com/daniel-rusu/strikt/actions/runs/3919581754/jobs/6700672392
Found the problem with the workflow setup: https://github.com/robfletcher/strikt/pull/283
Once this ^ PR gets merged then I think the correct solution is to create an extension function:
Copy code
fun String.withSystemLineSeparartors(): String = when (EOL) {
  "\n" -> this
  else -> replace("\n", EOL)
}
and update all the failing tests to look something like this:
Copy code
val expectedValue = """
    expected first line
    expected second line
  """.trimIndent().withSystemLineSeparartors()

expectThat(something).isEqualTo(expectedValue)
I'm not sure where that extension function should live. Ideally in a common module that all the other modules depend on but without exposing this function to the end-users of the Strikt library.
@robfletcher, I got official confirmation from the chief Kotlin architect that
\n
line separators on Windows is the expected behavior with raw strings: https://discuss.kotlinlang.org/t/raw-triple-quoted-strings-dont-preserve-the-line-separator-of-the-system/26213 Once this is merged: https://github.com/robfletcher/strikt/pull/283 Then I can start fixing the broken tests by appending:
.replace("\n", System.lineSeparator())
on all the raw strings where this applies
r
ok, that’s merged
d
Thanks, this fixes all the line-separator issues: https://github.com/robfletcher/strikt/pull/284