The library already had assertions for `ErrorIs`, `NotErrorIs` and
`ErrorAs`. This commit adds the `NotErrorAs` assertion which is the
inverse of `ErrorAs`.
## Summary
`collect.FailNow()` should exit goroutine without a panic to be usable
with `require` package.
## Changes
`collect.FailNow()` just does `runtime.Goexit()` instead of `panic()`.
For example `FailNow()` from `testing` package [behaves
similarly](https://cs.opensource.google/go/go/+/refs/tags/go1.21.2:src/testing/testing.go;l=973).
## Motivation
I just want `require` package to be usable with `EventuallyWithT` e.g. I
want this example to pass but it panics:
```go
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRequireEventuallyWithT(t *testing.T) {
state := 0
require.EventuallyWithT(t, func(c *assert.CollectT) {
defer func() { state += 1 }()
require.True(c, state == 2)
}, 100*time.Millisecond, 10*time.Millisecond)
}
```
See https://go.dev/play/p/Oqd95IT7qxQ
## Related issues
Fixes https://github.com/stretchr/testify/issues/1396
Fixes https://github.com/stretchr/testify/issues/1457
Grammar fixes in doc: _asserts that at none_ -> _asserts that none_
$ grep 'that at none' */*.go
assert/assertion_format.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
assert/assertion_forward.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
assert/assertion_forward.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
assert/assertions.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
require/require.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
require/require.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
require/require_forward.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
require/require_forward.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
The comments for the require package were just copied over
from the assert package when generating the functions.
This could lead to confusion because
1. The code-examples were showing examples using the
assert package instead of the require package
2. The function-documentation was not mentioning that
the functions were calling `t.FailNow()` which is some
critical information when using this package.
The tHelper interface is defined only for internal usage. We don't need
a "hard" type for it as we don't define methods on it. Let's make is
just a alias to the anonymous interface it represents.
Note: we are already using type aliases elswhere, and type aliases were
introduced a long time ago in Go 1.9.
* EqualExportedValues: Handle pointer and slice fields
* Update assert/assertions.go
Co-authored-by: Michael Pu <michael.pu123@gmail.com>
* Reduce redundant calls to 'copyExportedFields'
* Update comments
* Add support for maps
* Update Go version support to 1.19 and onward
* Re-generate after rebasing
---------
Co-authored-by: Michael Pu <michael.pu123@gmail.com>
* add EventuallyWithT assertion
* Change "EventuallyWithT" condition acceptance to no-errors raised
This change updates the "EventuallyWithT" assertion variants (regular, formatted,
requirement) to consider a condition as "met" if no assertion errors were raised
in a tick.
This allows to write easier conditions which simply contain assertions, without
needing to return a bool. The equivalent of a condition returning true in the
previous implementation would be a a condition with a single "assert.True(..)" call.
* Declare the "Collect.Copy(T)" method as a testing helper
* run go generate
---------
Co-authored-by: Arik Kfir <arik@kfirs.com>
* Implement checking only exported fields
Co-authored-by: Anthony Chang <anthony-chang@users.noreply.github.com>
* Update comment
* Run go generate
* Make compatiable with Go 1.16.5
* Fix go generate files
* Fix white space changes
* Fix whitespace changes
* Fix whitespace changes in gogenerate files
---------
Co-authored-by: Anthony Chang <anthony-chang@users.noreply.github.com>
* Add WithinTimeRange method
* Run ./.ci.generate.sh
* Rename WithinTimeRange to WithinRange
* Rename WithinRange expected parameter to actual
* Capitalise start parameter at start of error message
* Improve WithinRange example
* Added NotSame test for the assert package
* Added NotSame test for the require package
* Included formatted variants of NotSame for both assert and require