Skip to content

assert: add position and pass msg to underlying func in InDeltaMapValues, InDeltaMapValues, and InEpsilonSlice#1514

Open
hendrywiranto wants to merge 2 commits into
stretchr:masterfrom
hendrywiranto:pass-msg
Open

assert: add position and pass msg to underlying func in InDeltaMapValues, InDeltaMapValues, and InEpsilonSlice#1514
hendrywiranto wants to merge 2 commits into
stretchr:masterfrom
hendrywiranto:pass-msg

Conversation

@hendrywiranto
Copy link
Copy Markdown
Contributor

@hendrywiranto hendrywiranto commented Dec 3, 2023

Summary

Add position and pass msg to underlying func in InDeltaSlice, InDeltaMapValues, and InEpsilonSlice

Changes

  • Add position information into the msgAndArgs slice in those 3 funcs
    • at index: for slice index
    • at key: for map key

Motivation

When using those 3 functions, users don't know which key/index of the map/slice that produces the error because currently it's not added into the msgAndArgs slice.

Example

InDeltaSlice

Before
image

After
image

InDeltaMapValues

Before
image

After
image

InEpsilonSlice

Before
image

After
image

@hendrywiranto hendrywiranto force-pushed the pass-msg branch 4 times, most recently from e073c9f to 0cd093d Compare January 22, 2024 09:10
@hendrywiranto hendrywiranto force-pushed the pass-msg branch 2 times, most recently from a44a1b8 to fcc8dfd Compare February 22, 2024 14:32
@brackendawson brackendawson added this to the v1.8.6 milestone Feb 23, 2024
@brackendawson brackendawson modified the milestones: v1.9.1, v1.10 Mar 5, 2024
@dolmen dolmen added pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require assert.InEpsilon About assert.InEpsilon and family labels Mar 7, 2024
Comment thread assert/assertions.go Outdated
// appendMsgAndArgs appends a message string to the first element of the msgAndArgs slice
// and returns the updated slice.
func appendMsgAndArgs(msgAndArgs []interface{}, message string) []interface{} {
if len(msgAndArgs) == 0 || msgAndArgs == nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Check of msgAndArgs == nil is redundant. This is dead code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed, thanks!

Comment thread assert/assertions.go
}

return msgAndArgs
}
Copy link
Copy Markdown
Collaborator

@dolmen dolmen May 16, 2024

Choose a reason for hiding this comment

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

Refactor the function body to use a switch on len(msgAndArgs) instead of multiple if.

Copy link
Copy Markdown
Contributor Author

@hendrywiranto hendrywiranto May 17, 2024

Choose a reason for hiding this comment

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

thank you for the review, I have adjusted the function to use switch

@dolmen dolmen changed the title Add position and pass msg to underlying func in InDeltaMapValues, InDeltaMapValues, and InEpsilonSlice assert: add position and pass msg to underlying func in InDeltaMapValues, InDeltaMapValues, and InEpsilonSlice May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert.InEpsilon About assert.InEpsilon and family pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants