From aca1890ec1b2e3a58411e4cb1d7b9324e704a20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 7 Mar 2024 11:59:12 +0100 Subject: [PATCH 01/52] mock: document more alternatives to deprecated AnythingOfTypeArgument --- mock/mock.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index eca55f6..7abce13 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -766,7 +766,25 @@ const ( // AnythingOfTypeArgument contains the type of an argument // for use when type checking. Used in Diff and Assert. // -// Deprecated: this is an implementation detail that must not be used. Use [AnythingOfType] instead. +// Deprecated: this is an implementation detail that must not be used. Use the [AnythingOfType] constructor instead. +// +// If AnythingOfTypeArgument is used as a function return value type you can usually replace +// the function with a variable. Example: +// +// func anyString() mock.AnythingOfTypeArgument { +// return mock.AnythingOfType("string") +// } +// +// Can be replaced by: +// +// func anyString() interface{} { +// return mock.IsType("") +// } +// +// It could even be replaced with a variable: +// +// var anyString = mock.AnythingOfType("string") +// var anyString = mock.IsType("") // alternative type AnythingOfTypeArgument = anythingOfTypeArgument // anythingOfTypeArgument is a string that contains the type of an argument From d3dbb19355185612379252b72db50d1c67af9f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 19 Mar 2024 21:35:26 +0100 Subject: [PATCH 02/52] assert: make YAML dependency pluggable via build tags 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 } --- assert/assertions.go | 4 +++- assert/yaml/yaml_custom.go | 25 +++++++++++++++++++++++++ assert/yaml/yaml_default.go | 37 +++++++++++++++++++++++++++++++++++++ assert/yaml/yaml_fail.go | 18 ++++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 assert/yaml/yaml_custom.go create mode 100644 assert/yaml/yaml_default.go create mode 100644 assert/yaml/yaml_fail.go diff --git a/assert/assertions.go b/assert/assertions.go index 8109ef2..7c6398d 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -19,7 +19,9 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/pmezard/go-difflib/difflib" - "gopkg.in/yaml.v3" + + // Wrapper around gopkg.in/yaml.v3 + "github.com/stretchr/testify/assert/yaml" ) //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_format.go.tmpl" diff --git a/assert/yaml/yaml_custom.go b/assert/yaml/yaml_custom.go new file mode 100644 index 0000000..bc32dc9 --- /dev/null +++ b/assert/yaml/yaml_custom.go @@ -0,0 +1,25 @@ +//go:build testify_yaml_custom && !testify_yaml_fail && !testify_yaml_default +// +build testify_yaml_custom,!testify_yaml_fail,!testify_yaml_default + +// Package yaml is an implementation of YAML functions that calls a pluggable implementation. +// +// This implementation is selected with the testify_yaml_custom build tag. +// +// go test -tags testify_yaml_custom +// +// This implementation can be used at build time to replace the default implementation +// to avoid linking with [gopkg.in/yaml.v3]. +// +// In your test package: +// +// import assertYaml "github.com/stretchr/testify/assert/yaml" +// +// func init() { +// assertYaml.Unmarshall = func (in []byte, out interface{}) error { +// // ... +// return nil +// } +// } +package yaml + +var Unmarshal func(in []byte, out interface{}) error diff --git a/assert/yaml/yaml_default.go b/assert/yaml/yaml_default.go new file mode 100644 index 0000000..9a92eed --- /dev/null +++ b/assert/yaml/yaml_default.go @@ -0,0 +1,37 @@ +//go:build !testify_yaml_fail && !testify_yaml_custom +// +build !testify_yaml_fail,!testify_yaml_custom + +// Package yaml is just an indirection to handle YAML deserialization. +// +// This package is just an indirection that allows the builder to override the +// indirection with an alternative implementation of this package that uses +// another implemantation of YAML deserialization. This allows to not either not +// use YAML deserialization at all, or to use another implementation than +// [gopkg.in/yaml.v3] (for example for license compatibility reasons, see [PR #1120]). +// +// Alternative implementations are selected using build tags: +// +// - testify_yaml_fail: [Unmarshal] always fails with an error +// - testify_yaml_custom: [Unmarshal] is a variable. Caller must initialize it +// before calling any of [github.com/stretchr/testify/assert.YAMLEq] or +// [github.com/stretchr/testify/assert.YAMLEqf]. +// +// Usage: +// +// go test -tags testify_yaml_fail +// +// You can check with "go list" which implementation is linked: +// +// go list -f '{{.Imports}}' github.com/stretchr/testify/assert/yaml +// go list -tags testify_yaml_fail -f '{{.Imports}}' github.com/stretchr/testify/assert/yaml +// go list -tags testify_yaml_custom -f '{{.Imports}}' github.com/stretchr/testify/assert/yaml +// +// [PR #1120]: https://github.com/stretchr/testify/pull/1120 +package yaml + +import goyaml "gopkg.in/yaml.v3" + +// Unmarshal is just a wrapper of [gopkg.in/yaml.v3.Unmarshal]. +func Unmarshal(in []byte, out interface{}) error { + return goyaml.Unmarshal(in, out) +} diff --git a/assert/yaml/yaml_fail.go b/assert/yaml/yaml_fail.go new file mode 100644 index 0000000..e78f7df --- /dev/null +++ b/assert/yaml/yaml_fail.go @@ -0,0 +1,18 @@ +//go:build testify_yaml_fail && !testify_yaml_custom && !testify_yaml_default +// +build testify_yaml_fail,!testify_yaml_custom,!testify_yaml_default + +// Package yaml is an implementation of YAML functions that always fail. +// +// This implementation can be used at build time to replace the default implementation +// to avoid linking with [gopkg.in/yaml.v3]: +// +// go test -tags testify_yaml_fail +package yaml + +import "errors" + +var errNotImplemented = errors.New("YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)") + +func Unmarshal([]byte, interface{}) error { + return errNotImplemented +} From 42d887f28b4602ac3570597162aed14af8f1d909 Mon Sep 17 00:00:00 2001 From: Reda Chlieh Date: Thu, 11 Apr 2024 22:54:14 +0200 Subject: [PATCH 03/52] Remove type validation in EqualExportedValues --- assert/assertions.go | 15 ------------ assert/assertions_test.go | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 8109ef2..5a2b29c 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -619,21 +619,6 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs .. return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...) } - if aType.Kind() == reflect.Ptr { - aType = aType.Elem() - } - if bType.Kind() == reflect.Ptr { - bType = bType.Elem() - } - - if aType.Kind() != reflect.Struct { - return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...) - } - - if bType.Kind() != reflect.Struct { - return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...) - } - expected = copyExportedFields(expected) actual = copyExportedFields(actual) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 0ae36cd..1bcf53c 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -449,6 +449,56 @@ func TestEqualExportedValues(t *testing.T) { + Exported: (int) 1, notExported: (interface {}) `, }, + { + value1: []int{1, 2}, + value2: []int{1, 2}, + expectedEqual: true, + }, + { + value1: []int{1, 2}, + value2: []int{1, 3}, + expectedEqual: false, + expectedFail: ` + Diff: + --- Expected + +++ Actual + @@ -2,3 +2,3 @@ + (int) 1, + - (int) 2 + + (int) 3 + }`, + }, + { + value1: []*Nested{ + {1, 2}, + {3, 4}, + }, + value2: []*Nested{ + {1, "a"}, + {3, "b"}, + }, + expectedEqual: true, + }, + { + value1: []*Nested{ + {1, 2}, + {3, 4}, + }, + value2: []*Nested{ + {1, "a"}, + {2, "b"}, + }, + expectedEqual: false, + expectedFail: ` + Diff: + --- Expected + +++ Actual + @@ -6,3 +6,3 @@ + (*assert.Nested)({ + - Exported: (int) 3, + + Exported: (int) 2, + notExported: (interface {}) `, + }, } for _, c := range cases { From 4ec7678c611459e936827bd38005466b835f34c7 Mon Sep 17 00:00:00 2001 From: Jonathan Crowther Date: Fri, 12 Apr 2024 14:19:10 -0400 Subject: [PATCH 04/52] Correct the EventuallyWithT and EventuallyWithTf example --- assert/assertion_format.go | 2 +- assert/assertion_forward.go | 4 ++-- assert/assertions.go | 2 +- require/require.go | 4 ++-- require/require_forward.go | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 3ddab10..9397c81 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -186,7 +186,7 @@ func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick // assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func EventuallyWithTf(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index a84e09b..d2065be 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -336,7 +336,7 @@ func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, ti // a.EventuallyWithT(func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func (a *Assertions) EventuallyWithT(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -361,7 +361,7 @@ func (a *Assertions) EventuallyWithT(condition func(collect *CollectT), waitFor // a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func (a *Assertions) EventuallyWithTf(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/assert/assertions.go b/assert/assertions.go index 8109ef2..a291b1f 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1955,7 +1955,7 @@ func (*CollectT) Copy(TestingT) { // assert.EventuallyWithT(t, func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require.go b/require/require.go index 506a82f..5d9bc7c 100644 --- a/require/require.go +++ b/require/require.go @@ -418,7 +418,7 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t // assert.EventuallyWithT(t, func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -446,7 +446,7 @@ func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitF // assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require_forward.go b/require/require_forward.go index eee8310..6fed4cb 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -337,7 +337,7 @@ func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, ti // a.EventuallyWithT(func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func (a *Assertions) EventuallyWithT(condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -362,7 +362,7 @@ func (a *Assertions) EventuallyWithT(condition func(collect *assert.CollectT), w // a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") func (a *Assertions) EventuallyWithTf(condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() From a9e6121b1c054b960da5a6f3ba2c74fe51bdb9b1 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Thu, 11 Apr 2024 14:32:29 -0700 Subject: [PATCH 05/52] assert: handle []byte array properly The regexp package works more efficiently on bytes; if you have bytes, it is easier to pass these directly to assert.Regexp than to convert them to a string first. In addition, FindIndex/FindStringIndex are unnecessary here because we immediately throw away the result - let's just call Match() instead. --- assert/assertions.go | 10 ++++++++-- assert/assertions_test.go | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index a291b1f..eb800c1 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1615,7 +1615,6 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in // matchRegexp return true if a specified regexp matches a string. func matchRegexp(rx interface{}, str interface{}) bool { - var r *regexp.Regexp if rr, ok := rx.(*regexp.Regexp); ok { r = rr @@ -1623,7 +1622,14 @@ func matchRegexp(rx interface{}, str interface{}) bool { r = regexp.MustCompile(fmt.Sprint(rx)) } - return (r.FindStringIndex(fmt.Sprint(str)) != nil) + switch v := str.(type) { + case []byte: + return r.Match(v) + case string: + return r.MatchString(v) + default: + return r.MatchString(fmt.Sprint(v)) + } } diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 0ae36cd..fa68fe2 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -1972,13 +1972,16 @@ func TestRegexp(t *testing.T) { }{ {"^start", "start of the line"}, {"end$", "in the end"}, + {"end$", "in the end"}, {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12.34"}, } for _, tc := range cases { True(t, Regexp(mockT, tc.rx, tc.str)) True(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str)) + True(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str))) False(t, NotRegexp(mockT, tc.rx, tc.str)) + False(t, NotRegexp(mockT, tc.rx, []byte(tc.str))) False(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str)) } @@ -1993,7 +1996,9 @@ func TestRegexp(t *testing.T) { for _, tc := range cases { False(t, Regexp(mockT, tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str) False(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str)) + False(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str))) True(t, NotRegexp(mockT, tc.rx, tc.str)) + True(t, NotRegexp(mockT, tc.rx, []byte(tc.str))) True(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str)) } } From d4a63f5b89ec8c392fe4066e3a91b48dc10fe92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 7 Mar 2024 00:23:10 +0100 Subject: [PATCH 06/52] mock: simplify implementation of FunctionalOptions Remove unnecessary use of reflect in the implementation of mock.FunctionalOptions(). --- mock/mock.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 876371d..9062f01 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -803,21 +803,20 @@ func IsType(t interface{}) *IsTypeArgument { return &IsTypeArgument{t: reflect.TypeOf(t)} } -// FunctionalOptionsArgument is a struct that contains the type and value of an functional option argument -// for use when type checking. +// FunctionalOptionsArgument contains a list of functional options arguments +// expected for use when matching a list of arguments. type FunctionalOptionsArgument struct { - value interface{} + values []interface{} } // String returns the string representation of FunctionalOptionsArgument func (f *FunctionalOptionsArgument) String() string { var name string - tValue := reflect.ValueOf(f.value) - if tValue.Len() > 0 { - name = "[]" + reflect.TypeOf(tValue.Index(0).Interface()).String() + if len(f.values) > 0 { + name = "[]" + reflect.TypeOf(f.values[0]).String() } - return strings.Replace(fmt.Sprintf("%#v", f.value), "[]interface {}", name, 1) + return strings.Replace(fmt.Sprintf("%#v", f.values), "[]interface {}", name, 1) } // FunctionalOptions returns an [FunctionalOptionsArgument] object containing @@ -825,10 +824,10 @@ func (f *FunctionalOptionsArgument) String() string { // // For example: // -// Assert(t, FunctionalOptions(foo.Opt1("strValue"), foo.Opt2(613))) -func FunctionalOptions(value ...interface{}) *FunctionalOptionsArgument { +// args.Assert(t, FunctionalOptions(foo.Opt1("strValue"), foo.Opt2(613))) +func FunctionalOptions(values ...interface{}) *FunctionalOptionsArgument { return &FunctionalOptionsArgument{ - value: value, + values: values, } } @@ -982,20 +981,17 @@ func (args Arguments) Diff(objects []interface{}) (string, int) { output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected.t.Name(), actualT.Name(), actualFmt) } case *FunctionalOptionsArgument: - t := expected.value - var name string - tValue := reflect.ValueOf(t) - if tValue.Len() > 0 { - name = "[]" + reflect.TypeOf(tValue.Index(0).Interface()).String() + if len(expected.values) > 0 { + name = "[]" + reflect.TypeOf(expected.values[0]).String() } - tName := reflect.TypeOf(t).Name() - if name != reflect.TypeOf(actual).String() && tValue.Len() != 0 { + const tName = "[]interface{}" + if name != reflect.TypeOf(actual).String() && len(expected.values) != 0 { differences++ output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, tName, reflect.TypeOf(actual).Name(), actualFmt) } else { - if ef, af := assertOpts(t, actual); ef == "" && af == "" { + if ef, af := assertOpts(expected.values, actual); ef == "" && af == "" { // match output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, tName, tName) } else { From e33bd6fdd1e5e20802cd264db2ab1e363bad69bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:37:40 +0000 Subject: [PATCH 07/52] build(deps): bump softprops/action-gh-release from 1 to 2 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 21ffe56..08adf73 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,6 @@ jobs: uses: actions/checkout@v4 - name: Create GitHub release from tag - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: generate_release_notes: true From 8c324a0bbd418741163c17c7219a5f68295ed1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 23 Apr 2024 15:23:21 +0200 Subject: [PATCH 08/52] mock: simpler deprecation doc for AnythingOfTypeArgument Co-authored-by: Bracken --- mock/mock.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 7abce13..84ffcdc 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -766,25 +766,15 @@ const ( // AnythingOfTypeArgument contains the type of an argument // for use when type checking. Used in Diff and Assert. // -// Deprecated: this is an implementation detail that must not be used. Use the [AnythingOfType] constructor instead. +// Deprecated: this is an implementation detail that must not be used. Use the [AnythingOfType] constructor instead, example: // -// If AnythingOfTypeArgument is used as a function return value type you can usually replace -// the function with a variable. Example: +// m.On("Do", mock.AnythingOfType("string")) // -// func anyString() mock.AnythingOfTypeArgument { -// return mock.AnythingOfType("string") +// All explicit type declarations can be replaced with interface{} as is expected by [Mock.On], example: +// +// func anyString interface{} { +// return mock.AnythingOfType("string") // } -// -// Can be replaced by: -// -// func anyString() interface{} { -// return mock.IsType("") -// } -// -// It could even be replaced with a variable: -// -// var anyString = mock.AnythingOfType("string") -// var anyString = mock.IsType("") // alternative type AnythingOfTypeArgument = anythingOfTypeArgument // anythingOfTypeArgument is a string that contains the type of an argument From 32766084e47ab272ffaf0fcaa7c74be5882954bd Mon Sep 17 00:00:00 2001 From: Bracken Dawson Date: Mon, 29 Apr 2024 13:49:40 +0100 Subject: [PATCH 09/52] Correctly document EqualValues behavior --- assert/assertion_format.go | 4 ++-- assert/assertion_forward.go | 8 ++++---- assert/assertions.go | 4 ++-- require/require.go | 8 ++++---- require/require_forward.go | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 9397c81..c40f423 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -104,8 +104,8 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, return EqualExportedValues(t, expected, actual, append([]interface{}{msg}, args...)...) } -// EqualValuesf asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValuesf asserts that two objects are equal or convertible to the larger +// type and equal. // // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index d2065be..185e026 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -186,8 +186,8 @@ func (a *Assertions) EqualExportedValuesf(expected interface{}, actual interface return EqualExportedValuesf(a.t, expected, actual, msg, args...) } -// EqualValues asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValues asserts that two objects are equal or convertible to the larger +// type and equal. // // a.EqualValues(uint32(123), int32(123)) func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { @@ -197,8 +197,8 @@ func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAn return EqualValues(a.t, expected, actual, msgAndArgs...) } -// EqualValuesf asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValuesf asserts that two objects are equal or convertible to the larger +// type and equal. // // a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted") func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool { diff --git a/assert/assertions.go b/assert/assertions.go index a291b1f..21f5fb7 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -576,8 +576,8 @@ func truncatingFormat(data interface{}) string { return value } -// EqualValues asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValues asserts that two objects are equal or convertible to the larger +// type and equal. // // assert.EqualValues(t, uint32(123), int32(123)) func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { diff --git a/require/require.go b/require/require.go index 5d9bc7c..9290bcd 100644 --- a/require/require.go +++ b/require/require.go @@ -232,8 +232,8 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, t.FailNow() } -// EqualValues asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValues asserts that two objects are equal or convertible to the larger +// type and equal. // // assert.EqualValues(t, uint32(123), int32(123)) func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { @@ -246,8 +246,8 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg t.FailNow() } -// EqualValuesf asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValuesf asserts that two objects are equal or convertible to the larger +// type and equal. // // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { diff --git a/require/require_forward.go b/require/require_forward.go index 6fed4cb..f8302a1 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -187,8 +187,8 @@ func (a *Assertions) EqualExportedValuesf(expected interface{}, actual interface EqualExportedValuesf(a.t, expected, actual, msg, args...) } -// EqualValues asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValues asserts that two objects are equal or convertible to the larger +// type and equal. // // a.EqualValues(uint32(123), int32(123)) func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { @@ -198,8 +198,8 @@ func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAn EqualValues(a.t, expected, actual, msgAndArgs...) } -// EqualValuesf asserts that two objects are equal or convertible to the same types -// and equal. +// EqualValuesf asserts that two objects are equal or convertible to the larger +// type and equal. // // a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted") func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) { From 7af3ed34c25997a502b39d9882c3269012ee904d Mon Sep 17 00:00:00 2001 From: "hendry.wiranto" Date: Wed, 22 May 2024 01:03:16 +0700 Subject: [PATCH 10/52] feat: new assertion NotElementsMatch --- assert/assertion_format.go | 17 ++++++++++++++ assert/assertion_forward.go | 34 +++++++++++++++++++++++++++ assert/assertions.go | 33 ++++++++++++++++++++++++++ assert/assertions_test.go | 46 +++++++++++++++++++++++++++++++++++++ require/require.go | 40 ++++++++++++++++++++++++++++++++ require/require_forward.go | 34 +++++++++++++++++++++++++++ 6 files changed, 204 insertions(+) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index c40f423..ad39523 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -568,6 +568,23 @@ func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, a return NotContains(t, s, contains, append([]interface{}{msg}, args...)...) } +// NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false +// +// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true +// +// assert.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true +func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return NotElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...) +} + // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either // a slice or a channel with len == 0. // diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index 185e026..d90c65d 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -1128,6 +1128,40 @@ func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg strin return NotContainsf(a.t, s, contains, msg, args...) } +// NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// a.NotElementsMatch([1, 1, 2, 3], [1, 1, 2, 3]) -> false +// +// a.NotElementsMatch([1, 1, 2, 3], [1, 2, 3]) -> true +// +// a.NotElementsMatch([1, 2, 3], [1, 2, 4]) -> true +func (a *Assertions) NotElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return NotElementsMatch(a.t, listA, listB, msgAndArgs...) +} + +// NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// a.NotElementsMatchf([1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false +// +// a.NotElementsMatchf([1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true +// +// a.NotElementsMatchf([1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true +func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return NotElementsMatchf(a.t, listA, listB, msg, args...) +} + // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either // a slice or a channel with len == 0. // diff --git a/assert/assertions.go b/assert/assertions.go index 16d21e7..52487f0 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1176,6 +1176,39 @@ func formatListDiff(listA, listB interface{}, extraA, extraB []interface{}) stri return msg.String() } +// NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// assert.NotElementsMatch(t, [1, 1, 2, 3], [1, 1, 2, 3]) -> false +// +// assert.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true +// +// assert.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true +func NotElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if isEmpty(listA) && isEmpty(listB) { + return Fail(t, "A and B are the same", msgAndArgs) + } + + if !isList(t, listA, msgAndArgs...) { + return Fail(t, "A is not a list", msgAndArgs...) + } + if !isList(t, listB, msgAndArgs...) { + return Fail(t, "B is not a list", msgAndArgs...) + } + + extraA, extraB := diffLists(listA, listB) + if len(extraA) == 0 && len(extraB) == 0 { + return Fail(t, "A and B are the same", msgAndArgs) + } + + return true +} + // Condition uses a Comparison to assert a complex condition. func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { diff --git a/assert/assertions_test.go b/assert/assertions_test.go index fa68fe2..8b87727 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -1319,6 +1319,52 @@ func TestDiffLists(t *testing.T) { } } +func TestNotElementsMatch(t *testing.T) { + mockT := new(testing.T) + + cases := []struct { + expected interface{} + actual interface{} + result bool + }{ + // not mathing + {[]int{1}, []int{}, true}, + {[]int{}, []int{2}, true}, + {[]int{1}, []int{2}, true}, + {[]int{1}, []int{1, 1}, true}, + {[]int{1, 2}, []int{3, 4}, true}, + {[]int{3, 4}, []int{1, 2}, true}, + {[]int{1, 1, 2, 3}, []int{1, 2, 3}, true}, + {[]string{"hello"}, []string{"world"}, true}, + {[]string{"hello", "hello"}, []string{"world", "world"}, true}, + {[3]string{"hello", "hello", "hello"}, [3]string{"world", "world", "world"}, true}, + + // matching + {nil, nil, false}, + {[]int{}, nil, false}, + {[]int{}, []int{}, false}, + {[]int{1}, []int{1}, false}, + {[]int{1, 1}, []int{1, 1}, false}, + {[]int{1, 2}, []int{2, 1}, false}, + {[2]int{1, 2}, [2]int{2, 1}, false}, + {[]int{1, 1, 2}, []int{1, 2, 1}, false}, + {[]string{"hello", "world"}, []string{"world", "hello"}, false}, + {[]string{"hello", "hello"}, []string{"hello", "hello"}, false}, + {[]string{"hello", "hello", "world"}, []string{"hello", "world", "hello"}, false}, + {[3]string{"hello", "hello", "world"}, [3]string{"hello", "world", "hello"}, false}, + } + + for _, c := range cases { + t.Run(fmt.Sprintf("NotElementsMatch(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { + res := NotElementsMatch(mockT, c.actual, c.expected) + + if res != c.result { + t.Errorf("NotElementsMatch(%#v, %#v) should return %v", c.actual, c.expected, c.result) + } + }) + } +} + func TestCondition(t *testing.T) { mockT := new(testing.T) diff --git a/require/require.go b/require/require.go index 9290bcd..59b87c8 100644 --- a/require/require.go +++ b/require/require.go @@ -1429,6 +1429,46 @@ func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, a t.FailNow() } +// NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// assert.NotElementsMatch(t, [1, 1, 2, 3], [1, 1, 2, 3]) -> false +// +// assert.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true +// +// assert.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true +func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.NotElementsMatch(t, listA, listB, msgAndArgs...) { + return + } + t.FailNow() +} + +// NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false +// +// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true +// +// assert.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true +func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.NotElementsMatchf(t, listA, listB, msg, args...) { + return + } + t.FailNow() +} + // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either // a slice or a channel with len == 0. // diff --git a/require/require_forward.go b/require/require_forward.go index f8302a1..389de9a 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -1129,6 +1129,40 @@ func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg strin NotContainsf(a.t, s, contains, msg, args...) } +// NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// a.NotElementsMatch([1, 1, 2, 3], [1, 1, 2, 3]) -> false +// +// a.NotElementsMatch([1, 1, 2, 3], [1, 2, 3]) -> true +// +// a.NotElementsMatch([1, 2, 3], [1, 2, 4]) -> true +func (a *Assertions) NotElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + NotElementsMatch(a.t, listA, listB, msgAndArgs...) +} + +// NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified +// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, +// the number of appearances of each of them in both lists should not match. +// This is an inverse of ElementsMatch. +// +// a.NotElementsMatchf([1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false +// +// a.NotElementsMatchf([1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true +// +// a.NotElementsMatchf([1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true +func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + NotElementsMatchf(a.t, listA, listB, msg, args...) +} + // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either // a slice or a channel with len == 0. // From cb4e70cf8d9d1a87d1cb4580c1d53bdaab991ad0 Mon Sep 17 00:00:00 2001 From: "hendry.wiranto" Date: Tue, 28 May 2024 21:35:41 +0700 Subject: [PATCH 11/52] review: match fail msg with params --- assert/assertions.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 52487f0..7f16cb8 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1191,19 +1191,19 @@ func NotElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interf h.Helper() } if isEmpty(listA) && isEmpty(listB) { - return Fail(t, "A and B are the same", msgAndArgs) + return Fail(t, "listA and listB contain the same elements", msgAndArgs) } if !isList(t, listA, msgAndArgs...) { - return Fail(t, "A is not a list", msgAndArgs...) + return Fail(t, "listA is not a list type", msgAndArgs...) } if !isList(t, listB, msgAndArgs...) { - return Fail(t, "B is not a list", msgAndArgs...) + return Fail(t, "listB is not a list type", msgAndArgs...) } extraA, extraB := diffLists(listA, listB) if len(extraA) == 0 && len(extraB) == 0 { - return Fail(t, "A and B are the same", msgAndArgs) + return Fail(t, "listA and listB contain the same elements", msgAndArgs) } return true From 9326036bf5a035bb295949d779b8bd9996797801 Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Thu, 13 Jun 2024 06:52:14 +0200 Subject: [PATCH 12/52] Generate better comments for require package 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. --- _codegen/main.go | 4 +- require/require.go | 600 ++++++++++++++++++++++++++++------------ require/require.go.tmpl | 3 +- 3 files changed, 423 insertions(+), 184 deletions(-) diff --git a/_codegen/main.go b/_codegen/main.go index 11cdbfb..7158afc 100644 --- a/_codegen/main.go +++ b/_codegen/main.go @@ -107,7 +107,9 @@ func parseTemplates() (*template.Template, *template.Template, error) { } funcTemplate = string(f) } - tmpl, err := template.New("function").Parse(funcTemplate) + tmpl, err := template.New("function").Funcs(template.FuncMap{ + "replace": strings.ReplaceAll, + }).Parse(funcTemplate) if err != nil { return nil, nil, err } diff --git a/require/require.go b/require/require.go index 59b87c8..ed6bad9 100644 --- a/require/require.go +++ b/require/require.go @@ -10,6 +10,7 @@ import ( ) // Condition uses a Comparison to assert a complex condition. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -21,6 +22,7 @@ func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { } // Conditionf uses a Comparison to assert a complex condition. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -34,9 +36,11 @@ func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interfac // Contains asserts that the specified string, list(array, slice...) or map contains the // specified substring or element. // -// assert.Contains(t, "Hello World", "World") -// assert.Contains(t, ["Hello", "World"], "World") -// assert.Contains(t, {"Hello": "World"}, "Hello") +// require.Contains(t, "Hello World", "World") +// require.Contains(t, ["Hello", "World"], "World") +// require.Contains(t, {"Hello": "World"}, "Hello") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -50,9 +54,11 @@ func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...int // Containsf asserts that the specified string, list(array, slice...) or map contains the // specified substring or element. // -// assert.Containsf(t, "Hello World", "World", "error message %s", "formatted") -// assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") -// assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") +// require.Containsf(t, "Hello World", "World", "error message %s", "formatted") +// require.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") +// require.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -65,6 +71,7 @@ func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args // DirExists checks whether a directory exists in the given path. It also fails // if the path is a file rather a directory or there is an error checking whether it exists. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -77,6 +84,7 @@ func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { // DirExistsf checks whether a directory exists in the given path. It also fails // if the path is a file rather a directory or there is an error checking whether it exists. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -91,7 +99,8 @@ func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, // the number of appearances of each of them in both lists should match. // -// assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) +// require.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -106,7 +115,8 @@ func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, // the number of appearances of each of them in both lists should match. // -// assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") +// require.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -120,7 +130,9 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either // a slice or a channel with len == 0. // -// assert.Empty(t, obj) +// require.Empty(t, obj) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -134,7 +146,9 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either // a slice or a channel with len == 0. // -// assert.Emptyf(t, obj, "error message %s", "formatted") +// require.Emptyf(t, obj, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -147,11 +161,12 @@ func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { // Equal asserts that two objects are equal. // -// assert.Equal(t, 123, 123) +// require.Equal(t, 123, 123) // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). Function equality // cannot be determined and will always fail. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -166,7 +181,9 @@ func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...i // and that it is equal to the provided error. // // actualObj, err := SomeFunction() -// assert.EqualError(t, err, expectedErrorString) +// require.EqualError(t, err, expectedErrorString) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -181,7 +198,9 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte // and that it is equal to the provided error. // // actualObj, err := SomeFunction() -// assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") +// require.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -200,8 +219,10 @@ func EqualErrorf(t TestingT, theError error, errString string, msg string, args // Exported int // notExported int // } -// assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true -// assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false +// require.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true +// require.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -220,8 +241,10 @@ func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, m // Exported int // notExported int // } -// assert.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true -// assert.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false +// require.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true +// require.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -235,7 +258,9 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, // EqualValues asserts that two objects are equal or convertible to the larger // type and equal. // -// assert.EqualValues(t, uint32(123), int32(123)) +// require.EqualValues(t, uint32(123), int32(123)) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -249,7 +274,9 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg // EqualValuesf asserts that two objects are equal or convertible to the larger // type and equal. // -// assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") +// require.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -262,11 +289,12 @@ func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg stri // Equalf asserts that two objects are equal. // -// assert.Equalf(t, 123, 123, "error message %s", "formatted") +// require.Equalf(t, 123, 123, "error message %s", "formatted") // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). Function equality // cannot be determined and will always fail. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -280,9 +308,11 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar // Error asserts that a function returned an error (i.e. not `nil`). // // actualObj, err := SomeFunction() -// if assert.Error(t, err) { -// assert.Equal(t, expectedError, err) +// if require.Error(t, err) { +// require.Equal(t, expectedError, err) // } +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Error(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -295,6 +325,7 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) { // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. // This is a wrapper for errors.As. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -307,6 +338,7 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. // This is a wrapper for errors.As. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -321,7 +353,9 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int // and that the error contains the specified substring. // // actualObj, err := SomeFunction() -// assert.ErrorContains(t, err, expectedErrorSubString) +// require.ErrorContains(t, err, expectedErrorSubString) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -336,7 +370,9 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in // and that the error contains the specified substring. // // actualObj, err := SomeFunction() -// assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") +// require.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -349,6 +385,7 @@ func ErrorContainsf(t TestingT, theError error, contains string, msg string, arg // ErrorIs asserts that at least one of the errors in err's chain matches target. // This is a wrapper for errors.Is. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -361,6 +398,7 @@ func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { // ErrorIsf asserts that at least one of the errors in err's chain matches target. // This is a wrapper for errors.Is. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -374,9 +412,11 @@ func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface // Errorf asserts that a function returned an error (i.e. not `nil`). // // actualObj, err := SomeFunction() -// if assert.Errorf(t, err, "error message %s", "formatted") { -// assert.Equal(t, expectedErrorf, err) +// if require.Errorf(t, err, "error message %s", "formatted") { +// require.Equal(t, expectedErrorf, err) // } +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Errorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -390,7 +430,9 @@ func Errorf(t TestingT, err error, msg string, args ...interface{}) { // Eventually asserts that given condition will be met in waitFor time, // periodically checking target function each tick. // -// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) +// require.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -415,10 +457,12 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t // time.Sleep(8*time.Second) // externalValue = true // }() -// assert.EventuallyWithT(t, func(c *assert.CollectT) { +// require.EventuallyWithT(t, func(c *require.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick -// assert.True(c, externalValue, "expected 'externalValue' to be true") +// require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -443,10 +487,12 @@ func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitF // time.Sleep(8*time.Second) // externalValue = true // }() -// assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") { +// require.EventuallyWithTf(t, func(c *require.CollectT, "error message %s", "formatted") { // // add assertions as needed; any assertion failure will fail the current tick -// assert.True(c, externalValue, "expected 'externalValue' to be true") +// require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -460,7 +506,9 @@ func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), wait // Eventuallyf asserts that given condition will be met in waitFor time, // periodically checking target function each tick. // -// assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +// require.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -473,7 +521,9 @@ func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick // Exactly asserts that two objects are equal in value and type. // -// assert.Exactly(t, int32(123), int64(123)) +// require.Exactly(t, int32(123), int64(123)) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -486,7 +536,9 @@ func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. // Exactlyf asserts that two objects are equal in value and type. // -// assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") +// require.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -498,6 +550,7 @@ func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, } // Fail reports a failure through +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -509,6 +562,7 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } // FailNow fails test +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -520,6 +574,7 @@ func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } // FailNowf fails test +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -531,6 +586,7 @@ func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{} } // Failf reports a failure through +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -543,7 +599,9 @@ func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { // False asserts that the specified value is false. // -// assert.False(t, myBool) +// require.False(t, myBool) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func False(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -556,7 +614,9 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) { // Falsef asserts that the specified value is false. // -// assert.Falsef(t, myBool, "error message %s", "formatted") +// require.Falsef(t, myBool, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Falsef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -569,6 +629,7 @@ func Falsef(t TestingT, value bool, msg string, args ...interface{}) { // FileExists checks whether a file exists in the given path. It also fails if // the path points to a directory or there is an error when trying to check the file. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -581,6 +642,7 @@ func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { // FileExistsf checks whether a file exists in the given path. It also fails if // the path points to a directory or there is an error when trying to check the file. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -593,9 +655,11 @@ func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { // Greater asserts that the first element is greater than the second // -// assert.Greater(t, 2, 1) -// assert.Greater(t, float64(2), float64(1)) -// assert.Greater(t, "b", "a") +// require.Greater(t, 2, 1) +// require.Greater(t, float64(2), float64(1)) +// require.Greater(t, "b", "a") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -608,10 +672,12 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface // GreaterOrEqual asserts that the first element is greater than or equal to the second // -// assert.GreaterOrEqual(t, 2, 1) -// assert.GreaterOrEqual(t, 2, 2) -// assert.GreaterOrEqual(t, "b", "a") -// assert.GreaterOrEqual(t, "b", "b") +// require.GreaterOrEqual(t, 2, 1) +// require.GreaterOrEqual(t, 2, 2) +// require.GreaterOrEqual(t, "b", "a") +// require.GreaterOrEqual(t, "b", "b") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -624,10 +690,12 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in // GreaterOrEqualf asserts that the first element is greater than or equal to the second // -// assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") -// assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") -// assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") -// assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") +// require.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") +// require.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") +// require.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") +// require.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -640,9 +708,11 @@ func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, arg // Greaterf asserts that the first element is greater than the second // -// assert.Greaterf(t, 2, 1, "error message %s", "formatted") -// assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") -// assert.Greaterf(t, "b", "a", "error message %s", "formatted") +// require.Greaterf(t, 2, 1, "error message %s", "formatted") +// require.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") +// require.Greaterf(t, "b", "a", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -656,9 +726,10 @@ func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...in // HTTPBodyContains asserts that a specified handler returns a // body that contains a string. // -// assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") +// require.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -672,9 +743,10 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url s // HTTPBodyContainsf asserts that a specified handler returns a // body that contains a string. // -// assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// require.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -688,9 +760,10 @@ func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url // HTTPBodyNotContains asserts that a specified handler returns a // body that does not contain a string. // -// assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") +// require.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -704,9 +777,10 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, ur // HTTPBodyNotContainsf asserts that a specified handler returns a // body that does not contain a string. // -// assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// require.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -719,9 +793,10 @@ func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, u // HTTPError asserts that a specified handler returns an error status code. // -// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// require.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -734,9 +809,10 @@ func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, // HTTPErrorf asserts that a specified handler returns an error status code. // -// assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// require.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -749,9 +825,10 @@ func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, // HTTPRedirect asserts that a specified handler returns a redirect status code. // -// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// require.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -764,9 +841,10 @@ func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url strin // HTTPRedirectf asserts that a specified handler returns a redirect status code. // -// assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// require.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -779,9 +857,10 @@ func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url stri // HTTPStatusCode asserts that a specified handler returns a specified status code. // -// assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) +// require.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -794,9 +873,10 @@ func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url str // HTTPStatusCodef asserts that a specified handler returns a specified status code. // -// assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") +// require.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -809,9 +889,10 @@ func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url st // HTTPSuccess asserts that a specified handler returns a success status code. // -// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) +// require.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -824,9 +905,10 @@ func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string // HTTPSuccessf asserts that a specified handler returns a success status code. // -// assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") +// require.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -839,7 +921,9 @@ func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url strin // Implements asserts that an object is implemented by the specified interface. // -// assert.Implements(t, (*MyInterface)(nil), new(MyObject)) +// require.Implements(t, (*MyInterface)(nil), new(MyObject)) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -852,7 +936,9 @@ func Implements(t TestingT, interfaceObject interface{}, object interface{}, msg // Implementsf asserts that an object is implemented by the specified interface. // -// assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +// require.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -865,7 +951,9 @@ func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, ms // InDelta asserts that the two numerals are within delta of each other. // -// assert.InDelta(t, math.Pi, 22/7.0, 0.01) +// require.InDelta(t, math.Pi, 22/7.0, 0.01) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -877,6 +965,7 @@ func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64 } // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -888,6 +977,7 @@ func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delt } // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -899,6 +989,7 @@ func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, del } // InDeltaSlice is the same as InDelta, except it compares two slices. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -910,6 +1001,7 @@ func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta fl } // InDeltaSlicef is the same as InDelta, except it compares two slices. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -922,7 +1014,9 @@ func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta f // InDeltaf asserts that the two numerals are within delta of each other. // -// assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") +// require.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -934,6 +1028,7 @@ func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float6 } // InEpsilon asserts that expected and actual have a relative error less than epsilon +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -945,6 +1040,7 @@ func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon flo } // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -956,6 +1052,7 @@ func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilo } // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -967,6 +1064,7 @@ func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsil } // InEpsilonf asserts that expected and actual have a relative error less than epsilon +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -979,9 +1077,11 @@ func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon fl // IsDecreasing asserts that the collection is decreasing // -// assert.IsDecreasing(t, []int{2, 1, 0}) -// assert.IsDecreasing(t, []float{2, 1}) -// assert.IsDecreasing(t, []string{"b", "a"}) +// require.IsDecreasing(t, []int{2, 1, 0}) +// require.IsDecreasing(t, []float{2, 1}) +// require.IsDecreasing(t, []string{"b", "a"}) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -994,9 +1094,11 @@ func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { // IsDecreasingf asserts that the collection is decreasing // -// assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") -// assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") -// assert.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") +// require.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") +// require.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") +// require.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1009,9 +1111,11 @@ func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface // IsIncreasing asserts that the collection is increasing // -// assert.IsIncreasing(t, []int{1, 2, 3}) -// assert.IsIncreasing(t, []float{1, 2}) -// assert.IsIncreasing(t, []string{"a", "b"}) +// require.IsIncreasing(t, []int{1, 2, 3}) +// require.IsIncreasing(t, []float{1, 2}) +// require.IsIncreasing(t, []string{"a", "b"}) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1024,9 +1128,11 @@ func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { // IsIncreasingf asserts that the collection is increasing // -// assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") -// assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") -// assert.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") +// require.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") +// require.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") +// require.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1039,9 +1145,11 @@ func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface // IsNonDecreasing asserts that the collection is not decreasing // -// assert.IsNonDecreasing(t, []int{1, 1, 2}) -// assert.IsNonDecreasing(t, []float{1, 2}) -// assert.IsNonDecreasing(t, []string{"a", "b"}) +// require.IsNonDecreasing(t, []int{1, 1, 2}) +// require.IsNonDecreasing(t, []float{1, 2}) +// require.IsNonDecreasing(t, []string{"a", "b"}) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1054,9 +1162,11 @@ func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // IsNonDecreasingf asserts that the collection is not decreasing // -// assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") -// assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") -// assert.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") +// require.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") +// require.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") +// require.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1069,9 +1179,11 @@ func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interf // IsNonIncreasing asserts that the collection is not increasing // -// assert.IsNonIncreasing(t, []int{2, 1, 1}) -// assert.IsNonIncreasing(t, []float{2, 1}) -// assert.IsNonIncreasing(t, []string{"b", "a"}) +// require.IsNonIncreasing(t, []int{2, 1, 1}) +// require.IsNonIncreasing(t, []float{2, 1}) +// require.IsNonIncreasing(t, []string{"b", "a"}) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1084,9 +1196,11 @@ func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // IsNonIncreasingf asserts that the collection is not increasing // -// assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") -// assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") -// assert.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") +// require.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") +// require.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") +// require.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1098,6 +1212,7 @@ func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interf } // IsType asserts that the specified objects are of the same type. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1109,6 +1224,7 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs } // IsTypef asserts that the specified objects are of the same type. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1121,7 +1237,9 @@ func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg strin // JSONEq asserts that two JSON strings are equivalent. // -// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) +// require.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1134,7 +1252,9 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ // JSONEqf asserts that two JSON strings are equivalent. // -// assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") +// require.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1148,7 +1268,9 @@ func JSONEqf(t TestingT, expected string, actual string, msg string, args ...int // Len asserts that the specified object has specific length. // Len also fails if the object has a type that len() not accept. // -// assert.Len(t, mySlice, 3) +// require.Len(t, mySlice, 3) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1162,7 +1284,9 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) // Lenf asserts that the specified object has specific length. // Lenf also fails if the object has a type that len() not accept. // -// assert.Lenf(t, mySlice, 3, "error message %s", "formatted") +// require.Lenf(t, mySlice, 3, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1175,9 +1299,11 @@ func Lenf(t TestingT, object interface{}, length int, msg string, args ...interf // Less asserts that the first element is less than the second // -// assert.Less(t, 1, 2) -// assert.Less(t, float64(1), float64(2)) -// assert.Less(t, "a", "b") +// require.Less(t, 1, 2) +// require.Less(t, float64(1), float64(2)) +// require.Less(t, "a", "b") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1190,10 +1316,12 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) // LessOrEqual asserts that the first element is less than or equal to the second // -// assert.LessOrEqual(t, 1, 2) -// assert.LessOrEqual(t, 2, 2) -// assert.LessOrEqual(t, "a", "b") -// assert.LessOrEqual(t, "b", "b") +// require.LessOrEqual(t, 1, 2) +// require.LessOrEqual(t, 2, 2) +// require.LessOrEqual(t, "a", "b") +// require.LessOrEqual(t, "b", "b") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1206,10 +1334,12 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter // LessOrEqualf asserts that the first element is less than or equal to the second // -// assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") -// assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") -// assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") -// assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") +// require.LessOrEqualf(t, 1, 2, "error message %s", "formatted") +// require.LessOrEqualf(t, 2, 2, "error message %s", "formatted") +// require.LessOrEqualf(t, "a", "b", "error message %s", "formatted") +// require.LessOrEqualf(t, "b", "b", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1222,9 +1352,11 @@ func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args . // Lessf asserts that the first element is less than the second // -// assert.Lessf(t, 1, 2, "error message %s", "formatted") -// assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") -// assert.Lessf(t, "a", "b", "error message %s", "formatted") +// require.Lessf(t, 1, 2, "error message %s", "formatted") +// require.Lessf(t, float64(1), float64(2), "error message %s", "formatted") +// require.Lessf(t, "a", "b", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1237,8 +1369,10 @@ func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...inter // Negative asserts that the specified element is negative // -// assert.Negative(t, -1) -// assert.Negative(t, -1.23) +// require.Negative(t, -1) +// require.Negative(t, -1.23) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1251,8 +1385,10 @@ func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { // Negativef asserts that the specified element is negative // -// assert.Negativef(t, -1, "error message %s", "formatted") -// assert.Negativef(t, -1.23, "error message %s", "formatted") +// require.Negativef(t, -1, "error message %s", "formatted") +// require.Negativef(t, -1.23, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1266,7 +1402,9 @@ func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { // Never asserts that the given condition doesn't satisfy in waitFor time, // periodically checking the target function each tick. // -// assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) +// require.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1280,7 +1418,9 @@ func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.D // Neverf asserts that the given condition doesn't satisfy in waitFor time, // periodically checking the target function each tick. // -// assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +// require.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1293,7 +1433,9 @@ func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time. // Nil asserts that the specified object is nil. // -// assert.Nil(t, err) +// require.Nil(t, err) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1306,7 +1448,9 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // Nilf asserts that the specified object is nil. // -// assert.Nilf(t, err, "error message %s", "formatted") +// require.Nilf(t, err, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1319,6 +1463,7 @@ func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { // NoDirExists checks whether a directory does not exist in the given path. // It fails if the path points to an existing _directory_ only. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1331,6 +1476,7 @@ func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { // NoDirExistsf checks whether a directory does not exist in the given path. // It fails if the path points to an existing _directory_ only. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1344,9 +1490,11 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { // NoError asserts that a function returned no error (i.e. `nil`). // // actualObj, err := SomeFunction() -// if assert.NoError(t, err) { -// assert.Equal(t, expectedObj, actualObj) +// if require.NoError(t, err) { +// require.Equal(t, expectedObj, actualObj) // } +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NoError(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1360,9 +1508,11 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) { // NoErrorf asserts that a function returned no error (i.e. `nil`). // // actualObj, err := SomeFunction() -// if assert.NoErrorf(t, err, "error message %s", "formatted") { -// assert.Equal(t, expectedObj, actualObj) +// if require.NoErrorf(t, err, "error message %s", "formatted") { +// require.Equal(t, expectedObj, actualObj) // } +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1375,6 +1525,7 @@ func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { // NoFileExists checks whether a file does not exist in a given path. It fails // if the path points to an existing _file_ only. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1387,6 +1538,7 @@ func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { // NoFileExistsf checks whether a file does not exist in a given path. It fails // if the path points to an existing _file_ only. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1400,9 +1552,11 @@ func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the // specified substring or element. // -// assert.NotContains(t, "Hello World", "Earth") -// assert.NotContains(t, ["Hello", "World"], "Earth") -// assert.NotContains(t, {"Hello": "World"}, "Earth") +// require.NotContains(t, "Hello World", "Earth") +// require.NotContains(t, ["Hello", "World"], "Earth") +// require.NotContains(t, {"Hello": "World"}, "Earth") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1416,9 +1570,11 @@ func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ... // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the // specified substring or element. // -// assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") -// assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") -// assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") +// require.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") +// require.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") +// require.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1434,11 +1590,12 @@ func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, a // the number of appearances of each of them in both lists should not match. // This is an inverse of ElementsMatch. // -// assert.NotElementsMatch(t, [1, 1, 2, 3], [1, 1, 2, 3]) -> false +// require.NotElementsMatch(t, [1, 1, 2, 3], [1, 1, 2, 3]) -> false // -// assert.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true +// require.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true // -// assert.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true +// require.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1454,11 +1611,12 @@ func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndAr // the number of appearances of each of them in both lists should not match. // This is an inverse of ElementsMatch. // -// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false +// require.NotElementsMatchf(t, [1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false // -// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true +// require.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true // -// assert.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true +// require.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1472,9 +1630,11 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either // a slice or a channel with len == 0. // -// if assert.NotEmpty(t, obj) { -// assert.Equal(t, "two", obj[1]) +// if require.NotEmpty(t, obj) { +// require.Equal(t, "two", obj[1]) // } +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1488,9 +1648,11 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either // a slice or a channel with len == 0. // -// if assert.NotEmptyf(t, obj, "error message %s", "formatted") { -// assert.Equal(t, "two", obj[1]) +// if require.NotEmptyf(t, obj, "error message %s", "formatted") { +// require.Equal(t, "two", obj[1]) // } +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1503,10 +1665,11 @@ func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) // NotEqual asserts that the specified values are NOT equal. // -// assert.NotEqual(t, obj1, obj2) +// require.NotEqual(t, obj1, obj2) // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1519,7 +1682,9 @@ func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs . // NotEqualValues asserts that two objects are not equal even when converted to the same type // -// assert.NotEqualValues(t, obj1, obj2) +// require.NotEqualValues(t, obj1, obj2) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1532,7 +1697,9 @@ func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAnd // NotEqualValuesf asserts that two objects are not equal even when converted to the same type // -// assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") +// require.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1545,10 +1712,11 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s // NotEqualf asserts that the specified values are NOT equal. // -// assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted") +// require.NotEqualf(t, obj1, obj2, "error message %s", "formatted") // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1561,6 +1729,7 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, // NotErrorIs asserts that at none of the errors in err's chain matches target. // This is a wrapper for errors.Is. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1573,6 +1742,7 @@ func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) // NotErrorIsf asserts that at none of the errors in err's chain matches target. // This is a wrapper for errors.Is. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1585,7 +1755,9 @@ func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interf // NotImplements asserts that an object does not implement the specified interface. // -// assert.NotImplements(t, (*MyInterface)(nil), new(MyObject)) +// require.NotImplements(t, (*MyInterface)(nil), new(MyObject)) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1598,7 +1770,9 @@ func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, // NotImplementsf asserts that an object does not implement the specified interface. // -// assert.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +// require.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1611,7 +1785,9 @@ func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, // NotNil asserts that the specified object is not nil. // -// assert.NotNil(t, err) +// require.NotNil(t, err) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1624,7 +1800,9 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // NotNilf asserts that the specified object is not nil. // -// assert.NotNilf(t, err, "error message %s", "formatted") +// require.NotNilf(t, err, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1637,7 +1815,9 @@ func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. // -// assert.NotPanics(t, func(){ RemainCalm() }) +// require.NotPanics(t, func(){ RemainCalm() }) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1650,7 +1830,9 @@ func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. // -// assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") +// require.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1663,8 +1845,10 @@ func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interfac // NotRegexp asserts that a specified regexp does not match a string. // -// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") -// assert.NotRegexp(t, "^start", "it's not starting") +// require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") +// require.NotRegexp(t, "^start", "it's not starting") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1677,8 +1861,10 @@ func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interf // NotRegexpf asserts that a specified regexp does not match a string. // -// assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") -// assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") +// require.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") +// require.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1691,10 +1877,11 @@ func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args .. // NotSame asserts that two pointers do not reference the same object. // -// assert.NotSame(t, ptr1, ptr2) +// require.NotSame(t, ptr1, ptr2) // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1707,10 +1894,11 @@ func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. // NotSamef asserts that two pointers do not reference the same object. // -// assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted") +// require.NotSamef(t, ptr1, ptr2, "error message %s", "formatted") // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1725,8 +1913,10 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, // contain all elements given in the specified subset list(array, slice...) or // map. // -// assert.NotSubset(t, [1, 3, 4], [1, 2]) -// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) +// require.NotSubset(t, [1, 3, 4], [1, 2]) +// require.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1741,8 +1931,10 @@ func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...i // contain all elements given in the specified subset list(array, slice...) or // map. // -// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") -// assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") +// require.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") +// require.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1754,6 +1946,7 @@ func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, ar } // NotZero asserts that i is not the zero value for its type. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1765,6 +1958,7 @@ func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { } // NotZerof asserts that i is not the zero value for its type. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1777,7 +1971,9 @@ func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { // Panics asserts that the code inside the specified PanicTestFunc panics. // -// assert.Panics(t, func(){ GoCrazy() }) +// require.Panics(t, func(){ GoCrazy() }) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1792,7 +1988,9 @@ func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // panics, and that the recovered panic value is an error that satisfies the // EqualError comparison. // -// assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) +// require.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1807,7 +2005,9 @@ func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAn // panics, and that the recovered panic value is an error that satisfies the // EqualError comparison. // -// assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") +// require.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1821,7 +2021,9 @@ func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that // the recovered panic value equals the expected panic value. // -// assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) +// require.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1835,7 +2037,9 @@ func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, m // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that // the recovered panic value equals the expected panic value. // -// assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") +// require.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1848,7 +2052,9 @@ func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, // Panicsf asserts that the code inside the specified PanicTestFunc panics. // -// assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") +// require.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1861,8 +2067,10 @@ func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{} // Positive asserts that the specified element is positive // -// assert.Positive(t, 1) -// assert.Positive(t, 1.23) +// require.Positive(t, 1) +// require.Positive(t, 1.23) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1875,8 +2083,10 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { // Positivef asserts that the specified element is positive // -// assert.Positivef(t, 1, "error message %s", "formatted") -// assert.Positivef(t, 1.23, "error message %s", "formatted") +// require.Positivef(t, 1, "error message %s", "formatted") +// require.Positivef(t, 1.23, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1889,8 +2099,10 @@ func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { // Regexp asserts that a specified regexp matches a string. // -// assert.Regexp(t, regexp.MustCompile("start"), "it's starting") -// assert.Regexp(t, "start...$", "it's not starting") +// require.Regexp(t, regexp.MustCompile("start"), "it's starting") +// require.Regexp(t, "start...$", "it's not starting") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1903,8 +2115,10 @@ func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface // Regexpf asserts that a specified regexp matches a string. // -// assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") -// assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") +// require.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") +// require.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1917,10 +2131,11 @@ func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...in // Same asserts that two pointers reference the same object. // -// assert.Same(t, ptr1, ptr2) +// require.Same(t, ptr1, ptr2) // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1933,10 +2148,11 @@ func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...in // Samef asserts that two pointers reference the same object. // -// assert.Samef(t, ptr1, ptr2, "error message %s", "formatted") +// require.Samef(t, ptr1, ptr2, "error message %s", "formatted") // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1950,8 +2166,10 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg // Subset asserts that the specified list(array, slice...) or map contains all // elements given in the specified subset list(array, slice...) or map. // -// assert.Subset(t, [1, 2, 3], [1, 2]) -// assert.Subset(t, {"x": 1, "y": 2}, {"x": 1}) +// require.Subset(t, [1, 2, 3], [1, 2]) +// require.Subset(t, {"x": 1, "y": 2}, {"x": 1}) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1965,8 +2183,10 @@ func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...inte // Subsetf asserts that the specified list(array, slice...) or map contains all // elements given in the specified subset list(array, slice...) or map. // -// assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") -// assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") +// require.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") +// require.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1979,7 +2199,9 @@ func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args // True asserts that the specified value is true. // -// assert.True(t, myBool) +// require.True(t, myBool) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func True(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1992,7 +2214,9 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) { // Truef asserts that the specified value is true. // -// assert.Truef(t, myBool, "error message %s", "formatted") +// require.Truef(t, myBool, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Truef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2005,7 +2229,9 @@ func Truef(t TestingT, value bool, msg string, args ...interface{}) { // WithinDuration asserts that the two times are within duration delta of each other. // -// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) +// require.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2018,7 +2244,9 @@ func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time // WithinDurationf asserts that the two times are within duration delta of each other. // -// assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") +// require.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2031,7 +2259,9 @@ func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta tim // WithinRange asserts that a time is within a time range (inclusive). // -// assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) +// require.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2044,7 +2274,9 @@ func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, m // WithinRangef asserts that a time is within a time range (inclusive). // -// assert.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted") +// require.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted") +// +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2056,6 +2288,7 @@ func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, } // YAMLEq asserts that two YAML strings are equivalent. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2067,6 +2300,7 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ } // YAMLEqf asserts that two YAML strings are equivalent. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2078,6 +2312,7 @@ func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...int } // Zero asserts that i is the zero value for its type. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2089,6 +2324,7 @@ func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { } // Zerof asserts that i is the zero value for its type. +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require.go.tmpl b/require/require.go.tmpl index 55e42dd..ded85af 100644 --- a/require/require.go.tmpl +++ b/require/require.go.tmpl @@ -1,4 +1,5 @@ -{{.Comment}} +{{ replace .Comment "assert." "require."}} +// Instead of returning a boolean result this function calls `t.FailNow()` on failure. func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { if h, ok := t.(tHelper); ok { h.Helper() } if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } From 84619f5c3cc34b4aec7872962246d19f99abf81c Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Thu, 13 Jun 2024 05:57:39 -0700 Subject: [PATCH 13/52] fix: grammar in godoc for NotErrorIs(f) functions (#1607) 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. --- assert/assertion_format.go | 2 +- assert/assertion_forward.go | 4 ++-- assert/assertions.go | 2 +- require/require.go | 4 ++-- require/require_forward.go | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index ad39523..546fe1f 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -621,7 +621,7 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) } -// NotErrorIsf asserts that at none of the errors in err's chain matches target. +// NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index d90c65d..8504dca 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -1234,7 +1234,7 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str return NotEqualf(a.t, expected, actual, msg, args...) } -// NotErrorIs asserts that at none of the errors in err's chain matches target. +// NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { @@ -1243,7 +1243,7 @@ func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface return NotErrorIs(a.t, err, target, msgAndArgs...) } -// NotErrorIsf asserts that at none of the errors in err's chain matches target. +// NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func (a *Assertions) NotErrorIsf(err error, target error, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { diff --git a/assert/assertions.go b/assert/assertions.go index 7f16cb8..45777f0 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2094,7 +2094,7 @@ func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { ), msgAndArgs...) } -// NotErrorIs asserts that at none of the errors in err's chain matches target. +// NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { diff --git a/require/require.go b/require/require.go index 59b87c8..d0c73ff 100644 --- a/require/require.go +++ b/require/require.go @@ -1559,7 +1559,7 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, t.FailNow() } -// NotErrorIs asserts that at none of the errors in err's chain matches target. +// NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { @@ -1571,7 +1571,7 @@ func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) t.FailNow() } -// NotErrorIsf asserts that at none of the errors in err's chain matches target. +// NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { diff --git a/require/require_forward.go b/require/require_forward.go index 389de9a..3c15ca3 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -1235,7 +1235,7 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str NotEqualf(a.t, expected, actual, msg, args...) } -// NotErrorIs asserts that at none of the errors in err's chain matches target. +// NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { @@ -1244,7 +1244,7 @@ func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface NotErrorIs(a.t, err, target, msgAndArgs...) } -// NotErrorIsf asserts that at none of the errors in err's chain matches target. +// NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func (a *Assertions) NotErrorIsf(err error, target error, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { From 044c46a89fc0d0f106a7293ae9622a7b6cf14150 Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Thu, 13 Jun 2024 15:40:29 +0200 Subject: [PATCH 14/52] Update require.go.tmpl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Olivier Mengué --- require/require.go.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/require/require.go.tmpl b/require/require.go.tmpl index ded85af..11cca94 100644 --- a/require/require.go.tmpl +++ b/require/require.go.tmpl @@ -1,5 +1,5 @@ {{ replace .Comment "assert." "require."}} -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { if h, ok := t.(tHelper); ok { h.Helper() } if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } From f71de4a756dd594795b9a68167d53e000f2ead45 Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Thu, 13 Jun 2024 18:02:19 +0200 Subject: [PATCH 15/52] updated message --- require/require.go | 296 ++++++++++++++++++++++----------------------- 1 file changed, 148 insertions(+), 148 deletions(-) diff --git a/require/require.go b/require/require.go index 102dd7f..b94398f 100644 --- a/require/require.go +++ b/require/require.go @@ -10,7 +10,7 @@ import ( ) // Condition uses a Comparison to assert a complex condition. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -22,7 +22,7 @@ func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { } // Conditionf uses a Comparison to assert a complex condition. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -40,7 +40,7 @@ func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interfac // require.Contains(t, ["Hello", "World"], "World") // require.Contains(t, {"Hello": "World"}, "Hello") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -58,7 +58,7 @@ func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...int // require.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") // require.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -71,7 +71,7 @@ func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args // DirExists checks whether a directory exists in the given path. It also fails // if the path is a file rather a directory or there is an error checking whether it exists. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -84,7 +84,7 @@ func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { // DirExistsf checks whether a directory exists in the given path. It also fails // if the path is a file rather a directory or there is an error checking whether it exists. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -100,7 +100,7 @@ func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { // the number of appearances of each of them in both lists should match. // // require.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -116,7 +116,7 @@ func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs // the number of appearances of each of them in both lists should match. // // require.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -132,7 +132,7 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string // // require.Empty(t, obj) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -148,7 +148,7 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // // require.Emptyf(t, obj, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -166,7 +166,7 @@ func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). Function equality // cannot be determined and will always fail. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -183,7 +183,7 @@ func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...i // actualObj, err := SomeFunction() // require.EqualError(t, err, expectedErrorString) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -200,7 +200,7 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte // actualObj, err := SomeFunction() // require.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -222,7 +222,7 @@ func EqualErrorf(t TestingT, theError error, errString string, msg string, args // require.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true // require.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -244,7 +244,7 @@ func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, m // require.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true // require.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -260,7 +260,7 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, // // require.EqualValues(t, uint32(123), int32(123)) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -276,7 +276,7 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg // // require.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -294,7 +294,7 @@ func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg stri // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). Function equality // cannot be determined and will always fail. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -312,7 +312,7 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar // require.Equal(t, expectedError, err) // } // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Error(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -325,7 +325,7 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) { // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. // This is a wrapper for errors.As. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -338,7 +338,7 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. // This is a wrapper for errors.As. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -355,7 +355,7 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int // actualObj, err := SomeFunction() // require.ErrorContains(t, err, expectedErrorSubString) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -372,7 +372,7 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in // actualObj, err := SomeFunction() // require.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -385,7 +385,7 @@ func ErrorContainsf(t TestingT, theError error, contains string, msg string, arg // ErrorIs asserts that at least one of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -398,7 +398,7 @@ func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { // ErrorIsf asserts that at least one of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -416,7 +416,7 @@ func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface // require.Equal(t, expectedErrorf, err) // } // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Errorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -432,7 +432,7 @@ func Errorf(t TestingT, err error, msg string, args ...interface{}) { // // require.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -462,7 +462,7 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t // require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -492,7 +492,7 @@ func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitF // require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -508,7 +508,7 @@ func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), wait // // require.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -523,7 +523,7 @@ func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick // // require.Exactly(t, int32(123), int64(123)) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -538,7 +538,7 @@ func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. // // require.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -550,7 +550,7 @@ func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, } // Fail reports a failure through -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -562,7 +562,7 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } // FailNow fails test -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -574,7 +574,7 @@ func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } // FailNowf fails test -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -586,7 +586,7 @@ func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{} } // Failf reports a failure through -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -601,7 +601,7 @@ func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { // // require.False(t, myBool) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func False(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -616,7 +616,7 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) { // // require.Falsef(t, myBool, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Falsef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -629,7 +629,7 @@ func Falsef(t TestingT, value bool, msg string, args ...interface{}) { // FileExists checks whether a file exists in the given path. It also fails if // the path points to a directory or there is an error when trying to check the file. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -642,7 +642,7 @@ func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { // FileExistsf checks whether a file exists in the given path. It also fails if // the path points to a directory or there is an error when trying to check the file. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -659,7 +659,7 @@ func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { // require.Greater(t, float64(2), float64(1)) // require.Greater(t, "b", "a") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -677,7 +677,7 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface // require.GreaterOrEqual(t, "b", "a") // require.GreaterOrEqual(t, "b", "b") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -695,7 +695,7 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in // require.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") // require.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -712,7 +712,7 @@ func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, arg // require.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") // require.Greaterf(t, "b", "a", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -729,7 +729,7 @@ func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...in // require.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -746,7 +746,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url s // require.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -763,7 +763,7 @@ func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url // require.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -780,7 +780,7 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, ur // require.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -796,7 +796,7 @@ func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, u // require.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -812,7 +812,7 @@ func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, // require.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -828,7 +828,7 @@ func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, // require.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -844,7 +844,7 @@ func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url strin // require.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -860,7 +860,7 @@ func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url stri // require.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -876,7 +876,7 @@ func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url str // require.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -892,7 +892,7 @@ func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url st // require.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -908,7 +908,7 @@ func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string // require.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -923,7 +923,7 @@ func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url strin // // require.Implements(t, (*MyInterface)(nil), new(MyObject)) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -938,7 +938,7 @@ func Implements(t TestingT, interfaceObject interface{}, object interface{}, msg // // require.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -953,7 +953,7 @@ func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, ms // // require.InDelta(t, math.Pi, 22/7.0, 0.01) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -965,7 +965,7 @@ func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64 } // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -977,7 +977,7 @@ func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delt } // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -989,7 +989,7 @@ func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, del } // InDeltaSlice is the same as InDelta, except it compares two slices. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1001,7 +1001,7 @@ func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta fl } // InDeltaSlicef is the same as InDelta, except it compares two slices. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1016,7 +1016,7 @@ func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta f // // require.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1028,7 +1028,7 @@ func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float6 } // InEpsilon asserts that expected and actual have a relative error less than epsilon -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1040,7 +1040,7 @@ func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon flo } // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1052,7 +1052,7 @@ func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilo } // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1064,7 +1064,7 @@ func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsil } // InEpsilonf asserts that expected and actual have a relative error less than epsilon -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1081,7 +1081,7 @@ func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon fl // require.IsDecreasing(t, []float{2, 1}) // require.IsDecreasing(t, []string{"b", "a"}) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1098,7 +1098,7 @@ func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { // require.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") // require.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1115,7 +1115,7 @@ func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface // require.IsIncreasing(t, []float{1, 2}) // require.IsIncreasing(t, []string{"a", "b"}) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1132,7 +1132,7 @@ func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { // require.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") // require.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1149,7 +1149,7 @@ func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface // require.IsNonDecreasing(t, []float{1, 2}) // require.IsNonDecreasing(t, []string{"a", "b"}) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1166,7 +1166,7 @@ func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // require.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") // require.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1183,7 +1183,7 @@ func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interf // require.IsNonIncreasing(t, []float{2, 1}) // require.IsNonIncreasing(t, []string{"b", "a"}) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1200,7 +1200,7 @@ func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // require.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") // require.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1212,7 +1212,7 @@ func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interf } // IsType asserts that the specified objects are of the same type. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1224,7 +1224,7 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs } // IsTypef asserts that the specified objects are of the same type. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1239,7 +1239,7 @@ func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg strin // // require.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1254,7 +1254,7 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ // // require.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1270,7 +1270,7 @@ func JSONEqf(t TestingT, expected string, actual string, msg string, args ...int // // require.Len(t, mySlice, 3) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1286,7 +1286,7 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) // // require.Lenf(t, mySlice, 3, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1303,7 +1303,7 @@ func Lenf(t TestingT, object interface{}, length int, msg string, args ...interf // require.Less(t, float64(1), float64(2)) // require.Less(t, "a", "b") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1321,7 +1321,7 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) // require.LessOrEqual(t, "a", "b") // require.LessOrEqual(t, "b", "b") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1339,7 +1339,7 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter // require.LessOrEqualf(t, "a", "b", "error message %s", "formatted") // require.LessOrEqualf(t, "b", "b", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1356,7 +1356,7 @@ func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args . // require.Lessf(t, float64(1), float64(2), "error message %s", "formatted") // require.Lessf(t, "a", "b", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1372,7 +1372,7 @@ func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...inter // require.Negative(t, -1) // require.Negative(t, -1.23) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1388,7 +1388,7 @@ func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { // require.Negativef(t, -1, "error message %s", "formatted") // require.Negativef(t, -1.23, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1404,7 +1404,7 @@ func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { // // require.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1420,7 +1420,7 @@ func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.D // // require.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1435,7 +1435,7 @@ func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time. // // require.Nil(t, err) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1450,7 +1450,7 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // // require.Nilf(t, err, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1463,7 +1463,7 @@ func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { // NoDirExists checks whether a directory does not exist in the given path. // It fails if the path points to an existing _directory_ only. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1476,7 +1476,7 @@ func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { // NoDirExistsf checks whether a directory does not exist in the given path. // It fails if the path points to an existing _directory_ only. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1494,7 +1494,7 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { // require.Equal(t, expectedObj, actualObj) // } // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoError(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1512,7 +1512,7 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) { // require.Equal(t, expectedObj, actualObj) // } // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1525,7 +1525,7 @@ func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { // NoFileExists checks whether a file does not exist in a given path. It fails // if the path points to an existing _file_ only. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1538,7 +1538,7 @@ func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { // NoFileExistsf checks whether a file does not exist in a given path. It fails // if the path points to an existing _file_ only. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1556,7 +1556,7 @@ func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { // require.NotContains(t, ["Hello", "World"], "Earth") // require.NotContains(t, {"Hello": "World"}, "Earth") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1574,7 +1574,7 @@ func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ... // require.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") // require.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1595,7 +1595,7 @@ func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, a // require.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true // // require.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1616,7 +1616,7 @@ func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndAr // require.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true // // require.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1634,7 +1634,7 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str // require.Equal(t, "two", obj[1]) // } // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1652,7 +1652,7 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // require.Equal(t, "two", obj[1]) // } // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1669,7 +1669,7 @@ func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1684,7 +1684,7 @@ func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs . // // require.NotEqualValues(t, obj1, obj2) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1699,7 +1699,7 @@ func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAnd // // require.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1716,7 +1716,7 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1729,7 +1729,7 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, // NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1742,7 +1742,7 @@ func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) // NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1757,7 +1757,7 @@ func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interf // // require.NotImplements(t, (*MyInterface)(nil), new(MyObject)) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1772,7 +1772,7 @@ func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, // // require.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1787,7 +1787,7 @@ func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, // // require.NotNil(t, err) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1802,7 +1802,7 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // // require.NotNilf(t, err, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1817,7 +1817,7 @@ func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { // // require.NotPanics(t, func(){ RemainCalm() }) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1832,7 +1832,7 @@ func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // // require.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1848,7 +1848,7 @@ func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interfac // require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") // require.NotRegexp(t, "^start", "it's not starting") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1864,7 +1864,7 @@ func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interf // require.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") // require.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1881,7 +1881,7 @@ func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args .. // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1898,7 +1898,7 @@ func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1916,7 +1916,7 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, // require.NotSubset(t, [1, 3, 4], [1, 2]) // require.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1934,7 +1934,7 @@ func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...i // require.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") // require.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1946,7 +1946,7 @@ func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, ar } // NotZero asserts that i is not the zero value for its type. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1958,7 +1958,7 @@ func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { } // NotZerof asserts that i is not the zero value for its type. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1973,7 +1973,7 @@ func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { // // require.Panics(t, func(){ GoCrazy() }) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1990,7 +1990,7 @@ func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // // require.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2007,7 +2007,7 @@ func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAn // // require.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2023,7 +2023,7 @@ func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg // // require.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2039,7 +2039,7 @@ func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, m // // require.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2054,7 +2054,7 @@ func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, // // require.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2070,7 +2070,7 @@ func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{} // require.Positive(t, 1) // require.Positive(t, 1.23) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2086,7 +2086,7 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { // require.Positivef(t, 1, "error message %s", "formatted") // require.Positivef(t, 1.23, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2102,7 +2102,7 @@ func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { // require.Regexp(t, regexp.MustCompile("start"), "it's starting") // require.Regexp(t, "start...$", "it's not starting") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2118,7 +2118,7 @@ func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface // require.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") // require.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2135,7 +2135,7 @@ func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...in // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2152,7 +2152,7 @@ func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...in // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2169,7 +2169,7 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg // require.Subset(t, [1, 2, 3], [1, 2]) // require.Subset(t, {"x": 1, "y": 2}, {"x": 1}) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2186,7 +2186,7 @@ func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...inte // require.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") // require.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2201,7 +2201,7 @@ func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args // // require.True(t, myBool) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func True(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2216,7 +2216,7 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) { // // require.Truef(t, myBool, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Truef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2231,7 +2231,7 @@ func Truef(t TestingT, value bool, msg string, args ...interface{}) { // // require.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2246,7 +2246,7 @@ func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time // // require.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2261,7 +2261,7 @@ func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta tim // // require.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2276,7 +2276,7 @@ func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, m // // require.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted") // -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2288,7 +2288,7 @@ func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, } // YAMLEq asserts that two YAML strings are equivalent. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2300,7 +2300,7 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ } // YAMLEqf asserts that two YAML strings are equivalent. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2312,7 +2312,7 @@ func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...int } // Zero asserts that i is the zero value for its type. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2324,7 +2324,7 @@ func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { } // Zerof asserts that i is the zero value for its type. -// Instead of returning a boolean result this function calls `t.FailNow()` on failure. +// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() From b074924938f86d417f1c9a845c7e8b0784d7f937 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Thu, 13 Jun 2024 23:09:51 +0300 Subject: [PATCH 16/52] assert: collect.FailNow() should not panic (#1481) ## 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 --- assert/assertions.go | 30 ++++++++++++++++++++++-------- assert/assertions_test.go | 20 +++++++++++++++----- require/requirements_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 45777f0..104a0c9 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1956,6 +1956,9 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t // CollectT implements the TestingT interface and collects all errors. type CollectT struct { + // A slice of errors. Non-nil slice denotes a failure. + // If it's non-nil but len(c.errors) == 0, this is also a failure + // obtained by direct c.FailNow() call. errors []error } @@ -1964,9 +1967,10 @@ func (c *CollectT) Errorf(format string, args ...interface{}) { c.errors = append(c.errors, fmt.Errorf(format, args...)) } -// FailNow panics. -func (*CollectT) FailNow() { - panic("Assertion failed") +// FailNow stops execution by calling runtime.Goexit. +func (c *CollectT) FailNow() { + c.fail() + runtime.Goexit() } // Deprecated: That was a method for internal usage that should not have been published. Now just panics. @@ -1979,6 +1983,16 @@ func (*CollectT) Copy(TestingT) { panic("Copy() is deprecated") } +func (c *CollectT) fail() { + if !c.failed() { + c.errors = []error{} // Make it non-nil to mark a failure. + } +} + +func (c *CollectT) failed() bool { + return c.errors != nil +} + // EventuallyWithT asserts that given condition will be met in waitFor time, // periodically checking target function each tick. In contrast to Eventually, // it supplies a CollectT to the condition function, so that the condition @@ -2003,7 +2017,7 @@ func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time } var lastFinishedTickErrs []error - ch := make(chan []error, 1) + ch := make(chan *CollectT, 1) timer := time.NewTimer(waitFor) defer timer.Stop() @@ -2023,16 +2037,16 @@ func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time go func() { collect := new(CollectT) defer func() { - ch <- collect.errors + ch <- collect }() condition(collect) }() - case errs := <-ch: - if len(errs) == 0 { + case collect := <-ch: + if !collect.failed() { return true } // Keep the errors from the last ended condition, so that they can be copied to t if timeout is reached. - lastFinishedTickErrs = errs + lastFinishedTickErrs = collect.errors tick = ticker.C } } diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 8b87727..064b92f 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -2923,16 +2923,15 @@ func TestEventuallyWithTFalse(t *testing.T) { func TestEventuallyWithTTrue(t *testing.T) { mockT := new(errorsCapturingT) - state := 0 + counter := 0 condition := func(collect *CollectT) { - defer func() { - state += 1 - }() - True(collect, state == 2) + counter += 1 + True(collect, counter == 2) } True(t, EventuallyWithT(mockT, condition, 100*time.Millisecond, 20*time.Millisecond)) Len(t, mockT.errors, 0) + Equal(t, 2, counter, "Condition is expected to be called 2 times") } func TestEventuallyWithT_ConcurrencySafe(t *testing.T) { @@ -2970,6 +2969,17 @@ func TestEventuallyWithT_ReturnsTheLatestFinishedConditionErrors(t *testing.T) { Len(t, mockT.errors, 2) } +func TestEventuallyWithTFailNow(t *testing.T) { + mockT := new(CollectT) + + condition := func(collect *CollectT) { + collect.FailNow() + } + + False(t, EventuallyWithT(mockT, condition, 100*time.Millisecond, 20*time.Millisecond)) + Len(t, mockT.errors, 1) +} + func TestNeverFalse(t *testing.T) { condition := func() bool { return false diff --git a/require/requirements_test.go b/require/requirements_test.go index febf0c1..824b159 100644 --- a/require/requirements_test.go +++ b/require/requirements_test.go @@ -5,6 +5,8 @@ import ( "errors" "testing" "time" + + "github.com/stretchr/testify/assert" ) // AssertionTesterInterface defines an interface to be used for testing assertion methods @@ -681,3 +683,30 @@ func TestErrorAssertionFunc(t *testing.T) { }) } } + +func TestEventuallyWithTFalse(t *testing.T) { + mockT := new(MockT) + + condition := func(collect *assert.CollectT) { + True(collect, false) + } + + EventuallyWithT(mockT, condition, 100*time.Millisecond, 20*time.Millisecond) + True(t, mockT.Failed, "Check should fail") +} + +func TestEventuallyWithTTrue(t *testing.T) { + mockT := new(MockT) + + counter := 0 + condition := func(collect *assert.CollectT) { + defer func() { + counter += 1 + }() + True(collect, counter == 1) + } + + EventuallyWithT(mockT, condition, 100*time.Millisecond, 20*time.Millisecond) + False(t, mockT.Failed, "Check should pass") + Equal(t, 2, counter, "Condition is expected to be called 2 times") +} From 52df55490e922b9229bf066cd8f28664cf84de33 Mon Sep 17 00:00:00 2001 From: Harald Nordgren Date: Wed, 24 Jul 2024 13:39:26 +0200 Subject: [PATCH 17/52] .github/workflows: Run tests for Go 1.22 --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9458c39..1dd4e65 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,6 +29,7 @@ jobs: - "1.19" - "1.20" - "1.21" + - "1.22" steps: - uses: actions/checkout@v4 - name: Setup Go From da63673a11ab3babfaffb7501ef4108c505af6bb Mon Sep 17 00:00:00 2001 From: Joseph Dallago Date: Thu, 29 Aug 2024 22:05:04 +0300 Subject: [PATCH 18/52] Now properly record the ReturnArguments as part of the call. --- mock/mock.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index d5eb1ef..372c8e5 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -80,12 +80,12 @@ type Call struct { requires []*Call } -func newCall(parent *Mock, methodName string, callerInfo []string, methodArguments ...interface{}) *Call { +func newCall(parent *Mock, methodName string, callerInfo []string, methodArguments Arguments, returnArguments Arguments) *Call { return &Call{ Parent: parent, Method: methodName, Arguments: methodArguments, - ReturnArguments: make([]interface{}, 0), + ReturnArguments: returnArguments, callerInfo: callerInfo, Repeatability: 0, WaitFor: nil, @@ -351,7 +351,8 @@ func (m *Mock) On(methodName string, arguments ...interface{}) *Call { m.mutex.Lock() defer m.mutex.Unlock() - c := newCall(m, methodName, assert.CallerInfo(), arguments...) + + c := newCall(m, methodName, assert.CallerInfo(), arguments, make([]interface{}, 0)) m.ExpectedCalls = append(m.ExpectedCalls, c) return c } @@ -529,7 +530,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen call.totalCalls++ // add the call - m.Calls = append(m.Calls, *newCall(m, methodName, assert.CallerInfo(), arguments...)) + m.Calls = append(m.Calls, *newCall(m, methodName, assert.CallerInfo(), arguments, call.ReturnArguments)) m.mutex.Unlock() // block if specified From 7268a5bc0bb240a58a3f85d04076ad9ae13e2cb2 Mon Sep 17 00:00:00 2001 From: Reynier Ortiz Date: Fri, 6 Sep 2024 09:18:07 -0400 Subject: [PATCH 19/52] mock: in order mock calls --- mock/mock.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mock/mock.go b/mock/mock.go index d5eb1ef..6446445 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -273,6 +273,13 @@ func (c *Call) NotBefore(calls ...*Call) *Call { return c } +// InOrder defines the order in which the calls should be made +func InOrder(calls ...*Call) { + for i := 1; i < len(calls); i++ { + calls[i].NotBefore(calls[i-1]) + } +} + // Mock is the workhorse used to track activity on another object. // For an example of its usage, refer to the "Example Usage" section at the top // of this document. From e943930404ddd99e7481c92aabebbc589385b6b9 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Sun, 13 Nov 2022 21:32:28 +0000 Subject: [PATCH 20/52] fix(suite): test failures Fix TestFailfastSuite when run with go test flag -count=X where X greater than 1. --- suite/suite_test.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/suite/suite_test.go b/suite/suite_test.go index db57a5f..b97eb43 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -604,14 +604,44 @@ func TestFailfastSuite(t *testing.T) { }}, ) assert.False(t, ok) + var expect []string if failFast { // Test A Fails and because we are running with failfast Test B never runs and we proceed straight to TearDownSuite - assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";")) + expect = []string{"SetupSuite", "SetupTest", "Test A Fails", "TearDownTest", "TearDownSuite"} } else { // Test A Fails and because we are running without failfast we continue and run Test B and then proceed to TearDownSuite - assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;SetupTest;Test B Passes;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";")) + expect = []string{"SetupSuite", "SetupTest", "Test A Fails", "TearDownTest", "SetupTest", "Test B Passes", "TearDownTest", "TearDownSuite"} } + callOrderAssert(t, expect, s.callOrder) } + +type tHelper interface { + Helper() +} + +// callOrderAssert is a help with confirms that asserts that expect +// matches one or more times in callOrder. This makes it compatible +// with go test flag -count=X where X > 1. +func callOrderAssert(t *testing.T, expect, callOrder []string) { + var ti interface{} = t + if h, ok := ti.(tHelper); ok { + h.Helper() + } + + callCount := len(callOrder) + expectCount := len(expect) + if callCount > expectCount && callCount%expectCount == 0 { + // Command line flag -count=X where X > 1. + for len(callOrder) >= expectCount { + assert.Equal(t, expect, callOrder[:expectCount]) + callOrder = callOrder[expectCount:] + } + return + } + + assert.Equal(t, expect, callOrder) +} + func TestFailfastSuiteFailFastOn(t *testing.T) { // To test this with failfast on (and isolated from other intended test failures in our test suite) we launch it in its own process cmd := exec.Command("go", "test", "-v", "-race", "-run", "TestFailfastSuite", "-failfast") From bdb1271ed89c8de6881bc02cfe700bb91bc9a990 Mon Sep 17 00:00:00 2001 From: Reynier Ortiz Date: Fri, 6 Sep 2024 09:18:07 -0400 Subject: [PATCH 21/52] mock: in order mock calls --- mock/mock_test.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/mock/mock_test.go b/mock/mock_test.go index b80a8a7..bc3c5ad 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -937,6 +937,30 @@ func Test_Mock_Return_NotBefore_In_Order(t *testing.T) { }) } +func Test_Mock_Return_InOrder_Uses_NotBefore(t *testing.T) { + var mockedService = new(TestExampleImplementation) + + b := mockedService. + On("TheExampleMethod", 1, 2, 3). + Return(4, nil) + c := mockedService. + On("TheExampleMethod2", true). + Return() + + InOrder( + b, + c, + ) + + require.Equal(t, []*Call{b, c}, mockedService.ExpectedCalls) + require.NotPanics(t, func() { + mockedService.TheExampleMethod(1, 2, 3) + }) + require.NotPanics(t, func() { + mockedService.TheExampleMethod2(true) + }) +} + func Test_Mock_Return_NotBefore_Out_Of_Order(t *testing.T) { var mockedService = new(TestExampleImplementation) @@ -967,6 +991,40 @@ TheExampleMethod(int,int,int) }) } +func Test_Mock_Return_InOrder_Uses_NotBefore_Out_Of_Order(t *testing.T) { + var mockedService = new(TestExampleImplementation) + + b := mockedService. + On("TheExampleMethod", 1, 2, 3). + Return(4, nil).Twice() + c := mockedService. + On("TheExampleMethod2", true). + Return() + + InOrder( + b, + c, + ) + + require.Equal(t, []*Call{b, c}, mockedService.ExpectedCalls) + + expectedPanicString := `mock: Unexpected Method Call +----------------------------- + +TheExampleMethod2(bool) + 0: true + +Must not be called before: + +TheExampleMethod(int,int,int) + 0: 1 + 1: 2 + 2: 3` + require.PanicsWithValue(t, expectedPanicString, func() { + mockedService.TheExampleMethod2(true) + }) +} + func Test_Mock_Return_NotBefore_Not_Enough_Times(t *testing.T) { var mockedService = new(TestExampleImplementation) @@ -1022,6 +1080,7 @@ func Test_Mock_Return_NotBefore_Different_Mock_In_Order(t *testing.T) { mockedService2.TheExampleMethod2(true) }) } + func Test_Mock_Return_NotBefore_Different_Mock_Out_Of_Order(t *testing.T) { var ( mockedService1 = new(TestExampleImplementation) From f17409f81f93ebd964caa7a36793134d68e23fdb Mon Sep 17 00:00:00 2001 From: Reynier Ortiz Date: Fri, 6 Sep 2024 09:18:07 -0400 Subject: [PATCH 22/52] mock: in order mock calls (requested changes applied) --- mock/mock.go | 7 +++++++ mock/mock_test.go | 33 ++++++++++++--------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 6446445..920a87a 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -274,6 +274,13 @@ func (c *Call) NotBefore(calls ...*Call) *Call { } // InOrder defines the order in which the calls should be made +// +// For example: +// +// InOrder( +// Mock.On("init").Return(nil), +// Mock.On("Do").Return(nil), +// ) func InOrder(calls ...*Call) { for i := 1; i < len(calls); i++ { calls[i].NotBefore(calls[i-1]) diff --git a/mock/mock_test.go b/mock/mock_test.go index bc3c5ad..4878b67 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -940,19 +940,15 @@ func Test_Mock_Return_NotBefore_In_Order(t *testing.T) { func Test_Mock_Return_InOrder_Uses_NotBefore(t *testing.T) { var mockedService = new(TestExampleImplementation) - b := mockedService. - On("TheExampleMethod", 1, 2, 3). - Return(4, nil) - c := mockedService. - On("TheExampleMethod2", true). - Return() - InOrder( - b, - c, + mockedService. + On("TheExampleMethod", 1, 2, 3). + Return(4, nil), + mockedService. + On("TheExampleMethod2", true). + Return(), ) - require.Equal(t, []*Call{b, c}, mockedService.ExpectedCalls) require.NotPanics(t, func() { mockedService.TheExampleMethod(1, 2, 3) }) @@ -994,20 +990,15 @@ TheExampleMethod(int,int,int) func Test_Mock_Return_InOrder_Uses_NotBefore_Out_Of_Order(t *testing.T) { var mockedService = new(TestExampleImplementation) - b := mockedService. - On("TheExampleMethod", 1, 2, 3). - Return(4, nil).Twice() - c := mockedService. - On("TheExampleMethod2", true). - Return() - InOrder( - b, - c, + mockedService. + On("TheExampleMethod", 1, 2, 3). + Return(4, nil).Twice(), + mockedService. + On("TheExampleMethod2", true). + Return(), ) - require.Equal(t, []*Call{b, c}, mockedService.ExpectedCalls) - expectedPanicString := `mock: Unexpected Method Call ----------------------------- From ea6964c2e96c2c682acc94781c71d861e21c94fc Mon Sep 17 00:00:00 2001 From: spirin Date: Mon, 30 Sep 2024 21:33:46 +0300 Subject: [PATCH 23/52] mock: caller information for unexpected method call --- mock/mock.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index d5eb1ef..a4b7b08 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -491,11 +491,12 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen m.mutex.Unlock() if closestCall != nil { - m.fail("\n\nmock: Unexpected Method Call\n-----------------------------\n\n%s\n\nThe closest call I have is: \n\n%s\n\n%s\nDiff: %s", + m.fail("\n\nmock: Unexpected Method Call\n-----------------------------\n\n%s\n\nThe closest call I have is: \n\n%s\n\n%s\nDiff: %s\nat: %s\n", callString(methodName, arguments, true), callString(methodName, closestCall.Arguments, true), diffArguments(closestCall.Arguments, arguments), strings.TrimSpace(mismatch), + assert.CallerInfo(), ) } else { m.fail("\nassert: mock: I don't know what to return because the method call was unexpected.\n\tEither do Mock.On(\"%s\").Return(...) first, or remove the %s() call.\n\tThis method was unexpected:\n\t\t%s\n\tat: %s", methodName, methodName, callString(methodName, arguments, true), assert.CallerInfo()) From d62ca68bf5d930468044ce3b7286c12a63079c22 Mon Sep 17 00:00:00 2001 From: spirin Date: Tue, 1 Oct 2024 02:21:38 +0300 Subject: [PATCH 24/52] tests --- mock/mock_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mock/mock_test.go b/mock/mock_test.go index b80a8a7..95159d8 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -1980,7 +1980,7 @@ func TestArgumentMatcherToPrintMismatch(t *testing.T) { defer func() { if r := recover(); r != nil { matchingExp := regexp.MustCompile( - `\s+mock: Unexpected Method Call\s+-*\s+GetTime\(int\)\s+0: 1\s+The closest call I have is:\s+GetTime\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*\(int=1\) not matched by func\(int\) bool`) + `\s+mock: Unexpected Method Call\s+-*\s+GetTime\(int\)\s+0: 1\s+The closest call I have is:\s+GetTime\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*\(int=1\) not matched by func\(int\) bool\nat: \[[^\]]+mock\/mock_test.go`) assert.Regexp(t, matchingExp, r) } }() @@ -1997,7 +1997,7 @@ func TestArgumentMatcherToPrintMismatchWithReferenceType(t *testing.T) { defer func() { if r := recover(); r != nil { matchingExp := regexp.MustCompile( - `\s+mock: Unexpected Method Call\s+-*\s+GetTimes\(\[\]int\)\s+0: \[\]int\{1\}\s+The closest call I have is:\s+GetTimes\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*\(\[\]int=\[1\]\) not matched by func\(\[\]int\) bool`) + `\s+mock: Unexpected Method Call\s+-*\s+GetTimes\(\[\]int\)\s+0: \[\]int\{1\}\s+The closest call I have is:\s+GetTimes\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*\(\[\]int=\[1\]\) not matched by func\(\[\]int\) bool\nat: \[[^\]]+mock\/mock_test.go`) assert.Regexp(t, matchingExp, r) } }() @@ -2028,7 +2028,7 @@ func TestClosestCallMismatchedArgumentInformationShowsTheClosest(t *testing.T) { func TestClosestCallFavorsFirstMock(t *testing.T) { defer func() { if r := recover(); r != nil { - diffRegExp := `Difference found in argument 0:\s+--- Expected\s+\+\+\+ Actual\s+@@ -2,4 \+2,4 @@\s+\(bool\) true,\s+- \(bool\) true,\s+- \(bool\) true\s+\+ \(bool\) false,\s+\+ \(bool\) false\s+}\s+` + diffRegExp := `Difference found in argument 0:\s+--- Expected\s+\+\+\+ Actual\s+@@ -2,4 \+2,4 @@\s+\(bool\) true,\s+- \(bool\) true,\s+- \(bool\) true\s+\+ \(bool\) false,\s+\+ \(bool\) false\s+}\s+Diff: 0: FAIL: \(\[\]bool=\[(true\s?|false\s?){3}]\) != \(\[\]bool=\[(true\s?|false\s?){3}\]\)` matchingExp := regexp.MustCompile(unexpectedCallRegex(`TheExampleMethod7([]bool)`, `0: \[\]bool{true, false, false}`, `0: \[\]bool{true, true, true}`, diffRegExp)) assert.Regexp(t, matchingExp, r) } @@ -2044,7 +2044,7 @@ func TestClosestCallFavorsFirstMock(t *testing.T) { func TestClosestCallUsesRepeatabilityToFindClosest(t *testing.T) { defer func() { if r := recover(); r != nil { - diffRegExp := `Difference found in argument 0:\s+--- Expected\s+\+\+\+ Actual\s+@@ -1,4 \+1,4 @@\s+\(\[\]bool\) \(len=3\) {\s+- \(bool\) false,\s+- \(bool\) false,\s+\+ \(bool\) true,\s+\+ \(bool\) true,\s+\(bool\) false\s+` + diffRegExp := `Difference found in argument 0:\s+--- Expected\s+\+\+\+ Actual\s+@@ -1,4 \+1,4 @@\s+\(\[\]bool\) \(len=3\) {\s+- \(bool\) false,\s+- \(bool\) false,\s+\+ \(bool\) true,\s+\+ \(bool\) true,\s+\(bool\) false\s+Diff: 0: FAIL: \(\[\]bool=\[(true\s?|false\s?){3}]\) != \(\[\]bool=\[(true\s?|false\s?){3}\]\)` matchingExp := regexp.MustCompile(unexpectedCallRegex(`TheExampleMethod7([]bool)`, `0: \[\]bool{true, true, false}`, `0: \[\]bool{false, false, false}`, diffRegExp)) assert.Regexp(t, matchingExp, r) } @@ -2101,7 +2101,7 @@ func Test_isBetterMatchThanReturnsFalseIfRepeatabilityIsLessThanOrEqualToOther(t func unexpectedCallRegex(method, calledArg, expectedArg, diff string) string { rMethod := regexp.QuoteMeta(method) - return fmt.Sprintf(`\s+mock: Unexpected Method Call\s+-*\s+%s\s+%s\s+The closest call I have is:\s+%s\s+%s\s+%s`, + return fmt.Sprintf(`\s+mock: Unexpected Method Call\s+-*\s+%s\s+%s\s+The closest call I have is:\s+%s\s+%s\s+%s\nat: \[[^\]]+mock\/mock_test.go`, rMethod, calledArg, rMethod, expectedArg, diff) } From fed9ee68dc942c41c77a9b2c2431f3c2967c00ae Mon Sep 17 00:00:00 2001 From: Bracken Dawson Date: Tue, 1 Oct 2024 23:55:16 +0100 Subject: [PATCH 25/52] Document suite's lack of support for t.Parallel --- README.md | 2 ++ suite/doc.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 0250c3e..ccaa758 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,8 @@ You can use the [mockery tool](https://vektra.github.io/mockery/latest/) to auto [`suite`](https://pkg.go.dev/github.com/stretchr/testify/suite "API documentation") package ----------------------------------------------------------------------------------------- +> [!WARNING] +> The suite package does not support parallel tests. See [#934](https://github.com/stretchr/testify/issues/934). The `suite` package provides functionality that you might be used to from more common object-oriented languages. With it, you can build a testing suite as a struct, build setup/teardown methods and testing methods on your struct, and run them with 'go test' as per normal. diff --git a/suite/doc.go b/suite/doc.go index 8d55a3a..05a562f 100644 --- a/suite/doc.go +++ b/suite/doc.go @@ -5,6 +5,8 @@ // or individual tests (depending on which interface(s) you // implement). // +// The suite package does not support parallel tests. See [issue 934]. +// // A testing suite is usually built by first extending the built-in // suite functionality from suite.Suite in testify. Alternatively, // you could reproduce that logic on your own if you wanted (you @@ -63,4 +65,6 @@ // func TestExampleTestSuite(t *testing.T) { // suite.Run(t, new(ExampleTestSuite)) // } +// +// [issue 934]: https://github.com/stretchr/testify/issues/934 package suite From 3380867632684d2023eeeb0d5d1d45a7b89e6972 Mon Sep 17 00:00:00 2001 From: Pal Sivertsen Date: Tue, 30 Nov 2021 14:26:04 +0100 Subject: [PATCH 26/52] Add NotErrorAs assertion The library already had assertions for `ErrorIs`, `NotErrorIs` and `ErrorAs`. This commit adds the `NotErrorAs` assertion which is the inverse of `ErrorAs`. --- assert/assertion_format.go | 9 +++++++++ assert/assertion_forward.go | 18 ++++++++++++++++++ assert/assertions.go | 18 ++++++++++++++++++ assert/assertions_test.go | 27 ++++++++++++++++++++++++++- require/require.go | 24 ++++++++++++++++++++++++ require/require_forward.go | 18 ++++++++++++++++++ 6 files changed, 113 insertions(+), 1 deletion(-) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 546fe1f..1db3955 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -621,6 +621,15 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) } +// NotErrorAsf asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return NotErrorAs(t, err, target, append([]interface{}{msg}, args...)...) +} + // NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool { diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index 8504dca..a658b4d 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -1234,6 +1234,24 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str return NotEqualf(a.t, expected, actual, msg, args...) } +// NotErrorAs asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return NotErrorAs(a.t, err, target, msgAndArgs...) +} + +// NotErrorAsf asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return NotErrorAsf(a.t, err, target, msg, args...) +} + // NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface{}) bool { diff --git a/assert/assertions.go b/assert/assertions.go index 104a0c9..5ace3d4 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2149,6 +2149,24 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ ), msgAndArgs...) } +// NotErrorAs asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if !errors.As(err, target) { + return true + } + + chain := buildErrorChainString(err) + + return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ + "found: %q\n"+ + "in chain: %s", target, chain, + ), msgAndArgs...) +} + func buildErrorChainString(err error) string { if err == nil { return "" diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 064b92f..228f20a 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -3284,7 +3284,32 @@ func TestErrorAs(t *testing.T) { t.Run(fmt.Sprintf("ErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) { res := ErrorAs(mockT, tt.err, &target) if res != tt.result { - t.Errorf("ErrorAs(%#v,%#v) should return %t)", tt.err, target, tt.result) + t.Errorf("ErrorAs(%#v,%#v) should return %t", tt.err, target, tt.result) + } + }) + } +} + +func TestNotErrorAs(t *testing.T) { + tests := []struct { + err error + result bool + }{ + {fmt.Errorf("wrap: %w", &customError{}), false}, + {io.EOF, true}, + {nil, true}, + } + for _, tt := range tests { + tt := tt + var target *customError + t.Run(fmt.Sprintf("NotErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) { + mockT := new(testing.T) + res := NotErrorAs(mockT, tt.err, &target) + if res != tt.result { + t.Errorf("NotErrorAs(%#v,%#v) should not return %t", tt.err, target, tt.result) + } + if res == mockT.Failed() { + t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !mockT.Failed()) } }) } diff --git a/require/require.go b/require/require.go index d0c73ff..bf9877c 100644 --- a/require/require.go +++ b/require/require.go @@ -1559,6 +1559,30 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, t.FailNow() } +// NotErrorAs asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.NotErrorAs(t, err, target, msgAndArgs...) { + return + } + t.FailNow() +} + +// NotErrorAsf asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.NotErrorAsf(t, err, target, msg, args...) { + return + } + t.FailNow() +} + // NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { diff --git a/require/require_forward.go b/require/require_forward.go index 3c15ca3..521daaf 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -1235,6 +1235,24 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str NotEqualf(a.t, expected, actual, msg, args...) } +// NotErrorAs asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + NotErrorAs(a.t, err, target, msgAndArgs...) +} + +// NotErrorAsf asserts that at none of the errors in err's chain matches target. +// This is the inverse of the ErrorAs function. +func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + NotErrorAsf(a.t, err, target, msg, args...) +} + // NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface{}) { From aade8450b3812d4f2e5d4cb65769b264c4604328 Mon Sep 17 00:00:00 2001 From: Pal Sivertsen Date: Tue, 30 Nov 2021 14:29:39 +0100 Subject: [PATCH 27/52] Improve tests for ErrorIs/ErrorAs Checks that the assertion result matches what's set in `testing.T`. --- assert/assertions_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 228f20a..20d63b1 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -3269,7 +3269,6 @@ func TestNotErrorIs(t *testing.T) { } func TestErrorAs(t *testing.T) { - mockT := new(testing.T) tests := []struct { err error result bool @@ -3282,10 +3281,14 @@ func TestErrorAs(t *testing.T) { tt := tt var target *customError t.Run(fmt.Sprintf("ErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) { + mockT := new(testing.T) res := ErrorAs(mockT, tt.err, &target) if res != tt.result { t.Errorf("ErrorAs(%#v,%#v) should return %t", tt.err, target, tt.result) } + if res == mockT.Failed() { + t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !mockT.Failed()) + } }) } } From dc100b1be3ac644d59bccf1f4b9b00261eb10f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Sivertsen?= Date: Fri, 4 Oct 2024 09:52:45 +0200 Subject: [PATCH 28/52] Review: Drop doc line and fix typo Review feedback: https://github.com/stretchr/testify/pull/1129#discussion_r1786495803 --- assert/assertion_format.go | 3 +-- assert/assertion_forward.go | 6 ++---- assert/assertions.go | 3 +-- require/require.go | 6 ++---- require/require_forward.go | 6 ++---- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 1db3955..2dff9e4 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -621,8 +621,7 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) } -// NotErrorAsf asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAsf asserts that none of the errors in err's chain matches target. func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index a658b4d..7bcc9f0 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -1234,8 +1234,7 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str return NotEqualf(a.t, expected, actual, msg, args...) } -// NotErrorAs asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAs asserts that none of the errors in err's chain matches target. func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1243,8 +1242,7 @@ func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...int return NotErrorAs(a.t, err, target, msgAndArgs...) } -// NotErrorAsf asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAsf asserts that none of the errors in err's chain matches target. func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/assert/assertions.go b/assert/assertions.go index 5ace3d4..4ebe302 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2149,8 +2149,7 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ ), msgAndArgs...) } -// NotErrorAs asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAs asserts that none of the errors in err's chain matches target. func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require.go b/require/require.go index bf9877c..9871d08 100644 --- a/require/require.go +++ b/require/require.go @@ -1559,8 +1559,7 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, t.FailNow() } -// NotErrorAs asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAs asserts that none of the errors in err's chain matches target. func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1571,8 +1570,7 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa t.FailNow() } -// NotErrorAsf asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAsf asserts that none of the errors in err's chain matches target. func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require_forward.go b/require/require_forward.go index 521daaf..34ac533 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -1235,8 +1235,7 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str NotEqualf(a.t, expected, actual, msg, args...) } -// NotErrorAs asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAs asserts that none of the errors in err's chain matches target. func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1244,8 +1243,7 @@ func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...int NotErrorAs(a.t, err, target, msgAndArgs...) } -// NotErrorAsf asserts that at none of the errors in err's chain matches target. -// This is the inverse of the ErrorAs function. +// NotErrorAsf asserts that none of the errors in err's chain matches target. func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() From f844b269dfdaed00db57ff08e2ff601daa349e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Sivertsen?= Date: Fri, 4 Oct 2024 12:37:24 +0200 Subject: [PATCH 29/52] Review: Expand NotErrorAs func docs https://github.com/stretchr/testify/pull/1129#discussion_r1787490770 --- assert/assertion_format.go | 3 ++- assert/assertion_forward.go | 6 ++++-- assert/assertions.go | 3 ++- require/require.go | 6 ++++-- require/require_forward.go | 6 ++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 2dff9e4..1906341 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -621,7 +621,8 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) } -// NotErrorAsf asserts that none of the errors in err's chain matches target. +// NotErrorAsf asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index 7bcc9f0..2162908 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -1234,7 +1234,8 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str return NotEqualf(a.t, expected, actual, msg, args...) } -// NotErrorAs asserts that none of the errors in err's chain matches target. +// NotErrorAs asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1242,7 +1243,8 @@ func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...int return NotErrorAs(a.t, err, target, msgAndArgs...) } -// NotErrorAsf asserts that none of the errors in err's chain matches target. +// NotErrorAsf asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/assert/assertions.go b/assert/assertions.go index 4ebe302..44b854d 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2149,7 +2149,8 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ ), msgAndArgs...) } -// NotErrorAs asserts that none of the errors in err's chain matches target. +// NotErrorAs asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require.go b/require/require.go index 9871d08..50ec19e 100644 --- a/require/require.go +++ b/require/require.go @@ -1559,7 +1559,8 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, t.FailNow() } -// NotErrorAs asserts that none of the errors in err's chain matches target. +// NotErrorAs asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1570,7 +1571,8 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa t.FailNow() } -// NotErrorAsf asserts that none of the errors in err's chain matches target. +// NotErrorAsf asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require_forward.go b/require/require_forward.go index 34ac533..1bd8730 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -1235,7 +1235,8 @@ func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg str NotEqualf(a.t, expected, actual, msg, args...) } -// NotErrorAs asserts that none of the errors in err's chain matches target. +// NotErrorAs asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1243,7 +1244,8 @@ func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...int NotErrorAs(a.t, err, target, msgAndArgs...) } -// NotErrorAsf asserts that none of the errors in err's chain matches target. +// NotErrorAsf asserts that none of the errors in err's chain matches target, +// but if so, sets target to that error value. func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() From 2063e816961eecfd3a9f80e13fa69f7ef66a4c54 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 4 Oct 2024 18:02:45 +0300 Subject: [PATCH 30/52] assert: fix typos in comments --- assert/assertions_test.go | 2 +- assert/yaml/yaml_custom.go | 2 +- assert/yaml/yaml_default.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 20d63b1..e158688 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -1327,7 +1327,7 @@ func TestNotElementsMatch(t *testing.T) { actual interface{} result bool }{ - // not mathing + // not matching {[]int{1}, []int{}, true}, {[]int{}, []int{2}, true}, {[]int{1}, []int{2}, true}, diff --git a/assert/yaml/yaml_custom.go b/assert/yaml/yaml_custom.go index bc32dc9..baa0cc7 100644 --- a/assert/yaml/yaml_custom.go +++ b/assert/yaml/yaml_custom.go @@ -15,7 +15,7 @@ // import assertYaml "github.com/stretchr/testify/assert/yaml" // // func init() { -// assertYaml.Unmarshall = func (in []byte, out interface{}) error { +// assertYaml.Unmarshal = func (in []byte, out interface{}) error { // // ... // return nil // } diff --git a/assert/yaml/yaml_default.go b/assert/yaml/yaml_default.go index 9a92eed..b83c6cf 100644 --- a/assert/yaml/yaml_default.go +++ b/assert/yaml/yaml_default.go @@ -5,7 +5,7 @@ // // This package is just an indirection that allows the builder to override the // indirection with an alternative implementation of this package that uses -// another implemantation of YAML deserialization. This allows to not either not +// another implementation of YAML deserialization. This allows to not either not // use YAML deserialization at all, or to use another implementation than // [gopkg.in/yaml.v3] (for example for license compatibility reasons, see [PR #1120]). // From ba3e7c34d5ee33bd1dd7d6835daafeaa093525ca Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 4 Oct 2024 18:06:40 +0300 Subject: [PATCH 31/52] mock: fix doc comment for NotBefore --- mock/mock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index 41257fb..0c30941 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -256,7 +256,7 @@ func (c *Call) Unset() *Call { // calls have been called as expected. The referenced calls may be from the // same mock instance and/or other mock instances. // -// Mock.On("Do").Return(nil).Notbefore( +// Mock.On("Do").Return(nil).NotBefore( // Mock.On("Init").Return(nil) // ) func (c *Call) NotBefore(calls ...*Call) *Call { From 3b2754b72fe06f9f41e8998132daaece39d01d7a Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Tue, 15 Oct 2024 13:54:51 +0200 Subject: [PATCH 32/52] remove failure note on require-comments --- require/require.go | 236 ---------------------------------------- require/require.go.tmpl | 1 - 2 files changed, 237 deletions(-) diff --git a/require/require.go b/require/require.go index b94398f..6e52b04 100644 --- a/require/require.go +++ b/require/require.go @@ -10,7 +10,6 @@ import ( ) // Condition uses a Comparison to assert a complex condition. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -22,7 +21,6 @@ func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { } // Conditionf uses a Comparison to assert a complex condition. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -39,8 +37,6 @@ func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interfac // require.Contains(t, "Hello World", "World") // require.Contains(t, ["Hello", "World"], "World") // require.Contains(t, {"Hello": "World"}, "Hello") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -57,8 +53,6 @@ func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...int // require.Containsf(t, "Hello World", "World", "error message %s", "formatted") // require.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") // require.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -71,7 +65,6 @@ func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args // DirExists checks whether a directory exists in the given path. It also fails // if the path is a file rather a directory or there is an error checking whether it exists. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -84,7 +77,6 @@ func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { // DirExistsf checks whether a directory exists in the given path. It also fails // if the path is a file rather a directory or there is an error checking whether it exists. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -100,7 +92,6 @@ func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { // the number of appearances of each of them in both lists should match. // // require.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -116,7 +107,6 @@ func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs // the number of appearances of each of them in both lists should match. // // require.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -131,8 +121,6 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string // a slice or a channel with len == 0. // // require.Empty(t, obj) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -147,8 +135,6 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // a slice or a channel with len == 0. // // require.Emptyf(t, obj, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -166,7 +152,6 @@ func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). Function equality // cannot be determined and will always fail. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -182,8 +167,6 @@ func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...i // // actualObj, err := SomeFunction() // require.EqualError(t, err, expectedErrorString) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -199,8 +182,6 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte // // actualObj, err := SomeFunction() // require.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -221,8 +202,6 @@ func EqualErrorf(t TestingT, theError error, errString string, msg string, args // } // require.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true // require.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -243,8 +222,6 @@ func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, m // } // require.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true // require.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -259,8 +236,6 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, // type and equal. // // require.EqualValues(t, uint32(123), int32(123)) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -275,8 +250,6 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg // type and equal. // // require.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -294,7 +267,6 @@ func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg stri // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). Function equality // cannot be determined and will always fail. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -311,8 +283,6 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar // if require.Error(t, err) { // require.Equal(t, expectedError, err) // } -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Error(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -325,7 +295,6 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) { // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. // This is a wrapper for errors.As. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -338,7 +307,6 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. // This is a wrapper for errors.As. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -354,8 +322,6 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int // // actualObj, err := SomeFunction() // require.ErrorContains(t, err, expectedErrorSubString) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -371,8 +337,6 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in // // actualObj, err := SomeFunction() // require.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -385,7 +349,6 @@ func ErrorContainsf(t TestingT, theError error, contains string, msg string, arg // ErrorIs asserts that at least one of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -398,7 +361,6 @@ func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { // ErrorIsf asserts that at least one of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -415,8 +377,6 @@ func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface // if require.Errorf(t, err, "error message %s", "formatted") { // require.Equal(t, expectedErrorf, err) // } -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Errorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -431,8 +391,6 @@ func Errorf(t TestingT, err error, msg string, args ...interface{}) { // periodically checking target function each tick. // // require.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -461,8 +419,6 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t // // add assertions as needed; any assertion failure will fail the current tick // require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -491,8 +447,6 @@ func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitF // // add assertions as needed; any assertion failure will fail the current tick // require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -507,8 +461,6 @@ func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), wait // periodically checking target function each tick. // // require.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -522,8 +474,6 @@ func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick // Exactly asserts that two objects are equal in value and type. // // require.Exactly(t, int32(123), int64(123)) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -537,8 +487,6 @@ func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. // Exactlyf asserts that two objects are equal in value and type. // // require.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -550,7 +498,6 @@ func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, } // Fail reports a failure through -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -562,7 +509,6 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } // FailNow fails test -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -574,7 +520,6 @@ func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } // FailNowf fails test -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -586,7 +531,6 @@ func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{} } // Failf reports a failure through -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -600,8 +544,6 @@ func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { // False asserts that the specified value is false. // // require.False(t, myBool) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func False(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -615,8 +557,6 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) { // Falsef asserts that the specified value is false. // // require.Falsef(t, myBool, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Falsef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -629,7 +569,6 @@ func Falsef(t TestingT, value bool, msg string, args ...interface{}) { // FileExists checks whether a file exists in the given path. It also fails if // the path points to a directory or there is an error when trying to check the file. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -642,7 +581,6 @@ func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { // FileExistsf checks whether a file exists in the given path. It also fails if // the path points to a directory or there is an error when trying to check the file. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -658,8 +596,6 @@ func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { // require.Greater(t, 2, 1) // require.Greater(t, float64(2), float64(1)) // require.Greater(t, "b", "a") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -676,8 +612,6 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface // require.GreaterOrEqual(t, 2, 2) // require.GreaterOrEqual(t, "b", "a") // require.GreaterOrEqual(t, "b", "b") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -694,8 +628,6 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in // require.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") // require.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") // require.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -711,8 +643,6 @@ func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, arg // require.Greaterf(t, 2, 1, "error message %s", "formatted") // require.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") // require.Greaterf(t, "b", "a", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -729,7 +659,6 @@ func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...in // require.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -746,7 +675,6 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url s // require.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -763,7 +691,6 @@ func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url // require.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -780,7 +707,6 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, ur // require.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -796,7 +722,6 @@ func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, u // require.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -812,7 +737,6 @@ func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, // require.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -828,7 +752,6 @@ func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, // require.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -844,7 +767,6 @@ func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url strin // require.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -860,7 +782,6 @@ func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url stri // require.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -876,7 +797,6 @@ func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url str // require.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -892,7 +812,6 @@ func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url st // require.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -908,7 +827,6 @@ func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string // require.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -922,8 +840,6 @@ func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url strin // Implements asserts that an object is implemented by the specified interface. // // require.Implements(t, (*MyInterface)(nil), new(MyObject)) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -937,8 +853,6 @@ func Implements(t TestingT, interfaceObject interface{}, object interface{}, msg // Implementsf asserts that an object is implemented by the specified interface. // // require.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -952,8 +866,6 @@ func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, ms // InDelta asserts that the two numerals are within delta of each other. // // require.InDelta(t, math.Pi, 22/7.0, 0.01) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -965,7 +877,6 @@ func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64 } // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -977,7 +888,6 @@ func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delt } // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -989,7 +899,6 @@ func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, del } // InDeltaSlice is the same as InDelta, except it compares two slices. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1001,7 +910,6 @@ func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta fl } // InDeltaSlicef is the same as InDelta, except it compares two slices. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1015,8 +923,6 @@ func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta f // InDeltaf asserts that the two numerals are within delta of each other. // // require.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1028,7 +934,6 @@ func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float6 } // InEpsilon asserts that expected and actual have a relative error less than epsilon -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1040,7 +945,6 @@ func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon flo } // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1052,7 +956,6 @@ func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilo } // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1064,7 +967,6 @@ func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsil } // InEpsilonf asserts that expected and actual have a relative error less than epsilon -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1080,8 +982,6 @@ func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon fl // require.IsDecreasing(t, []int{2, 1, 0}) // require.IsDecreasing(t, []float{2, 1}) // require.IsDecreasing(t, []string{"b", "a"}) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1097,8 +997,6 @@ func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { // require.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") // require.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") // require.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1114,8 +1012,6 @@ func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface // require.IsIncreasing(t, []int{1, 2, 3}) // require.IsIncreasing(t, []float{1, 2}) // require.IsIncreasing(t, []string{"a", "b"}) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1131,8 +1027,6 @@ func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { // require.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") // require.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") // require.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1148,8 +1042,6 @@ func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface // require.IsNonDecreasing(t, []int{1, 1, 2}) // require.IsNonDecreasing(t, []float{1, 2}) // require.IsNonDecreasing(t, []string{"a", "b"}) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1165,8 +1057,6 @@ func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // require.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") // require.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") // require.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1182,8 +1072,6 @@ func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interf // require.IsNonIncreasing(t, []int{2, 1, 1}) // require.IsNonIncreasing(t, []float{2, 1}) // require.IsNonIncreasing(t, []string{"b", "a"}) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1199,8 +1087,6 @@ func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // require.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") // require.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") // require.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1212,7 +1098,6 @@ func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interf } // IsType asserts that the specified objects are of the same type. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1224,7 +1109,6 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs } // IsTypef asserts that the specified objects are of the same type. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1238,8 +1122,6 @@ func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg strin // JSONEq asserts that two JSON strings are equivalent. // // require.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1253,8 +1135,6 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ // JSONEqf asserts that two JSON strings are equivalent. // // require.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1269,8 +1149,6 @@ func JSONEqf(t TestingT, expected string, actual string, msg string, args ...int // Len also fails if the object has a type that len() not accept. // // require.Len(t, mySlice, 3) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1285,8 +1163,6 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) // Lenf also fails if the object has a type that len() not accept. // // require.Lenf(t, mySlice, 3, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1302,8 +1178,6 @@ func Lenf(t TestingT, object interface{}, length int, msg string, args ...interf // require.Less(t, 1, 2) // require.Less(t, float64(1), float64(2)) // require.Less(t, "a", "b") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1320,8 +1194,6 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) // require.LessOrEqual(t, 2, 2) // require.LessOrEqual(t, "a", "b") // require.LessOrEqual(t, "b", "b") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1338,8 +1210,6 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter // require.LessOrEqualf(t, 2, 2, "error message %s", "formatted") // require.LessOrEqualf(t, "a", "b", "error message %s", "formatted") // require.LessOrEqualf(t, "b", "b", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1355,8 +1225,6 @@ func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args . // require.Lessf(t, 1, 2, "error message %s", "formatted") // require.Lessf(t, float64(1), float64(2), "error message %s", "formatted") // require.Lessf(t, "a", "b", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1371,8 +1239,6 @@ func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...inter // // require.Negative(t, -1) // require.Negative(t, -1.23) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1387,8 +1253,6 @@ func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { // // require.Negativef(t, -1, "error message %s", "formatted") // require.Negativef(t, -1.23, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1403,8 +1267,6 @@ func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { // periodically checking the target function each tick. // // require.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1419,8 +1281,6 @@ func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.D // periodically checking the target function each tick. // // require.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1434,8 +1294,6 @@ func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time. // Nil asserts that the specified object is nil. // // require.Nil(t, err) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1449,8 +1307,6 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // Nilf asserts that the specified object is nil. // // require.Nilf(t, err, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1463,7 +1319,6 @@ func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { // NoDirExists checks whether a directory does not exist in the given path. // It fails if the path points to an existing _directory_ only. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1476,7 +1331,6 @@ func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { // NoDirExistsf checks whether a directory does not exist in the given path. // It fails if the path points to an existing _directory_ only. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1493,8 +1347,6 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { // if require.NoError(t, err) { // require.Equal(t, expectedObj, actualObj) // } -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoError(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1511,8 +1363,6 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) { // if require.NoErrorf(t, err, "error message %s", "formatted") { // require.Equal(t, expectedObj, actualObj) // } -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1525,7 +1375,6 @@ func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { // NoFileExists checks whether a file does not exist in a given path. It fails // if the path points to an existing _file_ only. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1538,7 +1387,6 @@ func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { // NoFileExistsf checks whether a file does not exist in a given path. It fails // if the path points to an existing _file_ only. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1555,8 +1403,6 @@ func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { // require.NotContains(t, "Hello World", "Earth") // require.NotContains(t, ["Hello", "World"], "Earth") // require.NotContains(t, {"Hello": "World"}, "Earth") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1573,8 +1419,6 @@ func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ... // require.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") // require.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") // require.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1595,7 +1439,6 @@ func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, a // require.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true // // require.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1616,7 +1459,6 @@ func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndAr // require.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true // // require.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1633,8 +1475,6 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str // if require.NotEmpty(t, obj) { // require.Equal(t, "two", obj[1]) // } -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1651,8 +1491,6 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // if require.NotEmptyf(t, obj, "error message %s", "formatted") { // require.Equal(t, "two", obj[1]) // } -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1669,7 +1507,6 @@ func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1683,8 +1520,6 @@ func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs . // NotEqualValues asserts that two objects are not equal even when converted to the same type // // require.NotEqualValues(t, obj1, obj2) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1698,8 +1533,6 @@ func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAnd // NotEqualValuesf asserts that two objects are not equal even when converted to the same type // // require.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1716,7 +1549,6 @@ func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg s // // Pointer variable equality is determined based on the equality of the // referenced values (as opposed to the memory addresses). -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1729,7 +1561,6 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, // NotErrorIs asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1742,7 +1573,6 @@ func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) // NotErrorIsf asserts that none of the errors in err's chain matches target. // This is a wrapper for errors.Is. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1756,8 +1586,6 @@ func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interf // NotImplements asserts that an object does not implement the specified interface. // // require.NotImplements(t, (*MyInterface)(nil), new(MyObject)) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1771,8 +1599,6 @@ func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, // NotImplementsf asserts that an object does not implement the specified interface. // // require.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1786,8 +1612,6 @@ func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, // NotNil asserts that the specified object is not nil. // // require.NotNil(t, err) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1801,8 +1625,6 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // NotNilf asserts that the specified object is not nil. // // require.NotNilf(t, err, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1816,8 +1638,6 @@ func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. // // require.NotPanics(t, func(){ RemainCalm() }) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1831,8 +1651,6 @@ func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. // // require.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1847,8 +1665,6 @@ func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interfac // // require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") // require.NotRegexp(t, "^start", "it's not starting") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1863,8 +1679,6 @@ func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interf // // require.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") // require.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1881,7 +1695,6 @@ func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args .. // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1898,7 +1711,6 @@ func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1915,8 +1727,6 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, // // require.NotSubset(t, [1, 3, 4], [1, 2]) // require.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1933,8 +1743,6 @@ func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...i // // require.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") // require.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1946,7 +1754,6 @@ func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, ar } // NotZero asserts that i is not the zero value for its type. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1958,7 +1765,6 @@ func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { } // NotZerof asserts that i is not the zero value for its type. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1972,8 +1778,6 @@ func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { // Panics asserts that the code inside the specified PanicTestFunc panics. // // require.Panics(t, func(){ GoCrazy() }) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1989,8 +1793,6 @@ func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // EqualError comparison. // // require.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2006,8 +1808,6 @@ func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAn // EqualError comparison. // // require.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2022,8 +1822,6 @@ func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg // the recovered panic value equals the expected panic value. // // require.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2038,8 +1836,6 @@ func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, m // the recovered panic value equals the expected panic value. // // require.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2053,8 +1849,6 @@ func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, // Panicsf asserts that the code inside the specified PanicTestFunc panics. // // require.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2069,8 +1863,6 @@ func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{} // // require.Positive(t, 1) // require.Positive(t, 1.23) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2085,8 +1877,6 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { // // require.Positivef(t, 1, "error message %s", "formatted") // require.Positivef(t, 1.23, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2101,8 +1891,6 @@ func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { // // require.Regexp(t, regexp.MustCompile("start"), "it's starting") // require.Regexp(t, "start...$", "it's not starting") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2117,8 +1905,6 @@ func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface // // require.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") // require.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2135,7 +1921,6 @@ func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...in // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2152,7 +1937,6 @@ func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...in // // Both arguments must be pointer variables. Pointer variable sameness is // determined based on the equality of both type and value. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2168,8 +1952,6 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg // // require.Subset(t, [1, 2, 3], [1, 2]) // require.Subset(t, {"x": 1, "y": 2}, {"x": 1}) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2185,8 +1967,6 @@ func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...inte // // require.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") // require.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2200,8 +1980,6 @@ func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args // True asserts that the specified value is true. // // require.True(t, myBool) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func True(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2215,8 +1993,6 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) { // Truef asserts that the specified value is true. // // require.Truef(t, myBool, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Truef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2230,8 +2006,6 @@ func Truef(t TestingT, value bool, msg string, args ...interface{}) { // WithinDuration asserts that the two times are within duration delta of each other. // // require.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2245,8 +2019,6 @@ func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time // WithinDurationf asserts that the two times are within duration delta of each other. // // require.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2260,8 +2032,6 @@ func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta tim // WithinRange asserts that a time is within a time range (inclusive). // // require.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2275,8 +2045,6 @@ func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, m // WithinRangef asserts that a time is within a time range (inclusive). // // require.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted") -// -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2288,7 +2056,6 @@ func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, } // YAMLEq asserts that two YAML strings are equivalent. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2300,7 +2067,6 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ } // YAMLEqf asserts that two YAML strings are equivalent. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2312,7 +2078,6 @@ func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...int } // Zero asserts that i is the zero value for its type. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2324,7 +2089,6 @@ func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { } // Zerof asserts that i is the zero value for its type. -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/require/require.go.tmpl b/require/require.go.tmpl index 11cca94..8b32836 100644 --- a/require/require.go.tmpl +++ b/require/require.go.tmpl @@ -1,5 +1,4 @@ {{ replace .Comment "assert." "require."}} -// Failure of this check is fatal ([testing.T.FailNow] is called on failure). func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { if h, ok := t.(tHelper); ok { h.Helper() } if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } From 6555fd4da6911f1a3a0e751fbe4fd61c22e809d5 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Wed, 16 Oct 2024 17:25:23 +0300 Subject: [PATCH 33/52] Fix issue #1662 (comparing infs should fail) --- assert/assertions.go | 3 +++ assert/assertions_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/assert/assertions.go b/assert/assertions.go index 44b854d..d4b4bef 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1527,6 +1527,9 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd if err != nil { return Fail(t, err.Error(), msgAndArgs...) } + if math.IsNaN(actualEpsilon) { + return Fail(t, "relative error is NaN", msgAndArgs...) + } if actualEpsilon > epsilon { return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+ " < %#v (actual)", epsilon, actualEpsilon), msgAndArgs...) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index e158688..848a5d8 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -1986,6 +1986,14 @@ func TestInEpsilon(t *testing.T) { {math.NaN(), 0, 1}, {0, math.NaN(), 1}, {0, 0, math.NaN()}, + {math.Inf(1), 1, 1}, + {math.Inf(-1), 1, 1}, + {1, math.Inf(1), 1}, + {1, math.Inf(-1), 1}, + {math.Inf(1), math.Inf(1), 1}, + {math.Inf(1), math.Inf(-1), 1}, + {math.Inf(-1), math.Inf(1), 1}, + {math.Inf(-1), math.Inf(-1), 1}, } for _, tc := range cases { From 9c174eb41c6bd1d44d9aec62f68b8f1c514f3f5f Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Tue, 23 Jul 2024 16:18:22 +0200 Subject: [PATCH 34/52] fix: compare functional option names for indirect calls Closes Functional Options testing broken for indirect calls #1380 --- mock/mock.go | 9 ++++++++- mock/mock_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index 4932833..0097675 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1260,5 +1260,12 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { func funcName(opt interface{}) string { n := runtime.FuncForPC(reflect.ValueOf(opt).Pointer()).Name() - return strings.TrimSuffix(path.Base(n), path.Ext(n)) + trimmed := strings.TrimSuffix(path.Base(n), path.Ext(n)) + splitted := strings.Split(trimmed, ".") + + if len(splitted) == 0 { + return trimmed + } + + return splitted[len(splitted)-1] } diff --git a/mock/mock_test.go b/mock/mock_test.go index d286867..12fb45e 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -55,6 +55,10 @@ func (i *TestExampleImplementation) TheExampleMethodFunctionalOptions(x string, return args.Error(0) } +func TheExampleMethodFunctionalOptionsIndirect(i *TestExampleImplementation) { + i.TheExampleMethodFunctionalOptions("test", OpNum(1), OpStr("foo")) +} + //go:noinline func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) { i.Called(yesorno) @@ -1505,6 +1509,23 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType(t *testing.T) { } +func Test_Mock_AssertExpectationsFunctionalOptionsTypeIndirectly(t *testing.T) { + + var mockedService = new(TestExampleImplementation) + + mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1), OpStr("foo"))).Return(nil).Once() + + tt := new(testing.T) + assert.False(t, mockedService.AssertExpectations(tt)) + + // make the call now + TheExampleMethodFunctionalOptionsIndirect(mockedService) + + // now assert expectations + assert.True(t, mockedService.AssertExpectations(tt)) + +} + func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) { var mockedService = new(TestExampleImplementation) @@ -1522,6 +1543,20 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) { } +func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff(t *testing.T) { + + var mockedService = new(TestExampleImplementation) + + mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1))).Return(nil).Once() + + tt := new(testing.T) + assert.False(t, mockedService.AssertExpectations(tt)) + + assert.Panics(t, func() { + mockedService.TheExampleMethodFunctionalOptions("test", OpStr("1")) + }) +} + func Test_Mock_AssertExpectations_With_Repeatability(t *testing.T) { var mockedService = new(TestExampleImplementation) From 22d3bd5defb6f5dfe50062c22651669393ecdbc5 Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Tue, 23 Jul 2024 16:53:06 +0200 Subject: [PATCH 35/52] in order to remain compatible with go1..19, don't compare function names (but do include them in the diff output) --- mock/mock.go | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 0097675..19ec01d 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1204,17 +1204,10 @@ type tHelper interface { func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { expectedOpts := reflect.ValueOf(expected) actualOpts := reflect.ValueOf(actual) - var expectedNames []string - for i := 0; i < expectedOpts.Len(); i++ { - expectedNames = append(expectedNames, funcName(expectedOpts.Index(i).Interface())) - } - var actualNames []string - for i := 0; i < actualOpts.Len(); i++ { - actualNames = append(actualNames, funcName(actualOpts.Index(i).Interface())) - } - if !assert.ObjectsAreEqual(expectedNames, actualNames) { - expectedFmt = fmt.Sprintf("%v", expectedNames) - actualFmt = fmt.Sprintf("%v", actualNames) + + if expectedOpts.Len() != actualOpts.Len() { + expectedFmt = fmt.Sprintf("%v", expectedOpts) + actualFmt = fmt.Sprintf("%v", actualOpts) return } @@ -1222,14 +1215,6 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { expectedOpt := expectedOpts.Index(i).Interface() actualOpt := actualOpts.Index(i).Interface() - expectedFunc := expectedNames[i] - actualFunc := actualNames[i] - if expectedFunc != actualFunc { - expectedFmt = expectedFunc - actualFmt = actualFunc - return - } - ot := reflect.TypeOf(expectedOpt) var expectedValues []reflect.Value var actualValues []reflect.Value @@ -1248,8 +1233,8 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { for i := 0; i < ot.NumIn(); i++ { if !assert.ObjectsAreEqual(expectedValues[i].Interface(), actualValues[i].Interface()) { - expectedFmt = fmt.Sprintf("%s %+v", expectedNames[i], expectedValues[i].Interface()) - actualFmt = fmt.Sprintf("%s %+v", expectedNames[i], actualValues[i].Interface()) + expectedFmt = fmt.Sprintf("%s %+v", funcName(expectedOpts.Index(i).Interface()), expectedValues[i].Interface()) + actualFmt = fmt.Sprintf("%s %+v", funcName(actualOpts.Index(i).Interface()), actualValues[i].Interface()) return } } From 822223ec3418f3f55230d59b2701b9d6dafff758 Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Tue, 22 Oct 2024 16:04:49 +0200 Subject: [PATCH 36/52] fix name regression --- mock/mock.go | 20 +++++++++++++++++--- mock/mock_test.go | 29 +++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 19ec01d..487dca2 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1211,6 +1211,20 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { return } + var expectedNames []string + for i := 0; i < expectedOpts.Len(); i++ { + expectedNames = append(expectedNames, funcName(expectedOpts.Index(i).Interface())) + } + var actualNames []string + for i := 0; i < actualOpts.Len(); i++ { + actualNames = append(actualNames, funcName(actualOpts.Index(i).Interface())) + } + if !assert.ObjectsAreEqual(expectedNames, actualNames) { + expectedFmt = fmt.Sprintf("%v", expectedNames) + actualFmt = fmt.Sprintf("%v", actualNames) + return + } + for i := 0; i < expectedOpts.Len(); i++ { expectedOpt := expectedOpts.Index(i).Interface() actualOpt := actualOpts.Index(i).Interface() @@ -1232,9 +1246,9 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { reflect.ValueOf(actualOpt).Call(actualValues) for i := 0; i < ot.NumIn(); i++ { - if !assert.ObjectsAreEqual(expectedValues[i].Interface(), actualValues[i].Interface()) { - expectedFmt = fmt.Sprintf("%s %+v", funcName(expectedOpts.Index(i).Interface()), expectedValues[i].Interface()) - actualFmt = fmt.Sprintf("%s %+v", funcName(actualOpts.Index(i).Interface()), actualValues[i].Interface()) + if expectedArg, actualArg := expectedValues[i].Interface(), actualValues[i].Interface(); !assert.ObjectsAreEqual(expectedArg, actualArg) { + expectedFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], expectedArg, expectedArg) + actualFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], actualArg, actualArg) return } } diff --git a/mock/mock_test.go b/mock/mock_test.go index 12fb45e..e5bdaef 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -50,6 +50,13 @@ func OpStr(s string) OptionFn { o.str = s } } + +func OpBytes(b []byte) OptionFn { + return func(m *options) { + m.str = string(b) + } +} + func (i *TestExampleImplementation) TheExampleMethodFunctionalOptions(x string, opts ...OptionFn) error { args := i.Called(x, opts) return args.Error(0) @@ -1509,7 +1516,7 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType(t *testing.T) { } -func Test_Mock_AssertExpectationsFunctionalOptionsTypeIndirectly(t *testing.T) { +func Test_Mock_AssertExpectationsFunctionalOptionsType_Indirectly(t *testing.T) { var mockedService = new(TestExampleImplementation) @@ -1543,17 +1550,31 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) { } -func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff(t *testing.T) { +func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Name(t *testing.T) { var mockedService = new(TestExampleImplementation) - mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1))).Return(nil).Once() + mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpStr("this"))).Return(nil).Once() tt := new(testing.T) assert.False(t, mockedService.AssertExpectations(tt)) assert.Panics(t, func() { - mockedService.TheExampleMethodFunctionalOptions("test", OpStr("1")) + mockedService.TheExampleMethodFunctionalOptions("test", OpBytes([]byte("this"))) + }) +} + +func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Arg(t *testing.T) { + + var mockedService = new(TestExampleImplementation) + + mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpStr("this"))).Return(nil).Once() + + tt := new(testing.T) + assert.False(t, mockedService.AssertExpectations(tt)) + + assert.Panics(t, func() { + mockedService.TheExampleMethodFunctionalOptions("test", OpStr("that")) }) } From 55bac843547859145b0a174024ce495256cff5f8 Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Thu, 24 Oct 2024 11:28:15 +0200 Subject: [PATCH 37/52] reword tests --- mock/mock_test.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mock/mock_test.go b/mock/mock_test.go index e5bdaef..7124923 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -1516,23 +1516,6 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType(t *testing.T) { } -func Test_Mock_AssertExpectationsFunctionalOptionsType_Indirectly(t *testing.T) { - - var mockedService = new(TestExampleImplementation) - - mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1), OpStr("foo"))).Return(nil).Once() - - tt := new(testing.T) - assert.False(t, mockedService.AssertExpectations(tt)) - - // make the call now - TheExampleMethodFunctionalOptionsIndirect(mockedService) - - // now assert expectations - assert.True(t, mockedService.AssertExpectations(tt)) - -} - func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) { var mockedService = new(TestExampleImplementation) @@ -1550,6 +1533,23 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType_Empty(t *testing.T) { } +func Test_Mock_AssertExpectationsFunctionalOptionsType_Indirectly(t *testing.T) { + + var mockedService = new(TestExampleImplementation) + + mockedService.On("TheExampleMethodFunctionalOptions", "test", FunctionalOptions(OpNum(1), OpStr("foo"))).Return(nil).Once() + + tt := new(testing.T) + assert.False(t, mockedService.AssertExpectations(tt)) + + // make the call now + TheExampleMethodFunctionalOptionsIndirect(mockedService) + + // now assert expectations + assert.True(t, mockedService.AssertExpectations(tt)) + +} + func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Name(t *testing.T) { var mockedService = new(TestExampleImplementation) From fb67df63928ed75bbececffbd748155d2620f290 Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Thu, 24 Oct 2024 11:40:45 +0200 Subject: [PATCH 38/52] no regression --- mock/mock.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 487dca2..7ba05b7 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1205,12 +1205,6 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { expectedOpts := reflect.ValueOf(expected) actualOpts := reflect.ValueOf(actual) - if expectedOpts.Len() != actualOpts.Len() { - expectedFmt = fmt.Sprintf("%v", expectedOpts) - actualFmt = fmt.Sprintf("%v", actualOpts) - return - } - var expectedNames []string for i := 0; i < expectedOpts.Len(); i++ { expectedNames = append(expectedNames, funcName(expectedOpts.Index(i).Interface())) @@ -1229,6 +1223,14 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { expectedOpt := expectedOpts.Index(i).Interface() actualOpt := actualOpts.Index(i).Interface() + expectedFunc := expectedNames[i] + actualFunc := actualNames[i] + if expectedFunc != actualFunc { + expectedFmt = expectedFunc + actualFmt = actualFunc + return + } + ot := reflect.TypeOf(expectedOpt) var expectedValues []reflect.Value var actualValues []reflect.Value From be992afabf0732046a842caf78868376945ad245 Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Thu, 24 Oct 2024 13:28:30 +0200 Subject: [PATCH 39/52] trial --- mock/mock.go | 56 +++++++++++++++++++++++++++-------------------- mock/mock_test.go | 2 +- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 7ba05b7..fe35108 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1205,32 +1205,29 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { expectedOpts := reflect.ValueOf(expected) actualOpts := reflect.ValueOf(actual) - var expectedNames []string - for i := 0; i < expectedOpts.Len(); i++ { - expectedNames = append(expectedNames, funcName(expectedOpts.Index(i).Interface())) - } - var actualNames []string - for i := 0; i < actualOpts.Len(); i++ { - actualNames = append(actualNames, funcName(actualOpts.Index(i).Interface())) - } - if !assert.ObjectsAreEqual(expectedNames, actualNames) { - expectedFmt = fmt.Sprintf("%v", expectedNames) - actualFmt = fmt.Sprintf("%v", actualNames) + if expectedOpts.Len() != actualOpts.Len() { + expectedFmt = fmt.Sprintf("%v", expected) + actualFmt = fmt.Sprintf("%v", actual) return } + var funcNames []string + + for i := 0; i < expectedOpts.Len(); i++ { + expectedFunc := getRuntimeFunc(expectedOpts.Index(i).Interface()) + funcNames = append(funcNames, funcName(getRuntimeFunc(expectedFunc))) + + if actualFunc := getRuntimeFunc(actualOpts.Index(i).Interface()); !isFuncSame(expectedFunc, actualFunc) { + expectedFmt = funcName(expectedFunc) + actualFmt = funcName(actualFunc) + return + } + } + for i := 0; i < expectedOpts.Len(); i++ { expectedOpt := expectedOpts.Index(i).Interface() actualOpt := actualOpts.Index(i).Interface() - expectedFunc := expectedNames[i] - actualFunc := actualNames[i] - if expectedFunc != actualFunc { - expectedFmt = expectedFunc - actualFmt = actualFunc - return - } - ot := reflect.TypeOf(expectedOpt) var expectedValues []reflect.Value var actualValues []reflect.Value @@ -1249,8 +1246,8 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { for i := 0; i < ot.NumIn(); i++ { if expectedArg, actualArg := expectedValues[i].Interface(), actualValues[i].Interface(); !assert.ObjectsAreEqual(expectedArg, actualArg) { - expectedFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], expectedArg, expectedArg) - actualFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], actualArg, actualArg) + expectedFmt = fmt.Sprintf("%s(%T) -> %#v", funcNames[i], expectedArg, expectedArg) + actualFmt = fmt.Sprintf("%s(%T) -> %#v", funcNames[i], actualArg, actualArg) return } } @@ -1259,9 +1256,13 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { return "", "" } -func funcName(opt interface{}) string { - n := runtime.FuncForPC(reflect.ValueOf(opt).Pointer()).Name() - trimmed := strings.TrimSuffix(path.Base(n), path.Ext(n)) +func getRuntimeFunc(opt interface{}) *runtime.Func { + return runtime.FuncForPC(reflect.ValueOf(opt).Pointer()) +} + +func funcName(f *runtime.Func) string { + name := f.Name() + trimmed := strings.TrimSuffix(path.Base(name), path.Ext(name)) splitted := strings.Split(trimmed, ".") if len(splitted) == 0 { @@ -1270,3 +1271,10 @@ func funcName(opt interface{}) string { return splitted[len(splitted)-1] } + +func isFuncSame(f1, f2 *runtime.Func) bool { + f1File, f1Loc := f1.FileLine(f1.Entry()) + f2File, f2Loc := f2.FileLine(f2.Entry()) + + return f1File == f2File && f1Loc == f2Loc +} diff --git a/mock/mock_test.go b/mock/mock_test.go index 7124923..2de2773 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -1550,7 +1550,7 @@ func Test_Mock_AssertExpectationsFunctionalOptionsType_Indirectly(t *testing.T) } -func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Name(t *testing.T) { +func Test_Mock_AssertExpectationsFunctionalOptionsType_Diff_Func(t *testing.T) { var mockedService = new(TestExampleImplementation) From 8f049b01221b20d4fba5b8ebfd03b66d576d8cc1 Mon Sep 17 00:00:00 2001 From: "hendry.wiranto" Date: Sun, 10 Dec 2023 14:36:49 +0700 Subject: [PATCH 40/52] link maintainer manifesto on readme instead of v2 notice --- README.md | 3 ++- doc.go | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ccaa758..629a319 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ Testify - Thou Shalt Write Tests ================================ -ℹ️ We are working on testify v2 and would love to hear what you'd like to see in it, have your say here: https://cutt.ly/testify +Notice about Testify V2: +It won't happen due to various reasons. You can read more about it on the maintainer's manifesto [here](https://github.com/stretchr/testify/issues/1089#issuecomment-1812734472). [![Build Status](https://github.com/stretchr/testify/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/stretchr/testify/actions/workflows/main.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/testify)](https://goreportcard.com/report/github.com/stretchr/testify) [![PkgGoDev](https://pkg.go.dev/badge/github.com/stretchr/testify)](https://pkg.go.dev/github.com/stretchr/testify) diff --git a/doc.go b/doc.go index 96407f3..babc122 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,3 @@ -// ** We are working on testify v2 and would love to hear what you'd like to see in it, have your say here: https://cutt.ly/testify ** // Package testify is a set of packages that provide many tools for testifying that your code will behave as you intend. // // testify contains the following packages: From 2780579e15e5bbf58886f170d380caa1ac61f056 Mon Sep 17 00:00:00 2001 From: "hendry.wiranto" Date: Sat, 26 Oct 2024 23:14:23 +0700 Subject: [PATCH 41/52] review: use proper github md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 629a319..b2dbd16 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ Testify - Thou Shalt Write Tests ================================ -Notice about Testify V2: -It won't happen due to various reasons. You can read more about it on the maintainer's manifesto [here](https://github.com/stretchr/testify/issues/1089#issuecomment-1812734472). +> [!NOTE] +> Testify is being maintained at v1, no breaking changes will be accepted in this repo. +> [See discussion about v2](https://github.com/stretchr/testify/discussions/1560). [![Build Status](https://github.com/stretchr/testify/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/stretchr/testify/actions/workflows/main.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/testify)](https://goreportcard.com/report/github.com/stretchr/testify) [![PkgGoDev](https://pkg.go.dev/badge/github.com/stretchr/testify)](https://pkg.go.dev/github.com/stretchr/testify) From ea7129e00694592e20cb34c58a6b8a251418b9da Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Sun, 27 Oct 2024 08:02:53 +0100 Subject: [PATCH 42/52] better fmt --- mock/mock.go | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index fe35108..50eeaba 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1205,21 +1205,31 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { expectedOpts := reflect.ValueOf(expected) actualOpts := reflect.ValueOf(actual) + var expectedFuncs []*runtime.Func + var expectedNames []string + for i := 0; i < expectedOpts.Len(); i++ { + f := runtimeFunc(expectedOpts.Index(i).Interface()) + expectedFuncs = append(expectedFuncs, f) + expectedNames = append(expectedNames, funcName(f)) + } + var actualFuncs []*runtime.Func + var actualNames []string + for i := 0; i < actualOpts.Len(); i++ { + f := runtimeFunc(actualOpts.Index(i).Interface()) + actualFuncs = append(actualFuncs, f) + actualNames = append(actualNames, funcName(f)) + } + if expectedOpts.Len() != actualOpts.Len() { - expectedFmt = fmt.Sprintf("%v", expected) - actualFmt = fmt.Sprintf("%v", actual) + expectedFmt = fmt.Sprintf("%v", expectedNames) + actualFmt = fmt.Sprintf("%v", actualNames) return } - var funcNames []string - for i := 0; i < expectedOpts.Len(); i++ { - expectedFunc := getRuntimeFunc(expectedOpts.Index(i).Interface()) - funcNames = append(funcNames, funcName(getRuntimeFunc(expectedFunc))) - - if actualFunc := getRuntimeFunc(actualOpts.Index(i).Interface()); !isFuncSame(expectedFunc, actualFunc) { - expectedFmt = funcName(expectedFunc) - actualFmt = funcName(actualFunc) + if !isFuncSame(expectedFuncs[i], actualFuncs[i]) { + expectedFmt = expectedNames[i] + actualFmt = actualNames[i] return } } @@ -1246,8 +1256,8 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { for i := 0; i < ot.NumIn(); i++ { if expectedArg, actualArg := expectedValues[i].Interface(), actualValues[i].Interface(); !assert.ObjectsAreEqual(expectedArg, actualArg) { - expectedFmt = fmt.Sprintf("%s(%T) -> %#v", funcNames[i], expectedArg, expectedArg) - actualFmt = fmt.Sprintf("%s(%T) -> %#v", funcNames[i], actualArg, actualArg) + expectedFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], expectedArg, expectedArg) + actualFmt = fmt.Sprintf("%s(%T) -> %#v", expectedNames[i], actualArg, actualArg) return } } @@ -1256,7 +1266,7 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { return "", "" } -func getRuntimeFunc(opt interface{}) *runtime.Func { +func runtimeFunc(opt interface{}) *runtime.Func { return runtime.FuncForPC(reflect.ValueOf(opt).Pointer()) } From 05f87c016035811e6d8371f1887ec360c318f53f Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Sun, 27 Oct 2024 08:05:00 +0100 Subject: [PATCH 43/52] more similar --- mock/mock.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 50eeaba..9f24479 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1227,16 +1227,14 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { } for i := 0; i < expectedOpts.Len(); i++ { + expectedOpt := expectedOpts.Index(i).Interface() + actualOpt := actualOpts.Index(i).Interface() + if !isFuncSame(expectedFuncs[i], actualFuncs[i]) { expectedFmt = expectedNames[i] actualFmt = actualNames[i] return } - } - - for i := 0; i < expectedOpts.Len(); i++ { - expectedOpt := expectedOpts.Index(i).Interface() - actualOpt := actualOpts.Index(i).Interface() ot := reflect.TypeOf(expectedOpt) var expectedValues []reflect.Value From 7d99b2b43d8f60a8982a78cde6e8bd287dea5da0 Mon Sep 17 00:00:00 2001 From: Arjun Dhawan Date: Sun, 27 Oct 2024 08:07:57 +0100 Subject: [PATCH 44/52] attempt 2 --- mock/mock.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 9f24479..eb5682d 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -1227,15 +1227,15 @@ func assertOpts(expected, actual interface{}) (expectedFmt, actualFmt string) { } for i := 0; i < expectedOpts.Len(); i++ { - expectedOpt := expectedOpts.Index(i).Interface() - actualOpt := actualOpts.Index(i).Interface() - if !isFuncSame(expectedFuncs[i], actualFuncs[i]) { expectedFmt = expectedNames[i] actualFmt = actualNames[i] return } + expectedOpt := expectedOpts.Index(i).Interface() + actualOpt := actualOpts.Index(i).Interface() + ot := reflect.TypeOf(expectedOpt) var expectedValues []reflect.Value var actualValues []reflect.Value From 118fb8346630c192421c8914848381af9d4412a7 Mon Sep 17 00:00:00 2001 From: Hisham Akmal Date: Mon, 28 Oct 2024 16:38:04 +0530 Subject: [PATCH 45/52] NotSame should fail if args are not pointers #1661 (#1664) ## Summary Reduces the confusion assosciated with NotSame that previously would check nothing if any of the values is not a pointer. The changes made were tested using TestSame, TestNotSame, and Test_samePointers tests, and the changes did clear the tests. ## Changes 1. Modified samePointers to return another bool value(ok) that would determine if the 2 values are of pointer type or not, while the returned "same" bool value would determine if the 2 pointers are same. 2. Modified assert.NotSame to call Fail() if the 2 values are either i)pointers pointing to the same address or ii)either/both of the values are not pointers. 3. Modified assert.Same to call Fail() if the 2 values are either i)pointers not pointing to the same address or ii)either/both of the values are not pointers. 4. Modified Test_samePointers to handle the new behavior of samePointers by checking both if the inputs are pointers (ok) and if they point to the same object (same). ## Motivation Ensure NotSame accurately verifies pointer sameness by handling non-pointer inputs explicitly, improving clarity and reducing potential misuse. ## Related issues Closes #1661 --------- Co-authored-by: Bracken --- assert/assertions.go | 30 ++++++++++++++------ assert/assertions_test.go | 58 ++++++++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index bfb640a..4e91332 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -502,7 +502,13 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b h.Helper() } - if !samePointers(expected, actual) { + same, ok := samePointers(expected, actual) + if !ok { + return Fail(t, "Both arguments must be pointers", msgAndArgs...) + } + + if !same { + // both are pointers but not the same type & pointing to the same address return Fail(t, fmt.Sprintf("Not same: \n"+ "expected: %p %#v\n"+ "actual : %p %#v", expected, expected, actual, actual), msgAndArgs...) @@ -522,7 +528,13 @@ func NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{} h.Helper() } - if samePointers(expected, actual) { + same, ok := samePointers(expected, actual) + if !ok { + //fails when the arguments are not pointers + return !(Fail(t, "Both arguments must be pointers", msgAndArgs...)) + } + + if same { return Fail(t, fmt.Sprintf( "Expected and actual point to the same object: %p %#v", expected, expected), msgAndArgs...) @@ -530,21 +542,23 @@ func NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{} return true } -// samePointers compares two generic interface objects and returns whether -// they point to the same object -func samePointers(first, second interface{}) bool { +// samePointers checks if two generic interface objects are pointers of the same +// type pointing to the same object. It returns two values: same indicating if +// they are the same type and point to the same object, and ok indicating that +// both inputs are pointers. +func samePointers(first, second interface{}) (same bool, ok bool) { firstPtr, secondPtr := reflect.ValueOf(first), reflect.ValueOf(second) if firstPtr.Kind() != reflect.Ptr || secondPtr.Kind() != reflect.Ptr { - return false + return false, false //not both are pointers } firstType, secondType := reflect.TypeOf(first), reflect.TypeOf(second) if firstType != secondType { - return false + return false, true // both are pointers, but of different types } // compare pointer addresses - return first == second + return first == second, true } // formatUnequalValues takes two values of arbitrary types and returns string diff --git a/assert/assertions_test.go b/assert/assertions_test.go index ca12599..9f859fa 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -655,39 +655,59 @@ func Test_samePointers(t *testing.T) { second interface{} } tests := []struct { - name string - args args - assertion BoolAssertionFunc + name string + args args + same BoolAssertionFunc + ok BoolAssertionFunc }{ { - name: "1 != 2", - args: args{first: 1, second: 2}, - assertion: False, + name: "1 != 2", + args: args{first: 1, second: 2}, + same: False, + ok: False, }, { - name: "1 != 1 (not same ptr)", - args: args{first: 1, second: 1}, - assertion: False, + name: "1 != 1 (not same ptr)", + args: args{first: 1, second: 1}, + same: False, + ok: False, }, { - name: "ptr(1) == ptr(1)", - args: args{first: p, second: p}, - assertion: True, + name: "ptr(1) == ptr(1)", + args: args{first: p, second: p}, + same: True, + ok: True, }, { - name: "int(1) != float32(1)", - args: args{first: int(1), second: float32(1)}, - assertion: False, + name: "int(1) != float32(1)", + args: args{first: int(1), second: float32(1)}, + same: False, + ok: False, }, { - name: "array != slice", - args: args{first: [2]int{1, 2}, second: []int{1, 2}}, - assertion: False, + name: "array != slice", + args: args{first: [2]int{1, 2}, second: []int{1, 2}}, + same: False, + ok: False, + }, + { + name: "non-pointer vs pointer (1 != ptr(2))", + args: args{first: 1, second: p}, + same: False, + ok: False, + }, + { + name: "pointer vs non-pointer (ptr(2) != 1)", + args: args{first: p, second: 1}, + same: False, + ok: False, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - tt.assertion(t, samePointers(tt.args.first, tt.args.second)) + same, ok := samePointers(tt.args.first, tt.args.second) + tt.same(t, same) + tt.ok(t, ok) }) } } From 716de8dff46ed7ae3c6ebb7a6124db741ba7c018 Mon Sep 17 00:00:00 2001 From: sikehish Date: Mon, 28 Oct 2024 23:50:00 +0530 Subject: [PATCH 46/52] Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI --- mock/mock_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mock/mock_test.go b/mock/mock_test.go index d286867..5aab204 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -1256,7 +1256,7 @@ func Test_Mock_Called_blocks(t *testing.T) { var mockedService = new(TestExampleImplementation) - mockedService.Mock.On("asyncCall", 1, 2, 3).Return(5, "6", true).After(2 * time.Millisecond) + mockedService.Mock.On("asyncCall", 1, 2, 3).Return(5, "6", true).After(20 * time.Millisecond) ch := make(chan Arguments) @@ -1265,7 +1265,7 @@ func Test_Mock_Called_blocks(t *testing.T) { select { case <-ch: t.Fatal("should have waited") - case <-time.After(1 * time.Millisecond): + case <-time.After(10 * time.Millisecond): } returnArguments := <-ch From 014ae9a7a4ccff999ad5da28bb21b29715ab427a Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 10 Dec 2024 14:21:03 +0200 Subject: [PATCH 47/52] Replace deprecated io/ioutil with io and os --- _codegen/main.go | 5 ++--- suite/suite_test.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/_codegen/main.go b/_codegen/main.go index 7158afc..e193a74 100644 --- a/_codegen/main.go +++ b/_codegen/main.go @@ -16,7 +16,6 @@ import ( "go/token" "go/types" "io" - "io/ioutil" "log" "os" "path" @@ -101,7 +100,7 @@ func parseTemplates() (*template.Template, *template.Template, error) { return nil, nil, err } if *tmplFile != "" { - f, err := ioutil.ReadFile(*tmplFile) + f, err := os.ReadFile(*tmplFile) if err != nil { return nil, nil, err } @@ -183,7 +182,7 @@ func parsePackageSource(pkg string) (*types.Scope, *doc.Package, error) { files := make(map[string]*ast.File) fileList := make([]*ast.File, len(pd.GoFiles)) for i, fname := range pd.GoFiles { - src, err := ioutil.ReadFile(path.Join(pd.Dir, fname)) + src, err := os.ReadFile(path.Join(pd.Dir, fname)) if err != nil { return nil, nil, err } diff --git a/suite/suite_test.go b/suite/suite_test.go index b97eb43..eceecb6 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -4,7 +4,7 @@ import ( "bytes" "errors" "flag" - "io/ioutil" + "io" "math/rand" "os" "os/exec" @@ -440,7 +440,7 @@ func (sc *StdoutCapture) StopCapture() (string, error) { } os.Stdout.Close() os.Stdout = sc.oldStdout - bytes, err := ioutil.ReadAll(sc.readPipe) + bytes, err := io.ReadAll(sc.readPipe) if err != nil { return "", err } From f8c628e5a14e7cf6bc5d4407e2fdc54b772ee85b Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 16 Dec 2024 23:14:16 +0200 Subject: [PATCH 48/52] docs: Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2dbd16..d4857d3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Get started: * Install testify with [one line of code](#installation), or [update it with another](#staying-up-to-date) * For an introduction to writing test code in Go, see https://go.dev/doc/code#Testing * Check out the API Documentation https://pkg.go.dev/github.com/stretchr/testify - * Use [testifylint](https://github.com/Antonboom/testifylint) (via [golanci-lint](https://golangci-lint.run/)) to avoid common mistakes + * Use [testifylint](https://github.com/Antonboom/testifylint) (via [golangci-lint](https://golangci-lint.run/)) to avoid common mistakes * A little about [Test-Driven Development (TDD)](https://en.wikipedia.org/wiki/Test-driven_development) [`assert`](https://pkg.go.dev/github.com/stretchr/testify/assert "API documentation") package From ca6698b8a1c4617c5ca4333ce0c878e91c506702 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Tue, 31 Dec 2024 15:09:40 -0700 Subject: [PATCH 49/52] assert.ErrorAs: log target type --- assert/assertions.go | 49 ++++++++++++++++------ assert/assertions_test.go | 87 ++++++++++++++++++++++++++++----------- 2 files changed, 99 insertions(+), 37 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 4e91332..466554e 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2102,7 +2102,7 @@ func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { expectedText = target.Error() } - chain := buildErrorChainString(err) + chain := buildErrorChainString(err, false) return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+ "expected: %q\n"+ @@ -2125,7 +2125,7 @@ func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { expectedText = target.Error() } - chain := buildErrorChainString(err) + chain := buildErrorChainString(err, false) return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ "found: %q\n"+ @@ -2143,10 +2143,10 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ return true } - chain := buildErrorChainString(err) + chain := buildErrorChainString(err, true) return Fail(t, fmt.Sprintf("Should be in error chain:\n"+ - "expected: %q\n"+ + "expected: %T\n"+ "in chain: %s", target, chain, ), msgAndArgs...) } @@ -2161,24 +2161,49 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa return true } - chain := buildErrorChainString(err) + chain := buildErrorChainString(err, true) return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ - "found: %q\n"+ + "found: %T\n"+ "in chain: %s", target, chain, ), msgAndArgs...) } -func buildErrorChainString(err error) string { +func unwrapAll(err error) (errs []error) { + errs = append(errs, err) + switch x := err.(type) { + case interface{ Unwrap() error }: + err = x.Unwrap() + if err == nil { + return + } + errs = append(errs, unwrapAll(err)...) + case interface{ Unwrap() []error }: + for _, err := range x.Unwrap() { + errs = append(errs, unwrapAll(err)...) + } + return + default: + return + } + return +} + +func buildErrorChainString(err error, withType bool) string { if err == nil { return "" } - e := errors.Unwrap(err) - chain := fmt.Sprintf("%q", err.Error()) - for e != nil { - chain += fmt.Sprintf("\n\t%q", e.Error()) - e = errors.Unwrap(e) + var chain string + errs := unwrapAll(err) + for i := range errs { + if i != 0 { + chain += "\n\t" + } + chain += fmt.Sprintf("%q", errs[i].Error()) + if withType { + chain += fmt.Sprintf(" (%T)", errs[i]) + } } return chain } diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 9f859fa..18911ba 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -3175,11 +3175,13 @@ func parseLabeledOutput(output string) []labeledContent { } type captureTestingT struct { - msg string + failed bool + msg string } func (ctt *captureTestingT) Errorf(format string, args ...interface{}) { ctt.msg = fmt.Sprintf(format, args...) + ctt.failed = true } func (ctt *captureTestingT) checkResultAndErrMsg(t *testing.T, expectedRes, res bool, expectedErrMsg string) { @@ -3188,6 +3190,9 @@ func (ctt *captureTestingT) checkResultAndErrMsg(t *testing.T, expectedRes, res t.Errorf("Should return %t", expectedRes) return } + if res == ctt.failed { + t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !ctt.failed) + } contents := parseLabeledOutput(ctt.msg) if res == true { if contents != nil { @@ -3348,50 +3353,82 @@ func TestNotErrorIs(t *testing.T) { func TestErrorAs(t *testing.T) { tests := []struct { - err error - result bool + err error + result bool + resultErrMsg string }{ - {fmt.Errorf("wrap: %w", &customError{}), true}, - {io.EOF, false}, - {nil, false}, + { + err: fmt.Errorf("wrap: %w", &customError{}), + result: true, + }, + { + err: io.EOF, + result: false, + resultErrMsg: "" + + "Should be in error chain:\n" + + "expected: **assert.customError\n" + + "in chain: \"EOF\" (*errors.errorString)\n", + }, + { + err: nil, + result: false, + resultErrMsg: "" + + "Should be in error chain:\n" + + "expected: **assert.customError\n" + + "in chain: \n", + }, + { + err: fmt.Errorf("abc: %w", errors.New("def")), + result: false, + resultErrMsg: "" + + "Should be in error chain:\n" + + "expected: **assert.customError\n" + + "in chain: \"abc: def\" (*fmt.wrapError)\n" + + "\t\"def\" (*errors.errorString)\n", + }, } for _, tt := range tests { tt := tt var target *customError t.Run(fmt.Sprintf("ErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) { - mockT := new(testing.T) + mockT := new(captureTestingT) res := ErrorAs(mockT, tt.err, &target) - if res != tt.result { - t.Errorf("ErrorAs(%#v,%#v) should return %t", tt.err, target, tt.result) - } - if res == mockT.Failed() { - t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !mockT.Failed()) - } + mockT.checkResultAndErrMsg(t, tt.result, res, tt.resultErrMsg) }) } } func TestNotErrorAs(t *testing.T) { tests := []struct { - err error - result bool + err error + result bool + resultErrMsg string }{ - {fmt.Errorf("wrap: %w", &customError{}), false}, - {io.EOF, true}, - {nil, true}, + { + err: fmt.Errorf("wrap: %w", &customError{}), + result: false, + resultErrMsg: "" + + "Target error should not be in err chain:\n" + + "found: **assert.customError\n" + + "in chain: \"wrap: fail\" (*fmt.wrapError)\n" + + "\t\"fail\" (*assert.customError)\n", + }, + { + err: io.EOF, + result: true, + }, + { + err: nil, + result: true, + }, } for _, tt := range tests { tt := tt var target *customError t.Run(fmt.Sprintf("NotErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) { - mockT := new(testing.T) + mockT := new(captureTestingT) res := NotErrorAs(mockT, tt.err, &target) - if res != tt.result { - t.Errorf("NotErrorAs(%#v,%#v) should not return %t", tt.err, target, tt.result) - } - if res == mockT.Failed() { - t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !mockT.Failed()) - } + mockT.checkResultAndErrMsg(t, tt.result, res, tt.resultErrMsg) }) } } From ccb5e7f656ccfbd55ab31f98b4a7aa8d5255d30a Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Tue, 31 Dec 2024 15:26:24 -0700 Subject: [PATCH 50/52] Remove redundant returns --- assert/assertions.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 466554e..4efe1de 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2182,9 +2182,6 @@ func unwrapAll(err error) (errs []error) { for _, err := range x.Unwrap() { errs = append(errs, unwrapAll(err)...) } - return - default: - return } return } From 1c717c00c126f37ce24492e0e34ca7921bf01b5d Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Tue, 31 Dec 2024 15:35:31 -0700 Subject: [PATCH 51/52] Add return --- assert/assertions_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 18911ba..bb6af1b 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -3192,6 +3192,7 @@ func (ctt *captureTestingT) checkResultAndErrMsg(t *testing.T, expectedRes, res } if res == ctt.failed { t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !ctt.failed) + return } contents := parseLabeledOutput(ctt.msg) if res == true { From c60c3bd7fb8aa1f50fe1e91c9136060a4cbd9657 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Fri, 3 Jan 2025 14:34:16 -0700 Subject: [PATCH 52/52] dereference target --- assert/assertions.go | 8 ++++---- assert/assertions_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 4efe1de..be82161 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2146,8 +2146,8 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ chain := buildErrorChainString(err, true) return Fail(t, fmt.Sprintf("Should be in error chain:\n"+ - "expected: %T\n"+ - "in chain: %s", target, chain, + "expected: %s\n"+ + "in chain: %s", reflect.ValueOf(target).Elem().Type(), chain, ), msgAndArgs...) } @@ -2164,8 +2164,8 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa chain := buildErrorChainString(err, true) return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ - "found: %T\n"+ - "in chain: %s", target, chain, + "found: %s\n"+ + "in chain: %s", reflect.ValueOf(target).Elem().Type(), chain, ), msgAndArgs...) } diff --git a/assert/assertions_test.go b/assert/assertions_test.go index bb6af1b..503eadb 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -3367,7 +3367,7 @@ func TestErrorAs(t *testing.T) { result: false, resultErrMsg: "" + "Should be in error chain:\n" + - "expected: **assert.customError\n" + + "expected: *assert.customError\n" + "in chain: \"EOF\" (*errors.errorString)\n", }, { @@ -3375,7 +3375,7 @@ func TestErrorAs(t *testing.T) { result: false, resultErrMsg: "" + "Should be in error chain:\n" + - "expected: **assert.customError\n" + + "expected: *assert.customError\n" + "in chain: \n", }, { @@ -3383,7 +3383,7 @@ func TestErrorAs(t *testing.T) { result: false, resultErrMsg: "" + "Should be in error chain:\n" + - "expected: **assert.customError\n" + + "expected: *assert.customError\n" + "in chain: \"abc: def\" (*fmt.wrapError)\n" + "\t\"def\" (*errors.errorString)\n", }, @@ -3410,7 +3410,7 @@ func TestNotErrorAs(t *testing.T) { result: false, resultErrMsg: "" + "Target error should not be in err chain:\n" + - "found: **assert.customError\n" + + "found: *assert.customError\n" + "in chain: \"wrap: fail\" (*fmt.wrapError)\n" + "\t\"fail\" (*assert.customError)\n", },