We have a number of unit tests which assemble a multi-line string in memory and compare it against a reference string in a file.
We've gotten a bit carried away and implemented the tests to use System.getProperty("line.separator")
to make the code OS-agnostic, but the reference files are just files with \n
line endings (Linux), so the tests which compared generated content to reference file content fail on a Windows machine because System.getProperty("line.separator")
returns \r\n
there.
This is test code so we'll probably simply define a final String LINE_ENDING="\n"
and update tests to use it instead of the "line.separator"
property value, but that said, I'd really like to understand why I'm unable to specify a different line separator. I tried mvn -DargLine="-Dline.separator=\n" test
, but the newline special character appears to have been interpreted as a literal letter "n"
so tests failed again. To my surprise, trying \\n
instead of \n
made no difference, either.
Can anyone show how one would set the line.separator
parameter properly?
Final note: the above commands were issued on a Linux machine. When running one of the tests from within Eclipse on a Windows, the \n
special character (passed in the debug configuration as a JVM parameter -Dline.separator=\n
) seems to be interpreted as the literal value "\\n"
. Searching the web proves frustratingly fruitless.