From 649b123db973a2319de57c733ac377f621574f99 Mon Sep 17 00:00:00 2001 From: Gabriel Burt Date: Fri, 22 Mar 2019 19:21:22 +0000 Subject: [PATCH 01/15] allow mocked.On("X").Return(func(a Arguments) Arguments { return nil }) --- mock/mock.go | 41 +++++++++++++++++++++++++++++++++++++++-- mock/mock_test.go | 15 +++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index c81a0bd4b..282d51216 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -32,6 +32,8 @@ type TestingT interface { Call */ +type returnArgumentsFunc func(args Arguments) Arguments + // Call represents a method call and is used for setting expectations, // as well as recording activity. type Call struct { @@ -44,9 +46,15 @@ type Call struct { Arguments Arguments // Holds the arguments that should be returned when - // this method is called. + // this method is called. If the first and only value is + // function which takes and returns Arguments, that will be invoked + // on each call of the mock to determine what to return. ReturnArguments Arguments + // if the first arg in ReturnArguments is a returnArgumentsFunc, this + // stores that ready for use + returnFunc returnArgumentsFunc + // Holds the caller info for the On() call callerInfo []string @@ -102,15 +110,44 @@ func (c *Call) unlock() { c.Parent.mutex.Unlock() } +// If the only return arg is a function which takes and returns Arguments, invoke it instead of returning it as the value +func (c *Call) getReturnArguments(args Arguments) Arguments { + if c.returnFunc != nil { + return c.returnFunc(args) + } + + return c.ReturnArguments +} + +var argumentsType = reflect.TypeOf(Arguments(nil)) + // Return specifies the return arguments for the expectation. // // Mock.On("DoSomething").Return(errors.New("failed")) +// +// If you pass a single returnArg which is a function that itself takes Arguments and returns Arguments, +// that will be invoked at runtime. +// +// Mock.On("HelloWorld").Return(func(args mock.Arguments) mock.Arguments { return "Hello " + arg[0].(string) }) func (c *Call) Return(returnArguments ...interface{}) *Call { c.lock() defer c.unlock() c.ReturnArguments = returnArguments + if len(c.ReturnArguments) == 1 { + fn := reflect.ValueOf(c.ReturnArguments[0]) + if fn.Kind() == reflect.Func { + fnType := fn.Type() + if fnType.NumIn() == 1 && fnType.NumOut() == 1 && fnType.In(0) == argumentsType && fnType.Out(0) == argumentsType { + c.returnFunc = func(args Arguments) Arguments { + ret := fn.Call([]reflect.Value{reflect.ValueOf(args)}) + return ret[0].Interface().(Arguments) + } + } + } + } + return c } @@ -581,7 +618,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen } m.mutex.Lock() - returnArgs := call.ReturnArguments + returnArgs := call.getReturnArguments(arguments) m.mutex.Unlock() return returnArgs diff --git a/mock/mock_test.go b/mock/mock_test.go index 04664d44b..25cb899bf 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -834,6 +834,21 @@ func Test_Mock_Return_Run_Out_Of_Order(t *testing.T) { assert.NotNil(t, call.Run) } +func Test_Mock_Return_Func(t *testing.T) { + + // make a test impl object + var mockedService = new(TestExampleImplementation) + + mockedService.On("TheExampleMethod", 1, 2, 3). + Return(func(args Arguments) Arguments { + return []interface{}{42, fmt.Errorf("hrm")} + }). + Once() + + answer, _ := mockedService.TheExampleMethod(1, 2, 3) + assert.Equal(t, 42, answer) +} + func Test_Mock_Return_Once(t *testing.T) { // make a test impl object From c4b8210fec5d548e3ab87b2eacfe0dec06f0b5f5 Mon Sep 17 00:00:00 2001 From: Gabriel Burt Date: Wed, 6 Mar 2024 14:43:05 +0000 Subject: [PATCH 02/15] better mock ReturnFunc test --- mock/mock_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mock/mock_test.go b/mock/mock_test.go index 25cb899bf..a28b70359 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -839,14 +839,17 @@ func Test_Mock_Return_Func(t *testing.T) { // make a test impl object var mockedService = new(TestExampleImplementation) - mockedService.On("TheExampleMethod", 1, 2, 3). + mockedService.On("TheExampleMethod", Anything, Anything, Anything). Return(func(args Arguments) Arguments { - return []interface{}{42, fmt.Errorf("hrm")} + return Arguments{args[0].(int) + 40, fmt.Errorf("hrm")} }). - Once() + Twice() - answer, _ := mockedService.TheExampleMethod(1, 2, 3) + answer, _ := mockedService.TheExampleMethod(2, 4, 5) assert.Equal(t, 42, answer) + + answer, _ = mockedService.TheExampleMethod(44, 4, 5) + assert.Equal(t, 84, answer) } func Test_Mock_Return_Once(t *testing.T) { From 2a1ff62d22b43254a5d6316e2a8dd681d5bc5216 Mon Sep 17 00:00:00 2001 From: Gabriel Burt Date: Wed, 6 Mar 2024 14:51:29 +0000 Subject: [PATCH 03/15] simpler implementation per review feedback --- mock/mock.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 282d51216..92f68ad50 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -32,8 +32,6 @@ type TestingT interface { Call */ -type returnArgumentsFunc func(args Arguments) Arguments - // Call represents a method call and is used for setting expectations, // as well as recording activity. type Call struct { @@ -51,9 +49,9 @@ type Call struct { // on each call of the mock to determine what to return. ReturnArguments Arguments - // if the first arg in ReturnArguments is a returnArgumentsFunc, this + // if the first arg in ReturnArguments is a func(args Arguments) Arguments, this // stores that ready for use - returnFunc returnArgumentsFunc + returnFunc func(args Arguments) Arguments // Holds the caller info for the On() call callerInfo []string @@ -133,21 +131,15 @@ func (c *Call) Return(returnArguments ...interface{}) *Call { c.lock() defer c.unlock() - c.ReturnArguments = returnArguments - - if len(c.ReturnArguments) == 1 { - fn := reflect.ValueOf(c.ReturnArguments[0]) - if fn.Kind() == reflect.Func { - fnType := fn.Type() - if fnType.NumIn() == 1 && fnType.NumOut() == 1 && fnType.In(0) == argumentsType && fnType.Out(0) == argumentsType { - c.returnFunc = func(args Arguments) Arguments { - ret := fn.Call([]reflect.Value{reflect.ValueOf(args)}) - return ret[0].Interface().(Arguments) - } - } + if len(returnArguments) == 1 { + if fn, ok := returnArguments[0].(func(Arguments) Arguments); ok { + c.returnFunc = fn + return c } } + c.returnFunc = nil + c.ReturnArguments = returnArguments return c } From 74b30a30f751e12b192a7ab1e302caaf6b35918b Mon Sep 17 00:00:00 2001 From: Gabriel Burt Date: Wed, 6 Mar 2024 14:53:20 +0000 Subject: [PATCH 04/15] remove unused variable --- mock/mock.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 92f68ad50..2bc913551 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -117,8 +117,6 @@ func (c *Call) getReturnArguments(args Arguments) Arguments { return c.ReturnArguments } -var argumentsType = reflect.TypeOf(Arguments(nil)) - // Return specifies the return arguments for the expectation. // // Mock.On("DoSomething").Return(errors.New("failed")) From 9feebd4221362d9da099df35059bb8736ae54296 Mon Sep 17 00:00:00 2001 From: Gabriel Burt Date: Thu, 7 Mar 2024 16:10:02 +0000 Subject: [PATCH 05/15] reimplement via Run() func --- mock/mock.go | 86 ++++++++++++++++++++++++++++++++------------ mock/mock_test.go | 91 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 144 insertions(+), 33 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 2bc913551..be35016e9 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -49,8 +49,8 @@ type Call struct { // on each call of the mock to determine what to return. ReturnArguments Arguments - // if the first arg in ReturnArguments is a func(args Arguments) Arguments, this - // stores that ready for use + // if Run() was given a function which returns arguments, we'll call that whenever + // this call is invoked and use its return values as the arguments to return. returnFunc func(args Arguments) Arguments // Holds the caller info for the On() call @@ -110,6 +110,10 @@ func (c *Call) unlock() { // If the only return arg is a function which takes and returns Arguments, invoke it instead of returning it as the value func (c *Call) getReturnArguments(args Arguments) Arguments { + if c.returnFunc != nil && len(c.ReturnArguments) > 0 { + panic("Cannot specify a function with Run() that returns arguments and also specify a Return() fixed set of return arguments") + } + if c.returnFunc != nil { return c.returnFunc(args) } @@ -117,26 +121,13 @@ func (c *Call) getReturnArguments(args Arguments) Arguments { return c.ReturnArguments } -// Return specifies the return arguments for the expectation. +// Return specifies fixed return arguments for the expectation, that will be returned for every invocation. +// If you want to specify dynamic return values see the Run(fn) function. // // Mock.On("DoSomething").Return(errors.New("failed")) -// -// If you pass a single returnArg which is a function that itself takes Arguments and returns Arguments, -// that will be invoked at runtime. -// -// Mock.On("HelloWorld").Return(func(args mock.Arguments) mock.Arguments { return "Hello " + arg[0].(string) }) func (c *Call) Return(returnArguments ...interface{}) *Call { c.lock() defer c.unlock() - - if len(returnArguments) == 1 { - if fn, ok := returnArguments[0].(func(Arguments) Arguments); ok { - c.returnFunc = fn - return c - } - } - - c.returnFunc = nil c.ReturnArguments = returnArguments return c } @@ -199,18 +190,67 @@ func (c *Call) After(d time.Duration) *Call { return c } -// Run sets a handler to be called before returning. It can be used when -// mocking a method (such as an unmarshaler) that takes a pointer to a struct and -// sets properties in such struct +// Run sets a handler to be called before returning, possibly determining the return values of the call too. +// +// You can pass three types of functions to it: // -// Mock.On("Unmarshal", AnythingOfType("*map[string]interface{}")).Return().Run(func(args Arguments) { +// 1) func(Arguments) that will not affect what is returned (you can still call Return() to specify them) +// +// Mock.On("Unmarshal", mock.AnythingOfType("*map[string]interface{}")).Return().Run(func(args Arguments) { // arg := args.Get(0).(*map[string]interface{}) // arg["foo"] = "bar" // }) -func (c *Call) Run(fn func(args Arguments)) *Call { +// +// 2) A function which matches the signature of your mocked function itself, and determines the return values dynamically. +// +// Mock.On("HelloWorld", mock.Anything).Run(func(name string) string { +// return "Hello " + name +// }) +// +// 3) func(Arguments) Arguments which behaves like (2) except you need to do the typecasting yourself +// +// Mock.On("HelloWorld", mock.Anything).Run(func(args mock.Arguments) args mock.Arguments { +// return mock.Arguments([]any{"Hello " + args[0].(string)}) +// }) +func (c *Call) Run(fn interface{}) *Call { c.lock() defer c.unlock() - c.RunFn = fn + switch f := fn.(type) { + case func(Arguments): + c.RunFn = f + case func(Arguments) Arguments: + c.returnFunc = f + default: + fnVal := reflect.ValueOf(fn) + if fnVal.Kind() != reflect.Func { + panic(fmt.Sprintf("Invalid argument passed to Run(), must be a function, is a %T", fn)) + } + fnType := fnVal.Type() + c.returnFunc = func(args Arguments) (resp Arguments) { + var argVals []reflect.Value + for i, arg := range args { + if i == len(args)-1 && fnType.IsVariadic() { + // splat the variadic arg back out in the call, as expected by reflect.Value#Call + argVal := reflect.ValueOf(arg) + for j := 0; j < argVal.Len(); j++ { + argVals = append(argVals, argVal.Index(j)) + } + } else { + argVals = append(argVals, reflect.ValueOf(arg)) + } + } + + // actually call the fn + ret := fnVal.Call(argVals) + + for _, val := range ret { + resp = append(resp, val.Interface()) + } + + return resp + } + } + return c } diff --git a/mock/mock_test.go b/mock/mock_test.go index a28b70359..c7f723e62 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -834,22 +834,93 @@ func Test_Mock_Return_Run_Out_Of_Order(t *testing.T) { assert.NotNil(t, call.Run) } -func Test_Mock_Return_Func(t *testing.T) { +func Test_Mock_Run_ReturnFunc(t *testing.T) { // make a test impl object var mockedService = new(TestExampleImplementation) - mockedService.On("TheExampleMethod", Anything, Anything, Anything). - Return(func(args Arguments) Arguments { - return Arguments{args[0].(int) + 40, fmt.Errorf("hrm")} - }). - Twice() + t.Run("can dynamically set the return values", func(t *testing.T) { + mockedService.On("TheExampleMethod", Anything, Anything, Anything). + Run(func(a, b, c int) (int, error) { + return a + 40, fmt.Errorf("hmm") + }). + Twice() + + answer, _ := mockedService.TheExampleMethod(2, 4, 5) + assert.Equal(t, 42, answer) + + answer, _ = mockedService.TheExampleMethod(44, 4, 5) + assert.Equal(t, 84, answer) + }) + + t.Run("handles func(Args) Args style", func(t *testing.T) { + mockedService.On("TheExampleMethod", Anything, Anything, Anything). + Run(func(args Arguments) Arguments { + return []interface{}{args[0].(int) + 40, fmt.Errorf("hmm")} + }). + Twice() + + answer, _ := mockedService.TheExampleMethod(2, 4, 5) + assert.Equal(t, 42, answer) + + answer, _ = mockedService.TheExampleMethod(44, 4, 5) + assert.Equal(t, 84, answer) + }) + + t.Run("handles pointer input args", func(t *testing.T) { + mockedService.On("TheExampleMethod3", Anything).Run(func(et *ExampleType) error { + if et == nil { + return fmt.Errorf("Nil obj") + } + return nil + }).Twice() + + err := mockedService.TheExampleMethod3(nil) + assert.Error(t, err) + + err = mockedService.TheExampleMethod3(&ExampleType{}) + assert.NoError(t, err) + }) + + t.Run("handles no return args", func(t *testing.T) { + mockedService.On("TheExampleMethod2", Anything).Run(func(yesno bool) { + // nothing to return + }).Once() - answer, _ := mockedService.TheExampleMethod(2, 4, 5) - assert.Equal(t, 42, answer) + mockedService.TheExampleMethod2(true) + }) - answer, _ = mockedService.TheExampleMethod(44, 4, 5) - assert.Equal(t, 84, answer) + t.Run("handles variadic input args", func(t *testing.T) { + mockedService. + On("TheExampleMethodMixedVariadic", Anything, Anything). + Run(func(a int, b ...int) error { + var sum = a + for _, v := range b { + sum += v + } + return fmt.Errorf("%v", sum) + }) + + assert.Equal(t, "42", mockedService.TheExampleMethodMixedVariadic(40, 1, 1).Error()) + assert.Equal(t, "40", mockedService.TheExampleMethodMixedVariadic(40).Error()) + }) + + t.Run("panics if Run() called with an invalid value", func(t *testing.T) { + assert.PanicsWithValue(t, + "Invalid argument passed to Run(), must be a function, is a int", + func() { mockedService.On("TheExampleMethod").Run(42) }, + ) + }) + + t.Run("panics if both Return() and Run() are called specifying return args", func(t *testing.T) { + mockedService.On("TheExampleMethod", Anything, Anything, Anything). + Run(func(a, b, c int) (int, error) { + return a + 40, fmt.Errorf("hmm") + }). + Return(80, nil) + + assert.PanicsWithValue(t, "Cannot specify a function with Run() that returns arguments and also specify a Return() fixed set of return arguments", func() { mockedService.TheExampleMethod(1, 2, 3) }) + }) } func Test_Mock_Return_Once(t *testing.T) { From 1f763ab901062a44f04574f13a849a8c569c1c29 Mon Sep 17 00:00:00 2001 From: Gabriel Burt Date: Thu, 7 Mar 2024 16:11:30 +0000 Subject: [PATCH 06/15] fix typo in comment --- mock/mock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index be35016e9..f6f887126 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -209,7 +209,7 @@ func (c *Call) After(d time.Duration) *Call { // // 3) func(Arguments) Arguments which behaves like (2) except you need to do the typecasting yourself // -// Mock.On("HelloWorld", mock.Anything).Run(func(args mock.Arguments) args mock.Arguments { +// Mock.On("HelloWorld", mock.Anything).Run(func(args mock.Arguments) mock.Arguments { // return mock.Arguments([]any{"Hello " + args[0].(string)}) // }) func (c *Call) Run(fn interface{}) *Call { From 53d1b3ca95cf1b7f89c749a1c6216d94ec54d151 Mon Sep 17 00:00:00 2001 From: Snir Yehuda Date: Sun, 23 Jul 2023 19:10:39 +0300 Subject: [PATCH 07/15] assert.FunctionalOptions: fix go doc --- mock/mock.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index f6f887126..d5c221b93 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -44,13 +44,10 @@ type Call struct { Arguments Arguments // Holds the arguments that should be returned when - // this method is called. If the first and only value is - // function which takes and returns Arguments, that will be invoked - // on each call of the mock to determine what to return. + // this method is called. ReturnArguments Arguments - // if Run() was given a function which returns arguments, we'll call that whenever - // this call is invoked and use its return values as the arguments to return. + //TODO add docstring and make public returnFunc func(args Arguments) Arguments // Holds the caller info for the On() call @@ -925,8 +922,8 @@ func (f *FunctionalOptionsArgument) String() string { // // For example: // -// args.Assert(t, FunctionalOptions(foo.Opt1("strValue"), foo.Opt2(613))) -func FunctionalOptions(values ...interface{}) *FunctionalOptionsArgument { +// Assert(t, FunctionalOptions(foo.Opt1("strValue"), foo.Opt2(613))) +func FunctionalOptions(value ...interface{}) *FunctionalOptionsArgument { return &FunctionalOptionsArgument{ values: values, } From 131391681cc9f0194a492ae1c48b018a4505a284 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 08/15] mock: document more alternatives to deprecated AnythingOfTypeArgument --- mock/mock.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index d5c221b93..9cdc02074 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -856,15 +856,25 @@ const ( // AnythingOfTypeArgument contains the type of an argument // for use when type checking. Used in [Arguments.Diff] and [Arguments.Assert]. // -// Deprecated: this is an implementation detail that must not be used. Use the [AnythingOfType] constructor instead, example: +// Deprecated: this is an implementation detail that must not be used. Use the [AnythingOfType] constructor instead. // -// m.On("Do", mock.AnythingOfType("string")) +// If AnythingOfTypeArgument is used as a function return value type you can usually replace +// the function with a variable. Example: // -// All explicit type declarations can be replaced with interface{} as is expected by [Mock.On], example: +// func anyString() mock.AnythingOfTypeArgument { +// return mock.AnythingOfType("string") +// } +// +// Can be replaced by: // -// func anyString interface{} { -// return mock.AnythingOfType("string") +// 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 ff43deff7375e335c9afcb1fbd0e5226b276d7c6 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 09/15] mock: simpler deprecation doc for AnythingOfTypeArgument Co-authored-by: Bracken --- mock/mock.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 9cdc02074..d5c221b93 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -856,25 +856,15 @@ const ( // AnythingOfTypeArgument contains the type of an argument // for use when type checking. Used in [Arguments.Diff] and [Arguments.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") -// } -// -// Can be replaced by: +// All explicit type declarations can be replaced with interface{} as is expected by [Mock.On], example: // -// func anyString() interface{} { -// return mock.IsType("") +// func anyString interface{} { +// return mock.AnythingOfType("string") // } -// -// 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 4f3bd10b494284af96090e337c729e14fd55c59a Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Thu, 13 Jun 2024 06:52:14 +0200 Subject: [PATCH 10/15] 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. --- require/require.go | 236 ++++++++++++++++++++++++++++++++++++++++ require/require.go.tmpl | 1 + 2 files changed, 237 insertions(+) diff --git a/require/require.go b/require/require.go index d8921950d..a98f991a6 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() @@ -37,6 +39,8 @@ 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") +// +// 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() @@ -53,6 +57,8 @@ 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") +// +// 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() @@ -92,6 +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. func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -107,6 +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. func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -121,6 +131,8 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string // a slice or a channel with len == 0. // // 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() @@ -135,6 +147,8 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // a slice or a channel with len == 0. // // 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() @@ -152,6 +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. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -167,6 +182,8 @@ 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. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -182,6 +199,8 @@ 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. func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -202,6 +221,8 @@ 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. func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -222,6 +243,8 @@ 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. func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -236,6 +259,8 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, // type and equal. // // 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() @@ -250,6 +275,8 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg // type and equal. // // 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() @@ -267,6 +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. func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -283,6 +311,8 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar // 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() @@ -322,6 +354,8 @@ 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. func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -337,6 +371,8 @@ 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. 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() @@ -377,6 +415,8 @@ 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) // } +// +// 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() @@ -391,6 +431,8 @@ 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) +// +// 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() @@ -419,6 +461,8 @@ 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") +// +// 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() @@ -447,6 +491,8 @@ 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") +// +// 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() @@ -461,6 +507,8 @@ 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") +// +// 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() @@ -474,6 +522,8 @@ 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)) +// +// 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() @@ -487,6 +537,8 @@ 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") +// +// 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() @@ -544,6 +600,8 @@ func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { // False asserts that the specified value is false. // // 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() @@ -557,6 +615,8 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) { // Falsef asserts that the specified value is false. // // 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() @@ -596,6 +658,8 @@ 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") +// +// 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() @@ -612,6 +676,8 @@ 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") +// +// 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() @@ -628,6 +694,8 @@ 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") +// +// 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() @@ -643,6 +711,8 @@ 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") +// +// 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() @@ -659,6 +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. 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() @@ -675,6 +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. 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() @@ -691,6 +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. 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() @@ -707,6 +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. 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() @@ -722,6 +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. func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -737,6 +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. 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() @@ -752,6 +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. func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -767,6 +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. 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() @@ -782,6 +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. 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() @@ -797,6 +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. 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() @@ -812,6 +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. func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -827,6 +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. 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() @@ -840,6 +922,8 @@ 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)) +// +// 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() @@ -853,6 +937,8 @@ 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") +// +// 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() @@ -866,6 +952,8 @@ 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) +// +// 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() @@ -923,6 +1015,8 @@ 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") +// +// 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() @@ -982,6 +1080,8 @@ 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"}) +// +// 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() @@ -997,6 +1097,8 @@ 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") +// +// 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() @@ -1012,6 +1114,8 @@ 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"}) +// +// 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() @@ -1027,6 +1131,8 @@ 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") +// +// 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() @@ -1042,6 +1148,8 @@ 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"}) +// +// 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() @@ -1057,6 +1165,8 @@ 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") +// +// 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() @@ -1072,6 +1182,8 @@ 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"}) +// +// 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() @@ -1087,6 +1199,8 @@ 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") +// +// 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() @@ -1122,6 +1238,8 @@ 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"}`) +// +// 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() @@ -1135,6 +1253,8 @@ 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") +// +// 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() @@ -1149,6 +1269,8 @@ 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) +// +// 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() @@ -1163,6 +1285,8 @@ 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") +// +// 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() @@ -1178,6 +1302,8 @@ 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") +// +// 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() @@ -1194,6 +1320,8 @@ 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") +// +// 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() @@ -1210,6 +1338,8 @@ 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") +// +// 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() @@ -1225,6 +1355,8 @@ 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") +// +// 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() @@ -1239,6 +1371,8 @@ 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. func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1253,6 +1387,8 @@ 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. func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1267,6 +1403,8 @@ 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) +// +// 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() @@ -1281,6 +1419,8 @@ 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") +// +// 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() @@ -1294,6 +1434,8 @@ func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time. // Nil asserts that the specified object is nil. // // 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() @@ -1307,6 +1449,8 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { // Nilf asserts that the specified object is nil. // // 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() @@ -1347,6 +1493,8 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { // 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() @@ -1363,6 +1511,8 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) { // 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() @@ -1403,6 +1555,8 @@ 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") +// +// 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() @@ -1419,6 +1573,8 @@ 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") +// +// 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() @@ -1439,6 +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. func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1459,6 +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. func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1475,6 +1633,8 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str // 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() @@ -1491,6 +1651,8 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // 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() @@ -1507,6 +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. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1520,6 +1683,8 @@ 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) +// +// 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() @@ -1533,6 +1698,8 @@ 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") +// +// 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() @@ -1549,6 +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. func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1585,6 +1753,7 @@ func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ... // 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. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1597,6 +1766,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. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1610,6 +1780,8 @@ 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)) +// +// 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() @@ -1623,6 +1795,8 @@ 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") +// +// 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() @@ -1636,6 +1810,8 @@ func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, // NotNil asserts that the specified object is not nil. // // 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() @@ -1649,6 +1825,8 @@ 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") +// +// 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() @@ -1662,6 +1840,8 @@ 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() }) +// +// 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() @@ -1675,6 +1855,8 @@ 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") +// +// 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() @@ -1689,6 +1871,8 @@ 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. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1703,6 +1887,8 @@ 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. func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1719,6 +1905,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. func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1735,6 +1922,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. func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1751,6 +1939,8 @@ 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. func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1767,6 +1957,8 @@ 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. func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1778,6 +1970,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() @@ -1789,6 +1982,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() @@ -1802,6 +1996,8 @@ 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() }) +// +// 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() @@ -1817,6 +2013,8 @@ func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // EqualError comparison. // // 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() @@ -1832,6 +2030,8 @@ func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAn // EqualError comparison. // // 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() @@ -1846,6 +2046,8 @@ 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() }) +// +// 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() @@ -1860,6 +2062,8 @@ 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") +// +// 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() @@ -1873,6 +2077,8 @@ 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") +// +// 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() @@ -1887,6 +2093,8 @@ 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. func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1901,6 +2109,8 @@ 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. func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1915,6 +2125,8 @@ 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. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1929,6 +2141,8 @@ 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. func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1945,6 +2159,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. func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1961,6 +2176,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. func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1976,6 +2192,8 @@ 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. func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1991,6 +2209,8 @@ 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. func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2004,6 +2224,8 @@ func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args // True asserts that the specified value is true. // // 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() @@ -2017,6 +2239,8 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) { // Truef asserts that the specified value is true. // // 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() @@ -2030,6 +2254,8 @@ 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) +// +// 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() @@ -2043,6 +2269,8 @@ 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") +// +// 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() @@ -2056,6 +2284,8 @@ 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)) +// +// 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() @@ -2069,6 +2299,8 @@ 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") +// +// 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() @@ -2080,6 +2312,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() @@ -2091,6 +2324,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() @@ -2102,6 +2336,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() @@ -2113,6 +2348,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 8b3283685..ded85afa4 100644 --- a/require/require.go.tmpl +++ b/require/require.go.tmpl @@ -1,4 +1,5 @@ {{ 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 64dc131cbcc3b8f9b385566ff0eb62d05d87adf9 Mon Sep 17 00:00:00 2001 From: Justin Lewis Date: Sat, 5 Apr 2025 16:02:50 -0400 Subject: [PATCH 11/15] start implementing as RunWithReturn --- mock/mock.go | 88 ++------------- mock/mock_test.go | 89 --------------- require/require.go | 236 ---------------------------------------- require/require.go.tmpl | 1 - 4 files changed, 12 insertions(+), 402 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index d5c221b93..c81a0bd4b 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -47,9 +47,6 @@ type Call struct { // this method is called. ReturnArguments Arguments - //TODO add docstring and make public - returnFunc func(args Arguments) Arguments - // Holds the caller info for the On() call callerInfo []string @@ -105,27 +102,15 @@ func (c *Call) unlock() { c.Parent.mutex.Unlock() } -// If the only return arg is a function which takes and returns Arguments, invoke it instead of returning it as the value -func (c *Call) getReturnArguments(args Arguments) Arguments { - if c.returnFunc != nil && len(c.ReturnArguments) > 0 { - panic("Cannot specify a function with Run() that returns arguments and also specify a Return() fixed set of return arguments") - } - - if c.returnFunc != nil { - return c.returnFunc(args) - } - - return c.ReturnArguments -} - -// Return specifies fixed return arguments for the expectation, that will be returned for every invocation. -// If you want to specify dynamic return values see the Run(fn) function. +// Return specifies the return arguments for the expectation. // // Mock.On("DoSomething").Return(errors.New("failed")) func (c *Call) Return(returnArguments ...interface{}) *Call { c.lock() defer c.unlock() + c.ReturnArguments = returnArguments + return c } @@ -187,67 +172,18 @@ func (c *Call) After(d time.Duration) *Call { return c } -// Run sets a handler to be called before returning, possibly determining the return values of the call too. -// -// You can pass three types of functions to it: +// Run sets a handler to be called before returning. It can be used when +// mocking a method (such as an unmarshaler) that takes a pointer to a struct and +// sets properties in such struct // -// 1) func(Arguments) that will not affect what is returned (you can still call Return() to specify them) -// -// Mock.On("Unmarshal", mock.AnythingOfType("*map[string]interface{}")).Return().Run(func(args Arguments) { +// Mock.On("Unmarshal", AnythingOfType("*map[string]interface{}")).Return().Run(func(args Arguments) { // arg := args.Get(0).(*map[string]interface{}) // arg["foo"] = "bar" // }) -// -// 2) A function which matches the signature of your mocked function itself, and determines the return values dynamically. -// -// Mock.On("HelloWorld", mock.Anything).Run(func(name string) string { -// return "Hello " + name -// }) -// -// 3) func(Arguments) Arguments which behaves like (2) except you need to do the typecasting yourself -// -// Mock.On("HelloWorld", mock.Anything).Run(func(args mock.Arguments) mock.Arguments { -// return mock.Arguments([]any{"Hello " + args[0].(string)}) -// }) -func (c *Call) Run(fn interface{}) *Call { +func (c *Call) Run(fn func(args Arguments)) *Call { c.lock() defer c.unlock() - switch f := fn.(type) { - case func(Arguments): - c.RunFn = f - case func(Arguments) Arguments: - c.returnFunc = f - default: - fnVal := reflect.ValueOf(fn) - if fnVal.Kind() != reflect.Func { - panic(fmt.Sprintf("Invalid argument passed to Run(), must be a function, is a %T", fn)) - } - fnType := fnVal.Type() - c.returnFunc = func(args Arguments) (resp Arguments) { - var argVals []reflect.Value - for i, arg := range args { - if i == len(args)-1 && fnType.IsVariadic() { - // splat the variadic arg back out in the call, as expected by reflect.Value#Call - argVal := reflect.ValueOf(arg) - for j := 0; j < argVal.Len(); j++ { - argVals = append(argVals, argVal.Index(j)) - } - } else { - argVals = append(argVals, reflect.ValueOf(arg)) - } - } - - // actually call the fn - ret := fnVal.Call(argVals) - - for _, val := range ret { - resp = append(resp, val.Interface()) - } - - return resp - } - } - + c.RunFn = fn return c } @@ -645,7 +581,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen } m.mutex.Lock() - returnArgs := call.getReturnArguments(arguments) + returnArgs := call.ReturnArguments m.mutex.Unlock() return returnArgs @@ -922,8 +858,8 @@ 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{ values: values, } diff --git a/mock/mock_test.go b/mock/mock_test.go index c7f723e62..04664d44b 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -834,95 +834,6 @@ func Test_Mock_Return_Run_Out_Of_Order(t *testing.T) { assert.NotNil(t, call.Run) } -func Test_Mock_Run_ReturnFunc(t *testing.T) { - - // make a test impl object - var mockedService = new(TestExampleImplementation) - - t.Run("can dynamically set the return values", func(t *testing.T) { - mockedService.On("TheExampleMethod", Anything, Anything, Anything). - Run(func(a, b, c int) (int, error) { - return a + 40, fmt.Errorf("hmm") - }). - Twice() - - answer, _ := mockedService.TheExampleMethod(2, 4, 5) - assert.Equal(t, 42, answer) - - answer, _ = mockedService.TheExampleMethod(44, 4, 5) - assert.Equal(t, 84, answer) - }) - - t.Run("handles func(Args) Args style", func(t *testing.T) { - mockedService.On("TheExampleMethod", Anything, Anything, Anything). - Run(func(args Arguments) Arguments { - return []interface{}{args[0].(int) + 40, fmt.Errorf("hmm")} - }). - Twice() - - answer, _ := mockedService.TheExampleMethod(2, 4, 5) - assert.Equal(t, 42, answer) - - answer, _ = mockedService.TheExampleMethod(44, 4, 5) - assert.Equal(t, 84, answer) - }) - - t.Run("handles pointer input args", func(t *testing.T) { - mockedService.On("TheExampleMethod3", Anything).Run(func(et *ExampleType) error { - if et == nil { - return fmt.Errorf("Nil obj") - } - return nil - }).Twice() - - err := mockedService.TheExampleMethod3(nil) - assert.Error(t, err) - - err = mockedService.TheExampleMethod3(&ExampleType{}) - assert.NoError(t, err) - }) - - t.Run("handles no return args", func(t *testing.T) { - mockedService.On("TheExampleMethod2", Anything).Run(func(yesno bool) { - // nothing to return - }).Once() - - mockedService.TheExampleMethod2(true) - }) - - t.Run("handles variadic input args", func(t *testing.T) { - mockedService. - On("TheExampleMethodMixedVariadic", Anything, Anything). - Run(func(a int, b ...int) error { - var sum = a - for _, v := range b { - sum += v - } - return fmt.Errorf("%v", sum) - }) - - assert.Equal(t, "42", mockedService.TheExampleMethodMixedVariadic(40, 1, 1).Error()) - assert.Equal(t, "40", mockedService.TheExampleMethodMixedVariadic(40).Error()) - }) - - t.Run("panics if Run() called with an invalid value", func(t *testing.T) { - assert.PanicsWithValue(t, - "Invalid argument passed to Run(), must be a function, is a int", - func() { mockedService.On("TheExampleMethod").Run(42) }, - ) - }) - - t.Run("panics if both Return() and Run() are called specifying return args", func(t *testing.T) { - mockedService.On("TheExampleMethod", Anything, Anything, Anything). - Run(func(a, b, c int) (int, error) { - return a + 40, fmt.Errorf("hmm") - }). - Return(80, nil) - - assert.PanicsWithValue(t, "Cannot specify a function with Run() that returns arguments and also specify a Return() fixed set of return arguments", func() { mockedService.TheExampleMethod(1, 2, 3) }) - }) -} - func Test_Mock_Return_Once(t *testing.T) { // make a test impl object diff --git a/require/require.go b/require/require.go index a98f991a6..d8921950d 100644 --- a/require/require.go +++ b/require/require.go @@ -10,7 +10,6 @@ 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() @@ -22,7 +21,6 @@ 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -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]) -// 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() @@ -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") -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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. -// 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() @@ -182,8 +167,6 @@ 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. 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") -// -// 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() @@ -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 -// -// 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() @@ -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 -// -// 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() @@ -259,8 +236,6 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, // type and equal. // // 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() @@ -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") -// -// 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() @@ -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. -// 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() @@ -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) // } -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -354,8 +322,6 @@ 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. 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") -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -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) // } -// -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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)) -// -// 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() @@ -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") -// -// 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() @@ -550,7 +498,6 @@ 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() @@ -562,7 +509,6 @@ 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() @@ -574,7 +520,6 @@ 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() @@ -586,7 +531,6 @@ 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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). -// 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() @@ -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)) -// -// 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() @@ -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") -// -// 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() @@ -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) -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -989,7 +899,6 @@ 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() @@ -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. -// 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() @@ -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") -// -// 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() @@ -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 -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -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 -// 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() @@ -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"}) -// -// 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() @@ -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") -// -// 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() @@ -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"}) -// -// 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() @@ -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") -// -// 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() @@ -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"}) -// -// 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() @@ -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") -// -// 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() @@ -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"}) -// -// 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() @@ -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") -// -// 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() @@ -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. -// 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() @@ -1224,7 +1109,6 @@ 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() @@ -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"}`) -// -// 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() @@ -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") -// -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -1493,8 +1347,6 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { // 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() @@ -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) // } -// -// 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() @@ -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. -// 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() @@ -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. -// 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() @@ -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") -// -// 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() @@ -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") -// -// 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() @@ -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 -// 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() @@ -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 -// 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() @@ -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]) // } -// -// 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() @@ -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]) // } -// -// 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() @@ -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). -// 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() @@ -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) -// -// 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() @@ -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") -// -// 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() @@ -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). -// 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() @@ -1753,7 +1585,6 @@ func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ... // 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. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1766,7 +1597,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. -// 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() @@ -1780,8 +1610,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)) -// -// 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() @@ -1795,8 +1623,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") -// -// 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() @@ -1810,8 +1636,6 @@ func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, // NotNil asserts that the specified object is not nil. // // 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() @@ -1825,8 +1649,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") -// -// 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() @@ -1840,8 +1662,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() }) -// -// 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() @@ -1855,8 +1675,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") -// -// 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() @@ -1871,8 +1689,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") -// -// 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() @@ -1887,8 +1703,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") -// -// 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() @@ -1905,7 +1719,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. -// 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() @@ -1922,7 +1735,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. -// 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() @@ -1939,8 +1751,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}) -// -// 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() @@ -1957,8 +1767,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") -// -// 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() @@ -1970,7 +1778,6 @@ 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() @@ -1982,7 +1789,6 @@ 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() @@ -1996,8 +1802,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() }) -// -// 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() @@ -2013,8 +1817,6 @@ func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { // EqualError comparison. // // 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() @@ -2030,8 +1832,6 @@ func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAn // EqualError comparison. // // 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() @@ -2046,8 +1846,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() }) -// -// 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() @@ -2062,8 +1860,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") -// -// 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() @@ -2077,8 +1873,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") -// -// 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() @@ -2093,8 +1887,6 @@ 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. func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2109,8 +1901,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") -// -// 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() @@ -2125,8 +1915,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") -// -// 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() @@ -2141,8 +1929,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") -// -// 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() @@ -2159,7 +1945,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. -// 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() @@ -2176,7 +1961,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. -// 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() @@ -2192,8 +1976,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}) -// -// 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() @@ -2209,8 +1991,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") -// -// 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() @@ -2224,8 +2004,6 @@ func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args // True asserts that the specified value is true. // // 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() @@ -2239,8 +2017,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") -// -// 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() @@ -2254,8 +2030,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) -// -// 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() @@ -2269,8 +2043,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") -// -// 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() @@ -2284,8 +2056,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)) -// -// 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() @@ -2299,8 +2069,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") -// -// 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() @@ -2312,7 +2080,6 @@ 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() @@ -2324,7 +2091,6 @@ 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() @@ -2336,7 +2102,6 @@ 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() @@ -2348,7 +2113,6 @@ 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 ded85afa4..8b3283685 100644 --- a/require/require.go.tmpl +++ b/require/require.go.tmpl @@ -1,5 +1,4 @@ {{ 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 30726933d3b560591b16fa33fd95149975b106d8 Mon Sep 17 00:00:00 2001 From: Justin Lewis Date: Sat, 5 Apr 2025 16:59:00 -0400 Subject: [PATCH 12/15] update tests and all for RunWithReturn --- mock/mock.go | 21 +++++++++++ mock/mock_test.go | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/mock/mock.go b/mock/mock.go index c81a0bd4b..987bf0d96 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -71,6 +71,10 @@ type Call struct { // decoders. RunFn func(Arguments) + // RunFnWithReturn adds return arguments to RunFn. implemented separately + // to avoid breaking the API + RunFnWithReturn func(Arguments) Arguments + // PanicMsg holds msg to be used to mock panic on the function call // if the PanicMsg is set to a non nil string the function call will panic // irrespective of other settings @@ -187,6 +191,15 @@ func (c *Call) Run(fn func(args Arguments)) *Call { return c } +// RunWithReturn similar to Run above, but allows to return arguments +// from the function. Implemented separately to avoid breaking the API. +func (c *Call) RunWithReturn(fn func(args Arguments) Arguments) *Call { + c.lock() + defer c.unlock() + c.RunFnWithReturn = fn + return c +} + // Maybe allows the method call to be optional. Not calling an optional method // will not cause an error while asserting expectations func (c *Call) Maybe() *Call { @@ -584,6 +597,14 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen returnArgs := call.ReturnArguments m.mutex.Unlock() + m.mutex.Lock() + runFnWithReturn := call.RunFnWithReturn + m.mutex.Unlock() + + if runFnWithReturn != nil { + returnArgs = runFnWithReturn(arguments) + } + return returnArgs } diff --git a/mock/mock_test.go b/mock/mock_test.go index 04664d44b..afb7ca84b 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -834,6 +834,95 @@ func Test_Mock_Return_Run_Out_Of_Order(t *testing.T) { assert.NotNil(t, call.Run) } +func Test_Mock_RunWithReturn(t *testing.T) { + + // make a test impl object + var mockedService = new(TestExampleImplementation) + + t.Run("can dynamically set the return values", func(t *testing.T) { + counter := 0 + mockedService.On("TheExampleMethod", Anything, Anything, Anything). + RunWithReturn(func(args Arguments) Arguments { + counter++ + a, b, c := args[0].(int), args[1].(int), args[2].(int) + assert.IsType(t, 1, a) + assert.IsType(t, 1, b) + assert.IsType(t, 1, c) + return Arguments{counter} + }). + Twice() + + answer, _ := mockedService.TheExampleMethod(2, 4, 5) + assert.Equal(t, 1, answer) + + answer, _ = mockedService.TheExampleMethod(44, 4, 5) + assert.Equal(t, 2, answer) + }) + + t.Run("handles func(Args) Args style", func(t *testing.T) { + mockedService.On("TheExampleMethod", Anything, Anything, Anything). + RunWithReturn(func(args Arguments) Arguments { + return []interface{}{args[0].(int) + 40, fmt.Errorf("hmm")} + }). + Twice() + + answer, _ := mockedService.TheExampleMethod(2, 4, 5) + assert.Equal(t, 42, answer) + + answer, _ = mockedService.TheExampleMethod(44, 4, 5) + assert.Equal(t, 84, answer) + }) + + t.Run("handles pointer input args", func(t *testing.T) { + mockedService.On("TheExampleMethod3", Anything).RunWithReturn(func(arguments Arguments) Arguments { + et := arguments[0].(*ExampleType) + if et == nil { + return Arguments{errors.New("error")} + } + return Arguments{nil} + }).Twice() + + err := mockedService.TheExampleMethod3(nil) + assert.Error(t, err) + + err = mockedService.TheExampleMethod3(&ExampleType{}) + assert.NoError(t, err) + }) + + t.Run("handles variadic input args", func(t *testing.T) { + mockedService. + On("TheExampleMethodMixedVariadic", Anything, Anything). + RunWithReturn(func(args Arguments) Arguments { + a, b := args[0].(int), args[1].([]int) + var sum = a + for _, v := range b { + sum += v + } + return Arguments{fmt.Errorf("%v", sum)} + }) + + assert.Equal(t, "42", mockedService.TheExampleMethodMixedVariadic(40, 1, 1).Error()) + assert.Equal(t, "40", mockedService.TheExampleMethodMixedVariadic(40).Error()) + }) + + t.Run("allows all of Run and RunWithReturn and Return to be used", func(t *testing.T) { + mockedService.On("TheExampleMethod", Anything, Anything, Anything). + Run(func(args Arguments) { + a := args[0].(int) + assert.IsType(t, 1, a) + }). + RunWithReturn(func(args Arguments) Arguments { + a := args[0].(int) + return Arguments{a + 40, fmt.Errorf("hmm")} + }). + Return(80, nil) + + answer, err := mockedService.TheExampleMethod(2, 4, 5) + assert.Equal(t, 42, answer) + assert.Error(t, err) + }) +} + func Test_Mock_Return_Once(t *testing.T) { // make a test impl object From 9edc440725c275e955100f74c02bd024b4e1d8b7 Mon Sep 17 00:00:00 2001 From: Justin Lewis Date: Fri, 16 May 2025 10:51:25 -0400 Subject: [PATCH 13/15] pr feedback - make sure to handle order of execution correctly --- mock/mock.go | 24 ++++++++------ mock/mock_test.go | 81 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index ce267070f..52b977d33 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -71,9 +71,8 @@ type Call struct { // decoders. RunFn func(Arguments) - // RunFnWithReturn adds return arguments to RunFn. implemented separately - // to avoid breaking the API - RunFnWithReturn func(Arguments) Arguments + // Holds a handler to a function that will be called before returning. + returnFn func(Arguments) Arguments // PanicMsg holds msg to be used to mock panic on the function call // if the PanicMsg is set to a non nil string the function call will panic @@ -114,6 +113,7 @@ func (c *Call) Return(returnArguments ...interface{}) *Call { defer c.unlock() c.ReturnArguments = returnArguments + c.returnFn = nil return c } @@ -191,12 +191,16 @@ func (c *Call) Run(fn func(args Arguments)) *Call { return c } -// RunWithReturn similar to Run above, but allows to return arguments -// from the function. Implemented separately to avoid breaking the API. -func (c *Call) RunWithReturn(fn func(args Arguments) Arguments) *Call { +// ReturnFn sets a handler to be called before returning. +// +// Mock.On("MyMethod", arg1, arg2).ReturnFn(func(args Arguments) Arguments { +// return Arguments{args.Get(0) + args.Get(1)} +// }) +func (c *Call) ReturnFn(fn func(args Arguments) Arguments) *Call { c.lock() defer c.unlock() - c.RunFnWithReturn = fn + c.returnFn = fn + c.ReturnArguments = nil return c } @@ -598,11 +602,11 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen m.mutex.Unlock() m.mutex.Lock() - runFnWithReturn := call.RunFnWithReturn + returnFn := call.returnFn m.mutex.Unlock() - if runFnWithReturn != nil { - returnArgs = runFnWithReturn(arguments) + if returnFn != nil { + returnArgs = returnFn(arguments) } return returnArgs diff --git a/mock/mock_test.go b/mock/mock_test.go index afb7ca84b..d20500390 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -29,7 +29,7 @@ type TestExampleImplementation struct { func (i *TestExampleImplementation) TheExampleMethod(a, b, c int) (int, error) { args := i.Called(a, b, c) - return args.Int(0), errors.New("Whoops") + return args.Int(0), args.Error(1) } type options struct { @@ -834,7 +834,7 @@ func Test_Mock_Return_Run_Out_Of_Order(t *testing.T) { assert.NotNil(t, call.Run) } -func Test_Mock_RunWithReturn(t *testing.T) { +func Test_Mock_ReturnFn(t *testing.T) { // make a test impl object var mockedService = new(TestExampleImplementation) @@ -842,39 +842,43 @@ func Test_Mock_RunWithReturn(t *testing.T) { t.Run("can dynamically set the return values", func(t *testing.T) { counter := 0 mockedService.On("TheExampleMethod", Anything, Anything, Anything). - RunWithReturn(func(args Arguments) Arguments { + ReturnFn(func(args Arguments) Arguments { counter++ a, b, c := args[0].(int), args[1].(int), args[2].(int) assert.IsType(t, 1, a) assert.IsType(t, 1, b) assert.IsType(t, 1, c) - return Arguments{counter} + return Arguments{counter, nil} }). Twice() - answer, _ := mockedService.TheExampleMethod(2, 4, 5) + answer, err := mockedService.TheExampleMethod(2, 4, 5) + assert.NoError(t, err) assert.Equal(t, 1, answer) - answer, _ = mockedService.TheExampleMethod(44, 4, 5) + answer, err = mockedService.TheExampleMethod(44, 4, 5) + assert.NoError(t, err) assert.Equal(t, 2, answer) }) t.Run("handles func(Args) Args style", func(t *testing.T) { mockedService.On("TheExampleMethod", Anything, Anything, Anything). - RunWithReturn(func(args Arguments) Arguments { + ReturnFn(func(args Arguments) Arguments { return []interface{}{args[0].(int) + 40, fmt.Errorf("hmm")} }). Twice() - answer, _ := mockedService.TheExampleMethod(2, 4, 5) + answer, err := mockedService.TheExampleMethod(2, 4, 5) + assert.Error(t, err, "hmm") assert.Equal(t, 42, answer) - answer, _ = mockedService.TheExampleMethod(44, 4, 5) + answer, err = mockedService.TheExampleMethod(44, 4, 5) + assert.Error(t, err, "hmm") assert.Equal(t, 84, answer) }) t.Run("handles pointer input args", func(t *testing.T) { - mockedService.On("TheExampleMethod3", Anything).RunWithReturn(func(arguments Arguments) Arguments { + mockedService.On("TheExampleMethod3", Anything).ReturnFn(func(arguments Arguments) Arguments { et := arguments[0].(*ExampleType) if et == nil { return Arguments{errors.New("error")} @@ -892,7 +896,7 @@ func Test_Mock_RunWithReturn(t *testing.T) { t.Run("handles variadic input args", func(t *testing.T) { mockedService. On("TheExampleMethodMixedVariadic", Anything, Anything). - RunWithReturn(func(args Arguments) Arguments { + ReturnFn(func(args Arguments) Arguments { a, b := args[0].(int), args[1].([]int) var sum = a for _, v := range b { @@ -911,18 +915,65 @@ func Test_Mock_RunWithReturn(t *testing.T) { a := args[0].(int) assert.IsType(t, 1, a) }). - RunWithReturn(func(args Arguments) Arguments { + ReturnFn(func(args Arguments) Arguments { a := args[0].(int) return Arguments{a + 40, fmt.Errorf("hmm")} }). Return(80, nil) answer, err := mockedService.TheExampleMethod(2, 4, 5) - assert.Equal(t, 42, answer) - assert.Error(t, err) + assert.Equal(t, 80, answer) + assert.NoError(t, err) }) } +func Test_Mock_Return_RespectOrder(t *testing.T) { + tests := []struct { + name string + arrange func() *TestExampleImplementation + expected int + }{ + { + name: "should take the last return value", + arrange: func() *TestExampleImplementation { + m := new(TestExampleImplementation) + m.On("TheExampleMethod", Anything, Anything, Anything).Return(1, nil).Return(2, nil) + return m + }, + expected: 2, + }, + { + name: "should take the last return value with returnFn", + arrange: func() *TestExampleImplementation { + m := new(TestExampleImplementation) + m.On("TheExampleMethod", Anything, Anything, Anything).Return(1, nil).ReturnFn(func(args Arguments) Arguments { return Arguments{2, nil} }) + return m + }, + expected: 2, + }, + { + name: "should take the last return value with returnFn and return", + arrange: func() *TestExampleImplementation { + m := new(TestExampleImplementation) + m.On("TheExampleMethod", Anything, Anything, Anything).ReturnFn(func(args Arguments) Arguments { + return Arguments{1, nil} + }).Return(2, nil) + return m + }, + expected: 2, + }, + } + // run the tests + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + m := test.arrange() + actualResult, actualError := m.TheExampleMethod(0, 0, 0) + assert.NoError(t, actualError) + assert.Equal(t, test.expected, actualResult) + }) + } +} + func Test_Mock_Return_Once(t *testing.T) { // make a test impl object @@ -1430,7 +1481,7 @@ func Test_Mock_Called_For_SetTime_Expectation(t *testing.T) { var mockedService = new(TestExampleImplementation) - mockedService.On("TheExampleMethod", 1, 2, 3).Return(5, "6", true).Times(4) + mockedService.On("TheExampleMethod", 1, 2, 3).Return(5, nil).Times(4) mockedService.TheExampleMethod(1, 2, 3) mockedService.TheExampleMethod(1, 2, 3) From f2ac7eb7f966aac86e325b3b8bd0d64e939d9dd6 Mon Sep 17 00:00:00 2001 From: Justin Lewis Date: Fri, 16 May 2025 10:53:22 -0400 Subject: [PATCH 14/15] go fmt --- mock/mock.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 52b977d33..cd9941579 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -193,9 +193,9 @@ func (c *Call) Run(fn func(args Arguments)) *Call { // ReturnFn sets a handler to be called before returning. // -// Mock.On("MyMethod", arg1, arg2).ReturnFn(func(args Arguments) Arguments { -// return Arguments{args.Get(0) + args.Get(1)} -// }) +// Mock.On("MyMethod", arg1, arg2).ReturnFn(func(args Arguments) Arguments { +// return Arguments{args.Get(0) + args.Get(1)} +// }) func (c *Call) ReturnFn(fn func(args Arguments) Arguments) *Call { c.lock() defer c.unlock() From 8231ec41fd6ba3efee8d57f2879af8366b12098d Mon Sep 17 00:00:00 2001 From: Justin Lewis Date: Sat, 11 Oct 2025 19:57:18 -0400 Subject: [PATCH 15/15] show test intent better --- mock/mock_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mock/mock_test.go b/mock/mock_test.go index d20500390..c31585e16 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -848,17 +848,19 @@ func Test_Mock_ReturnFn(t *testing.T) { assert.IsType(t, 1, a) assert.IsType(t, 1, b) assert.IsType(t, 1, c) - return Arguments{counter, nil} + return Arguments{a + b + c, nil} }). Twice() answer, err := mockedService.TheExampleMethod(2, 4, 5) assert.NoError(t, err) - assert.Equal(t, 1, answer) + assert.Equal(t, 11, answer) + assert.Equal(t, 1, counter) answer, err = mockedService.TheExampleMethod(44, 4, 5) assert.NoError(t, err) - assert.Equal(t, 2, answer) + assert.Equal(t, 53, answer) + assert.Equal(t, 2, counter) }) t.Run("handles func(Args) Args style", func(t *testing.T) {