Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reject a NaN tolerance in
InDeltainstead 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 withdelta 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, andmocktests pass on Windows with Go 1.26.5 and 1.27.1, andgo 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:
TestFailfastSuiteFailFastOnstarts 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.