nus-cs2113-AY2021S1 / forum

8 stars 0 forks source link

CRLF vs LF part 2: Electric Boogaloo #102

Closed NeilBaner closed 3 years ago

NeilBaner commented 3 years ago

Hi again everyone, it's me back again with yet another thing I broke...

So for my Junit test, I wanted to test the (printed) output of a piece of code, which in itself required some wonky workarounds (setting System.out to a different outputstream and comparing...) However, the same issue with CRLF vs LF reared its ugly head... again.

As we know, running the program in Windows will result in using CRLF for the output. However, when I use assertEquals, my String uses LF so it doesn't pass the test. I changed the string to use \r\n instead of \n and it passed the test; however, now it fails on Ubuntu (and I suspect it will also do so on macOS)

Is there any way to modify the test for different platforms so it, for example, matches to a different String depending on the platform?

chocomango commented 3 years ago

you can use System.lineSeparator()

NeilBaner commented 3 years ago

Oh wow I didn't know of this. Thanks!