Closed liyubin117 closed 2 years ago
@liyubin117 There could be different situations. In some cases there should be an exact match, in some cases the line separators are not important. As this function has been doing the exact comparison for decades - it would be better keeping that behaviour. You can implement the platform independent asserts in your code or even make it an open source library.
@panchenko Thanks for your review.
Given many developers have been confused by the issue, and update version of junit dependency is a easier way to fix the issue for users, we can add a function assertEqualsPlatformIndependent
to avoid inflecting running projects, also give users an choice to check equality ignore platform difference
It sounds like the assertion is failing due to the behavior of your code that generates the expected and/or actual values, so JUnit is working as intended.
I agree that if there is a need for an assertion that ignores line endings, that should be done outside of JUnit.
Note: if you make your own version of this, then I suggest that expected
and actual
be of type String
.
It also looks like your IDE is incorrectly showing no differences.
If the following code fails then the problem isn't JUnit:
if (expected == null) {
if (actual != null) {
throw ...
}
} else if (!expected.toSting().equals(actual.toString())) {
throw ...
}
If you use AssertJ you can use this: http://joel-costigliola.github.io/assertj/core/api/org/assertj/core/api/AbstractCharSequenceAssert.html#isEqualToIgnoringNewLines(java.lang.CharSequence)
I don't see an equivalent in Truth.
@kcooney Thanks for reminding that
we use assertEquals to check the equality of objects in many scenarios, but an annoying issue is that line separator is different in unix and windows, sometimes we encounted the junit failed just only caused by platform dependent, in fact, the problem has been mentioned frequently in Stackoverflow, maybe we can fix it