Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when comparing arrays with same elements #395

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

olafurpg
Copy link
Member

Fixes #339.

Copy link
Contributor

@danicheg danicheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see improving the user experience for Arrays checking.

@@ -116,6 +116,28 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
)(implicit loc: Location, ev: B <:< A): Unit = {
StackTraces.dropInside {
if (obtained != expected) {

(obtained, expected) match {
case (a: Array[_], b: Array[_]) if a.sameElements(b) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems a bit puzzling to fail an assertion and ask the user to call the same assertion with converting Array -> Seq, although we have already done the job of checking elements... But I agree, it may help in understanding what's going on for those who forgot about Array's equals checking.

Shouldn't we add an analogical warning to assertNotEquals for a successful case (arrays are not equal by refs, but same on elements)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think it’s puzzling. It’s just an error message in the style of “did you mean?” compile errors.

You can already achieve the assertNotEquals behavior with an assert. The main point of the custom assertions is to provide richer error messages for common usecases. You can also enrich the assert failure message with clues.

Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! After reading all the discussions, I think this is the approach more in line with the spirit of MUnit: good DX without the magic.

@olafurpg olafurpg merged commit 0354373 into scalameta:main Jul 26, 2021
@olafurpg olafurpg deleted the array-eq branch July 26, 2021 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better handling of Array[T] in assertions
3 participants