Skip to content

assert.InDeltaSlice: fix lack of length mismatch handling#1896

Open
puneetdixit200 wants to merge 2 commits into
stretchr:masterfrom
puneetdixit200:fix/1263-in-delta-slice-length
Open

assert.InDeltaSlice: fix lack of length mismatch handling#1896
puneetdixit200 wants to merge 2 commits into
stretchr:masterfrom
puneetdixit200:fix/1263-in-delta-slice-length

Conversation

@puneetdixit200
Copy link
Copy Markdown

Fixes #1263.

InDeltaSlice already compares values by index, but it did not first verify that the two slices had the same length. That meant extra expected values were ignored, while extra actual values could panic by indexing past the expected slice.

This adds an explicit length check before the element-wise comparison. I also added regression coverage for both mismatch directions.

Verification:

  • go test ./assert -run TestInDeltaSlice -count=1 failed before the fix: the shorter actual slice passed and the longer actual slice panicked with reflect: slice index out of range
  • go test ./assert -run TestInDeltaSlice -count=1
  • go test ./assert -count=1
  • go test ./... -count=1
  • go vet ./...
  • gofmt -w assert/assertions.go assert/assertions_test.go
  • git diff --check

Comment thread assert/assertions.go Outdated
@dolmen dolmen changed the title Fix InDeltaSlice length mismatch handling assert.InDeltaSlice: fix lack of length mismatch handling May 24, 2026
@dolmen dolmen added bug pkg-assert Change related to package testify/assert floatting point labels May 24, 2026
@puneetdixit200
Copy link
Copy Markdown
Author

Updated in f402eee. InDeltaSlice now follows the InEpsilonSlice validation pattern more closely: it checks the expected value is a slice, uses IsType, uses Len for length mismatches, and reports element failures with the index. Added coverage for mismatched slice types. Verified with go test ./....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug floatting point pkg-assert Change related to package testify/assert

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert.InDeltaSlice doesn't check all expected values present

2 participants