Document the assert.Empty rules more comprehensively. This exposes our
quirks to the user to avoid wrong expectations.
Add many many many more test cases that document edges cases and will allow
to catch breaking changes and avoid regressions.
Add the `IsNotType` assertion, which is the inverse
of the existing `IsType` assertion. It allows users to assert that an
object is not of a specific type.
Additionally, minor documentation improvements were made.
## Summary
This PR adds a new assertion function, `IsNotType`, to the
`testify/assert` package. It complements the existing `IsType` function
by providing a way to assert that an object is not of a specific type.
## Changes
* Added the `IsNotType` function to the `assert` package.
* Wrote unit tests for `IsNotType` to ensure correctness.
* Updated documentation to include examples and usage for `IsNotType`.
## Motivation
The `testify/assert` package already provides an `IsType` function to
check if an object is of a specific type. However, there was no built-in
way to assert that an object is **not** of a specific type. This PR
addresses that gap by introducing the `IsNotType` function, improving
the library's completeness and usability.
## Example usage
```go
assert.IsNotType(t, &MyStruct{}, actualObject)
```
## Related issues
_N/A_
The library already had assertions for `ErrorIs`, `NotErrorIs` and
`ErrorAs`. This commit adds the `NotErrorAs` assertion which is the
inverse of `ErrorAs`.
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.
* 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
Use Go 1.9 t.Helper() to remove testify from the output of the tests and
stop using `\r` to try to overwrite the output.
This means in Go 1.7 and Go 1.8 testify will appear as failing the test.
HTTP assertions were missing the trailing `msgAndArgs ...interface{}`,
making it inconsistent with the rest of the assertions and resulting in
incorrect `*f` wrappers.
Fixes#528