Make the YAML dependency required for {assert,require}.YAMLEq{,f} pluggable.
The implementation can be selected using build tags:
- testify_yaml_default (default): gopkg.in/yaml.v3 is used, like before
- testify_yaml_fail: YAML deserialization is not implemented and always
fails. So assert.YAMLEq always fails. This is useful if the test suite
package doesn't use assert.YAMLEq (very common case).
- testify_yaml_custom: the github.com/stretchr/testify/assert/yaml
package exposes an Unmarshal variable of type func([]byte, any) error
(same as gopkg.in/yaml.v3) that allows to plug any alternate
implementation. For example github.com/goccy/go-yaml.Unmarshal.
This allows to avoid the link constraints of the license of
gopkg.in/yaml.v3 (see PR stretchr/testify#1120).
Usage: go test -tags testify_yaml_fail
To install the alternate implementation with testify_yaml_custom:
//go:build testify_yaml_custom
package my_pkg_test
import (
goyaml "github.com/goccy/go-yaml"
"github.com/stretchr/testify/assert/yaml"
)
func init() {
yaml.Unmarshal = goyaml.Unmarshal
}
Rename CompareType to compareResult to make it private. This type is
used only in internal functions and is of no use for external users and
should never have been made public.
CompareType has been introduced by 0b4ff03cda
and appeared in releases since v1.6.0.
Note: strictly speaking, this is a breaking change, but no external user
should have ever used assert.CompareType as it made no sense in the assert
API. A search on GitHub has revealed no use of it.
https://github.com/search?q=assert.CompareType+language%3AGo&type=Repositories&ref=advsearch&l=Go&l=
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.
This reverts commit 34763e0df3.
time.Time.Equal only tests that the two instances refer to the same instant, but time.Time also carries zone information, so this caused two non-equal instances to be considered equal.
As pointed out in issue #1520, if the suite is not initialised properly
(buy calling the Run function), then calling suite.Require() or
suite.Assert() will result in a deadlock.
This commit fixes that by panicking if the suite is not initialised
properly. This is justified because, the suite is intended to be
triggered in the right way. If the user does not do that, this panic will
nudge them in the right direction.
It has to be a panic because, at this point, we don't have access to any
testing.T context to gracefully call a t.Fail(). Also, these two
functions are not expected to return an error.
Fixes#1520