-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
all: replace reflect.DeepEqual for error comparisons in test files #71197
Comments
There is no API change here, so this does not have to be a proposal. Taking it out of the proposal process. |
It reminds me previous CL https://go-review.googlesource.com/c/go/+/620776 |
Just a note that this should be decided on a case-by-case basis. There is nothing with using |
As an example, I needed to add back use of One could even argue that it's fine to use |
Exactly, one of the reasons why I suggested to scope these changes per package. Rationale for each approach (error string comparison, custom comparison,
I think this piece from I guess considering more targeted or idiomatic checks where appropriate would be the way to go? This way, we avoid unnecessary code churn while still improving clarity and staying true to each package’s real testing needs. |
Proposal Details
Description
Currently, several test files across the codebase use
reflect.DeepEqual
to compare errors. This is not the recommended way to compare errors in Go, as it can be both inefficient and potentially fragile. We should replace these comparisons with proper error comparison methods.Affected Files
At least the following:
src/strconv/atof_test.go
src/strconv/atoi_test.go
src/errors/join_test.go
src/fmt/errors_test.go
src/net/iprawsock_test.go
src/net/mac_test.go
src/net/tcpsock_test.go
src/net/udpsock_test.go
src/encoding/asn1/asn1_test.go
src/encoding/base64/base64_test.go
src/go/build/build_test.go
Proposed Solution
Replace
reflect.DeepEqual
error comparisons with either:err.Error()
for simple caseserrors.Is()
where appropriateImplementation Plan
The changes will be submitted as separate PRs grouped by package to make reviews more manageable.
Each PR will:
reflect.DeepEqual
for error comparisonsBenefits
The text was updated successfully, but these errors were encountered: