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: pass cmp.Options to cmp.Diff in BeComparableToMatcher #563

Merged

Conversation

bartlomiej-grzegorek
Copy link
Contributor

Small fix to this PR introduced @xiantank.
As additional cmp.Options might be passed to cmp.Equal method, the same should be passed to cmp.Diff.
In worst cases, lacking of options might cause a panic; eg. while using

type structWithUnexportedFields struct {
    unexported string
    Exported   string
}

actual := structWithUnexportedFields{unexported: "xxx", Exported: "exported field value"}
expectedEqual := structWithUnexportedFields{unexported: "yyy", Exported: "exported field value"}
Expect(actual).To(BeComparableTo(expectedEqual, cmpopts.IgnoreUnexported(structWithUnexportedFields{}))

If the exported values were different, cmp.Equal returns false and FailureMessage will panic because cmp.Diff can't handle unexported fields.

@onsi
Copy link
Owner

onsi commented Jul 20, 2022

thanks for this - makes sense. I'll pull it in once the GitHub actions go green.

@onsi onsi merged commit a9a8414 into onsi:master Jul 20, 2022
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.

None yet

2 participants