A sort of fix for issue #1127 (take 2)#1300
Closed
tomwhoiscontrary wants to merge 3 commits into
Closed
Conversation
…head and find the first difference as usual to ease diagnosis
…re of different lengths
| int actualsLength = Array.getLength(actuals); | ||
| int expectedsLength = Array.getLength(expecteds); | ||
| if (actualsLength != expectedsLength) { | ||
| header = header + "array lengths differed, expected.length=" |
Contributor
Author
There was a problem hiding this comment.
Can do. I always get a bit creeped out by doing += on strings, for some reason!
Member
|
This change looks really useful. @junit-team/junit-committers Please take a look! :-) |
Member
|
I agree with Marc |
Member
|
Merged. Thanks! @tomwhoiscontrary could you please update the release notes at https://github.com/junit-team/junit4/wiki/4.13-Release-Notes ? |
Contributor
Author
|
@kcooney Thanks. Release note added - let me know if it needs improving. |
Member
|
@tomwhoiscontrary looks great. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is substantially the same change as in #1216, ported onto master as discussed. I will repeat the PR blurb for ease of reading ...
In issue #1127, @sf105 noted that when comparing two arrays which differ in length, assertArrayEquals() will only report that they differ in length, which he found insufficient for easy diagnosis. As a fix, he suggested printing the complete actual array contents.
Rather than doing that, this PR changes assertArrayEquals() to do the usual array comparison even when arrays differ in length, producing a failure message which combines the difference in length and the first difference in content. I think this should ease diagnosis, as @sf105 wanted, and it doesn't require making big changes to the code, adding Hamcrest, introducing a new behaviour (JUnit doesn't print complete array contents anywhere else), or blowing people's IDEs up when they compare multi-megabyte byte arrays.