JDK-8326389: [test] improve assertEquals failure output#17952
JDK-8326389: [test] improve assertEquals failure output#17952MBaesken wants to merge 4 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
I think it is a good idea to improve this. I was irritated by that output more than once. Maybe a better message would be ... "..." is not equal to "..." ? |
Thanks , I adjusted the output . |
|
now the error output is like looks much better to me. |
RealCLanger
left a comment
There was a problem hiding this comment.
Looks good from my end.
|
@MBaesken This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 74 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
Hi Christoph, thanks for the review ! |
|
Hello Matthias, the proposal to improve that failure message looks OK to me. However, I feel that the newly proposed error message isn't too different than what it was earlier. Perhaps, we could do something like: diff --git a/test/lib/jdk/test/lib/Asserts.java b/test/lib/jdk/test/lib/Asserts.java
index d503ea8e544..3b45d7f4129 100644
--- a/test/lib/jdk/test/lib/Asserts.java
+++ b/test/lib/jdk/test/lib/Asserts.java
@@ -199,10 +199,11 @@ public static void assertEquals(Object lhs, Object rhs) {
*/
public static void assertEquals(Object lhs, Object rhs, String msg) {
if ((lhs != rhs) && ((lhs == null) || !(lhs.equals(rhs)))) {
- msg = Objects.toString(msg, "assertEquals")
- + ": expected " + Objects.toString(lhs)
- + " to equal " + Objects.toString(rhs);
- fail(msg);
+ if (msg != null) {
+ fail(msg);
+ } else {
+ fail("assertEquals expected: " + lhs + " but was: " + rhs);
+ }
}
}
This is similar to what other test libraries usually report for such failures. |
But in the case of a non-empty |
|
Hello Christoph, in that case the |
|
Then maybe it should be
? |
|
Hello Christoph, yes that looks fine to me. |
|
Does "expected 0 to equal 1" really cause that much consternation? I just read it as "expected 0 to be equal to 1". Aren't there existing test libraries that already "standardise" these kinds of utilities that we can emulate? testng? junit? |
|
Hello David, the updated text that I proposed to Matthias, of the form "expected: ... but was: ..." was borrowed from what junit5 reports for such assertion failures https://github.com/junit-team/junit5/blob/main/junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertionFailureBuilder.java#L174 |
I adjusted it to the given suggestion. |
jaikiran
left a comment
There was a problem hiding this comment.
Thank you Matthias. This looks good to me. I haven't checked references for this internal Asserts class. Before integrating, please run relevant tests that use this class just to be sure no test relies (and now fails) on the message being printed by the failing assertion.
|
Thanks for the reviews ! /integrate |
|
Going to push as commit 9b1f1e5.
Your commit was automatically rebased without conflicts. |
Unfortunately we get now error messages like this java.lang.RuntimeException: VM output should contain exactly one rtm locking statistics entry for method compiler.testlibrary.rtm.XAbortProvoker::forceAbort expected: 0 but was: 1 It should be ... expected: 1 but was: 0 ; the assertEquals has this interface |
Currently assertEquals has in the failure case sometimes confusing output like :
java.lang.RuntimeException: VM output should contain exactly one RTM locking statistics entry for method compiler.rtm.locking.TestRTMTotalCountIncrRate$Test::lock: expected 0 to equal 1
at jdk.test.lib.Asserts.fail(Asserts.java:634)
at jdk.test.lib.Asserts.assertEquals(Asserts.java:205)
(I don't think we really expected that for some reason 0 equals 1)
This should be improved.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17952/head:pull/17952$ git checkout pull/17952Update a local copy of the PR:
$ git checkout pull/17952$ git pull https://git.openjdk.org/jdk.git pull/17952/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 17952View PR using the GUI difftool:
$ git pr show -t 17952Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17952.diff
Webrev
Link to Webrev Comment