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

fix(built_value_test): respect non comparable fields #1323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Leptopoda
Copy link
Contributor

@Leptopoda Leptopoda commented Aug 18, 2024

Fields annotated with compare: false were wrongly compared by the equalsBuilt matcher.

@davidmorgan
Copy link
Collaborator

Thanks! That makes sense, a couple of thoughts:

  • I think implementing as you have by adding an == check means that if the check fails because of a field that is compared, it will still go on to report mismatches on fields that have compare: false? That sounds confusing. Unfortunately I can't think of a way to do this correctly without codegen/mirrors.
  • It's not clear to me that we never want the old behavior, maybe we should have both? It could be added as a different equalsBuiltIgnoringIncomparable or equalsBuilt(..., onlyCheckComparable: true)? Then people would have to opt in to the new behaviour so I wouldn't worry so much about the first point.

What do you think? Thanks.

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
@Leptopoda Leptopoda force-pushed the fix/equals_built_includes_ignored_fields branch from cec3b9c to 3f68088 Compare September 12, 2024 11:54
@Leptopoda
Copy link
Contributor Author

Sorry for my late reply. I somehow forgot this PR.

What do you think?

TBH, I dislike both approaches, but I can see your point.
For now, I've opted for the extra parameter, as equalsBuiltIgnoringIncomparable would be really long and hard to read from a quick look.
I also thought about a way to change this behavior globally like BuiltValueMatcher.onlyCheckComparable = true but this would introduce some hidden behavior and would again need to be set for every test file so we wouldn't gain much.

@davidmorgan
Copy link
Collaborator

I'm still worried about the first point I raised: this doesn't actually give a correct failure message when

  • onlyCheckComparable: true
  • the value differs on both a comparable field and on a not-comparable field

then the compare with == will fail, it will go on to list the differences, but that list will also include the non-comparable fields that should not have been checked.

Given that the whole point of this helper is to improve the failure message, I wonder if people should just use expect(v1, v2) instead of expect(v1, equalsBuilt(v2)) when there are non-comparable fields that they care about.

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.

2 participants