Skip to content

assert: reject NaN tolerance in InDelta - #1967

Open
x0Lazarus wants to merge 1 commit into
stretchr:masterfrom
x0Lazarus:fix/reject-nan-delta
Open

x0Lazarus wants to merge 1 commit into
stretchr:masterfrom
x0Lazarus:fix/reject-nan-delta

Conversation

@x0Lazarus

Copy link
Copy Markdown

Summary

Reject a NaN tolerance in InDelta instead of silently passing the assertion.

Changes

Check the tolerance before comparing the numbers, using the same error handling as InEpsilon. Add regression tests for different values, equal values, and two NaN values, including the failure message and caller-supplied context.

Motivation

assert.InDelta(t, 1, 100, math.NaN()) currently passes because comparisons against NaN are always false. An invalid tolerance can therefore hide a real test failure. It now fails with delta must not be NaN. Comparisons using valid tolerances retain their existing behavior, including comparing two NaN values with a finite tolerance.

Validation

The new regression fails before the fix and passes afterward. The assert, require, and mock tests pass on Windows with Go 1.26.5 and 1.27.1, and go vet ./... passes. Regenerating and formatting the generated files produces no content changes.

The full suite has the same existing failure before and after this patch: TestFailfastSuiteFailFastOn starts a race-enabled subprocess, which cannot run here without a CGO compiler. Race tests remain unverified.

Related issues

Found while reviewing the current assertion code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant