Repository navigation
fix(gomock): display nil slices distinctly from empty slices in error messages - #308
wasim-builds wants to merge 1 commit into
Conversation
… messages When comparing nil slices with empty slices, the error message showed identical values for both 'Got' and 'Want' sides, making it impossible to distinguish them (issue uber-go#69). Updated formatGottenArg to detect nil slices using reflection and display them as 'nil' instead of '[]' in error output. Closes uber-go#69
|
By the way, I've really been enjoying contributing to this project! My goal is to get more involved in open source to help maintain projects and learn from great engineering teams. Is there a process or pathway for becoming a member of the uber-go GitHub organization? I'd love to continue helping out where I can! |
|
Hey 👋 Friendly bump on this one — fixes confusing gomock error messages when comparing nil vs empty slices. Small change, ready for review when you have a moment! 🙏 |
|
Hi! Quick follow-up — this PR fixes confusing gomock error messages for nil vs empty slice comparison. CLA is signed, CI is clean. Would appreciate a review! |
|
Hi there, Sharing this PR concerning fix(gomock): display nil slices distinctly from empty slices in error messages for uber-go/mock. Contributing around Go mocking frameworks, interface testing, and diagnostic error output has been exciting, and I'd love to help out with additional improvements and features across uber-go/mock. I am actively exploring freelance/contract engagements as well as full-time engineering positions and contributor roles. More details about my background and projects can be found on my profile: https://github.com/wasim-builds. |
What does this PR do?
Fixes confusing error messages when comparing nil slices with empty slices in gomock error output.
Problem
When a nil slice is passed where an empty slice is expected (or vice versa), the error message shows identical values for both "Got" and "Want", making it impossible to distinguish them:
This is because
fmt.Sprintf("%v", ...)formats both nil slices and empty slices as[].Solution
Update
formatGottenArgto detect nil slices usingreflect.ValueOfand display them asnilinstead of[]:Changes
gomock/call.go: UpdatedformatGottenArgto check if the argument is a nil slice using reflection, and format it asnil (<type>)instead of[] (<type>).gomock/controller_test.go: AddedSliceOfArraysMethodto the testSubjectstruct. AddedTestNilSliceVsEmptySliceandTestNilSliceOfArraysVsEmptytest cases to verify the fix for both[]byteand[][32]bytetypes (the exact type from the original issue report).Testing
All existing tests pass. Two new test cases added:
TestNilSliceVsEmptySlice- verifies[]bytenil vs empty distinctionTestNilSliceOfArraysVsEmpty- verifies[][32]bytenil vs empty distinction (the exact scenario from issue Wrong print msg when comparing initialized and uninitialized slice #69)Closes #69