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

Move object equality functions to another package for clarity #1279

Conversation

mminklet
Copy link

Summary

Move none assertion functions into a seperate package to make it clear that these do no do any assertions. There is a a lot of existing code out there with useless tests because people are assuming that assert.Foobar functions will do assertions.

Happy to take guidance on comments/naming etc.

Changes

Moved ObjectsAreEqual and ObjectsAreEqualValues and tests into a new sub package equals. Label existing functions as deprecated and call new functions instead. Call new methods anywhere in assert where the previous functions are called.

Motivation

Currently very confusing that these are in the assert package when they don't do any assertions at all.

change assert.ObjectsAreEqual to equal.ObjectsAreEqual etc

Related issues

Closes 1180

@brackendawson
Copy link
Collaborator

brackendawson commented Oct 10, 2022

If the aim of this is to prevent people from thinking that ObjectsAreEqual is an assertion that they should use, then I think this new equal package should be internal:

testify/
|-- assert
|   `-- assertions.go
|-- internal
|   `-- equal
|       `-- equal.go
|-- mock
|   `-- mock.go

nikolavp
nikolavp previously approved these changes Oct 10, 2022
@mminklet
Copy link
Author

If the aim of this is to prevent people from thinking that ObjectsAreEqual is an assertion that they should use, then I think this new equal package should be internal:

testify/
|-- assert
|   `-- assertions.go
|-- internal
|   `-- equal
|       `-- equal.go
|-- mock
|   `-- mock.go

I was actually thinking that people would still continue to use these methods, as they are useful, they're just not immediately obvious that the bool needs to be checked to have a working test. But perhaps another name/location outside of assert makes more sense?

@brackendawson
Copy link
Collaborator

If the aim of this is to prevent people from thinking that ObjectsAreEqual is an assertion that they should use, then I think this new equal package should be internal:

testify/
|-- assert
|   `-- assertions.go
|-- internal
|   `-- equal
|       `-- equal.go
|-- mock
|   `-- mock.go

I was actually thinking that people would still continue to use these methods, as they are useful, they're just not immediately obvious that the bool needs to be checked to have a working test. But perhaps another name/location outside of assert makes more sense?

While it's true that they might be useful to someone, I think people will still misuse them in exactly the same way. Testify is not a utility library, I think if people are looking for a comparison library then they should be looking at go-cmp instead.

@mminklet
Copy link
Author

mminklet commented Oct 10, 2022

Yeah that's a good point. Tbh then I'm a bit reticent about introducing this change then, as I don't want to remove useful functionality even if it is currently being misused

Actually scratch that, I realise that people just need to be directed to use the Equal and EqualValues assertions instead. I will alter my PR now

Edit: Updated with suggested changes.

@mminklet mminklet force-pushed the move-object-equal-functions-out-of-assert branch from 5459794 to 7e120ea Compare October 10, 2022 23:55
@mminklet
Copy link
Author

mminklet commented Mar 27, 2023

Is there any progress on this? If there are suggestions that are required, please let me know and I'll gladly make them. People are still being caught by this

@mminklet mminklet force-pushed the move-object-equal-functions-out-of-assert branch from 584d045 to 49741df Compare March 28, 2023 00:34
@mminklet mminklet force-pushed the move-object-equal-functions-out-of-assert branch from 49741df to ff0348f Compare March 28, 2023 00:38
@dolmen
Copy link
Collaborator

dolmen commented Jul 10, 2023

Please rebase this branch on top of master, to fix gofmt issues.

@dolmen dolmen added pkg-assert Change related to package testify/assert must-rebase enhancement labels Jul 10, 2023
@dolmen
Copy link
Collaborator

dolmen commented Jul 25, 2023

Replaced by #1431.

@dolmen
Copy link
Collaborator

dolmen commented Aug 8, 2023

Closing in favor of #1431.

@dolmen dolmen closed this Aug 8, 2023
@mminklet
Copy link
Author

mminklet commented Aug 8, 2023

Nice! Sorry I didn’t have time to rebase, it had been so long that there were more changes that needed more work. Glad to see the change got in anyway!

@mminklet mminklet deleted the move-object-equal-functions-out-of-assert branch August 8, 2023 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement must-rebase pkg-assert Change related to package testify/assert rejected/duplicate rejected/outdated Too old for a rebase, or no longer relevant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants