1// Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT.
2
3package assert
4
5import (
6 http "net/http"
7 url "net/url"
8 time "time"
9)
10
11// Conditionf uses a Comparison to assert a complex condition.
12func Conditionf(t TestingT, comp Comparison, msg string, args ...interface{}) bool {
13 if h, ok := t.(tHelper); ok {
14 h.Helper()
15 }
16 return Condition(t, comp, append([]interface{}{msg}, args...)...)
17}
18
19// Containsf asserts that the specified string, list(array, slice...) or map contains the
20// specified substring or element.
21//
22// assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
23// assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
24// assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
25func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool {
26 if h, ok := t.(tHelper); ok {
27 h.Helper()
28 }
29 return Contains(t, s, contains, append([]interface{}{msg}, args...)...)
30}
31
32// DirExistsf checks whether a directory exists in the given path. It also fails
33// if the path is a file rather a directory or there is an error checking whether it exists.
34func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
35 if h, ok := t.(tHelper); ok {
36 h.Helper()
37 }
38 return DirExists(t, path, append([]interface{}{msg}, args...)...)
39}
40
41// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
42// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
43// the number of appearances of each of them in both lists should match.
44//
45// assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
46func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
47 if h, ok := t.(tHelper); ok {
48 h.Helper()
49 }
50 return ElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
51}
52
53// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
54// a slice or a channel with len == 0.
55//
56// assert.Emptyf(t, obj, "error message %s", "formatted")
57func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
58 if h, ok := t.(tHelper); ok {
59 h.Helper()
60 }
61 return Empty(t, object, append([]interface{}{msg}, args...)...)
62}
63
64// Equalf asserts that two objects are equal.
65//
66// assert.Equalf(t, 123, 123, "error message %s", "formatted")
67//
68// Pointer variable equality is determined based on the equality of the
69// referenced values (as opposed to the memory addresses). Function equality
70// cannot be determined and will always fail.
71func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
72 if h, ok := t.(tHelper); ok {
73 h.Helper()
74 }
75 return Equal(t, expected, actual, append([]interface{}{msg}, args...)...)
76}
77
78// EqualErrorf asserts that a function returned an error (i.e. not `nil`)
79// and that it is equal to the provided error.
80//
81// actualObj, err := SomeFunction()
82// assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
83func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool {
84 if h, ok := t.(tHelper); ok {
85 h.Helper()
86 }
87 return EqualError(t, theError, errString, append([]interface{}{msg}, args...)...)
88}
89
90// EqualExportedValuesf asserts that the types of two objects are equal and their public
91// fields are also equal. This is useful for comparing structs that have private fields
92// that could potentially differ.
93//
94// type S struct {
95// Exported int
96// notExported int
97// }
98// assert.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true
99// assert.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false
100func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
101 if h, ok := t.(tHelper); ok {
102 h.Helper()
103 }
104 return EqualExportedValues(t, expected, actual, append([]interface{}{msg}, args...)...)
105}
106
107// EqualValuesf asserts that two objects are equal or convertible to the larger
108// type and equal.
109//
110// assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")
111func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
112 if h, ok := t.(tHelper); ok {
113 h.Helper()
114 }
115 return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...)
116}
117
118// Errorf asserts that a function returned an error (i.e. not `nil`).
119//
120// actualObj, err := SomeFunction()
121// if assert.Errorf(t, err, "error message %s", "formatted") {
122// assert.Equal(t, expectedErrorf, err)
123// }
124func Errorf(t TestingT, err error, msg string, args ...interface{}) bool {
125 if h, ok := t.(tHelper); ok {
126 h.Helper()
127 }
128 return Error(t, err, append([]interface{}{msg}, args...)...)
129}
130
131// ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
132// This is a wrapper for errors.As.
133func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool {
134 if h, ok := t.(tHelper); ok {
135 h.Helper()
136 }
137 return ErrorAs(t, err, target, append([]interface{}{msg}, args...)...)
138}
139
140// ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
141// and that the error contains the specified substring.
142//
143// actualObj, err := SomeFunction()
144// assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
145func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) bool {
146 if h, ok := t.(tHelper); ok {
147 h.Helper()
148 }
149 return ErrorContains(t, theError, contains, append([]interface{}{msg}, args...)...)
150}
151
152// ErrorIsf asserts that at least one of the errors in err's chain matches target.
153// This is a wrapper for errors.Is.
154func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool {
155 if h, ok := t.(tHelper); ok {
156 h.Helper()
157 }
158 return ErrorIs(t, err, target, append([]interface{}{msg}, args...)...)
159}
160
161// Eventuallyf asserts that given condition will be met in waitFor time,
162// periodically checking target function each tick.
163//
164// assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
165func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
166 if h, ok := t.(tHelper); ok {
167 h.Helper()
168 }
169 return Eventually(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...)
170}
171
172// EventuallyWithTf asserts that given condition will be met in waitFor time,
173// periodically checking target function each tick. In contrast to Eventually,
174// it supplies a CollectT to the condition function, so that the condition
175// function can use the CollectT to call other assertions.
176// The condition is considered "met" if no errors are raised in a tick.
177// The supplied CollectT collects all errors from one tick (if there are any).
178// If the condition is not met before waitFor, the collected errors of
179// the last tick are copied to t.
180//
181// externalValue := false
182// go func() {
183// time.Sleep(8*time.Second)
184// externalValue = true
185// }()
186// assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") {
187// // add assertions as needed; any assertion failure will fail the current tick
188// assert.True(c, externalValue, "expected 'externalValue' to be true")
189// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
190func EventuallyWithTf(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
191 if h, ok := t.(tHelper); ok {
192 h.Helper()
193 }
194 return EventuallyWithT(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...)
195}
196
197// Exactlyf asserts that two objects are equal in value and type.
198//
199// assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted")
200func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
201 if h, ok := t.(tHelper); ok {
202 h.Helper()
203 }
204 return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...)
205}
206
207// Failf reports a failure through
208func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool {
209 if h, ok := t.(tHelper); ok {
210 h.Helper()
211 }
212 return Fail(t, failureMessage, append([]interface{}{msg}, args...)...)
213}
214
215// FailNowf fails test
216func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool {
217 if h, ok := t.(tHelper); ok {
218 h.Helper()
219 }
220 return FailNow(t, failureMessage, append([]interface{}{msg}, args...)...)
221}
222
223// Falsef asserts that the specified value is false.
224//
225// assert.Falsef(t, myBool, "error message %s", "formatted")
226func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool {
227 if h, ok := t.(tHelper); ok {
228 h.Helper()
229 }
230 return False(t, value, append([]interface{}{msg}, args...)...)
231}
232
233// FileExistsf checks whether a file exists in the given path. It also fails if
234// the path points to a directory or there is an error when trying to check the file.
235func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
236 if h, ok := t.(tHelper); ok {
237 h.Helper()
238 }
239 return FileExists(t, path, append([]interface{}{msg}, args...)...)
240}
241
242// Greaterf asserts that the first element is greater than the second
243//
244// assert.Greaterf(t, 2, 1, "error message %s", "formatted")
245// assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted")
246// assert.Greaterf(t, "b", "a", "error message %s", "formatted")
247func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
248 if h, ok := t.(tHelper); ok {
249 h.Helper()
250 }
251 return Greater(t, e1, e2, append([]interface{}{msg}, args...)...)
252}
253
254// GreaterOrEqualf asserts that the first element is greater than or equal to the second
255//
256// assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")
257// assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")
258// assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")
259// assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")
260func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
261 if h, ok := t.(tHelper); ok {
262 h.Helper()
263 }
264 return GreaterOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...)
265}
266
267// HTTPBodyContainsf asserts that a specified handler returns a
268// body that contains a string.
269//
270// assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
271//
272// Returns whether the assertion was successful (true) or not (false).
273func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
274 if h, ok := t.(tHelper); ok {
275 h.Helper()
276 }
277 return HTTPBodyContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...)
278}
279
280// HTTPBodyNotContainsf asserts that a specified handler returns a
281// body that does not contain a string.
282//
283// assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
284//
285// Returns whether the assertion was successful (true) or not (false).
286func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
287 if h, ok := t.(tHelper); ok {
288 h.Helper()
289 }
290 return HTTPBodyNotContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...)
291}
292
293// HTTPErrorf asserts that a specified handler returns an error status code.
294//
295// assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
296//
297// Returns whether the assertion was successful (true) or not (false).
298func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
299 if h, ok := t.(tHelper); ok {
300 h.Helper()
301 }
302 return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
303}
304
305// HTTPRedirectf asserts that a specified handler returns a redirect status code.
306//
307// assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
308//
309// Returns whether the assertion was successful (true) or not (false).
310func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
311 if h, ok := t.(tHelper); ok {
312 h.Helper()
313 }
314 return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
315}
316
317// HTTPStatusCodef asserts that a specified handler returns a specified status code.
318//
319// assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")
320//
321// Returns whether the assertion was successful (true) or not (false).
322func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool {
323 if h, ok := t.(tHelper); ok {
324 h.Helper()
325 }
326 return HTTPStatusCode(t, handler, method, url, values, statuscode, append([]interface{}{msg}, args...)...)
327}
328
329// HTTPSuccessf asserts that a specified handler returns a success status code.
330//
331// assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
332//
333// Returns whether the assertion was successful (true) or not (false).
334func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
335 if h, ok := t.(tHelper); ok {
336 h.Helper()
337 }
338 return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
339}
340
341// Implementsf asserts that an object is implemented by the specified interface.
342//
343// assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
344func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
345 if h, ok := t.(tHelper); ok {
346 h.Helper()
347 }
348 return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...)
349}
350
351// InDeltaf asserts that the two numerals are within delta of each other.
352//
353// assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted")
354func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
355 if h, ok := t.(tHelper); ok {
356 h.Helper()
357 }
358 return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
359}
360
361// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
362func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
363 if h, ok := t.(tHelper); ok {
364 h.Helper()
365 }
366 return InDeltaMapValues(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
367}
368
369// InDeltaSlicef is the same as InDelta, except it compares two slices.
370func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
371 if h, ok := t.(tHelper); ok {
372 h.Helper()
373 }
374 return InDeltaSlice(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
375}
376
377// InEpsilonf asserts that expected and actual have a relative error less than epsilon
378func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
379 if h, ok := t.(tHelper); ok {
380 h.Helper()
381 }
382 return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
383}
384
385// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
386func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
387 if h, ok := t.(tHelper); ok {
388 h.Helper()
389 }
390 return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
391}
392
393// IsDecreasingf asserts that the collection is decreasing
394//
395// assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted")
396// assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted")
397// assert.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted")
398func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
399 if h, ok := t.(tHelper); ok {
400 h.Helper()
401 }
402 return IsDecreasing(t, object, append([]interface{}{msg}, args...)...)
403}
404
405// IsIncreasingf asserts that the collection is increasing
406//
407// assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted")
408// assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted")
409// assert.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted")
410func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
411 if h, ok := t.(tHelper); ok {
412 h.Helper()
413 }
414 return IsIncreasing(t, object, append([]interface{}{msg}, args...)...)
415}
416
417// IsNonDecreasingf asserts that the collection is not decreasing
418//
419// assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted")
420// assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted")
421// assert.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted")
422func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
423 if h, ok := t.(tHelper); ok {
424 h.Helper()
425 }
426 return IsNonDecreasing(t, object, append([]interface{}{msg}, args...)...)
427}
428
429// IsNonIncreasingf asserts that the collection is not increasing
430//
431// assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted")
432// assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted")
433// assert.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted")
434func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
435 if h, ok := t.(tHelper); ok {
436 h.Helper()
437 }
438 return IsNonIncreasing(t, object, append([]interface{}{msg}, args...)...)
439}
440
441// IsTypef asserts that the specified objects are of the same type.
442func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
443 if h, ok := t.(tHelper); ok {
444 h.Helper()
445 }
446 return IsType(t, expectedType, object, append([]interface{}{msg}, args...)...)
447}
448
449// JSONEqf asserts that two JSON strings are equivalent.
450//
451// assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
452func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool {
453 if h, ok := t.(tHelper); ok {
454 h.Helper()
455 }
456 return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...)
457}
458
459// Lenf asserts that the specified object has specific length.
460// Lenf also fails if the object has a type that len() not accept.
461//
462// assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
463func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool {
464 if h, ok := t.(tHelper); ok {
465 h.Helper()
466 }
467 return Len(t, object, length, append([]interface{}{msg}, args...)...)
468}
469
470// Lessf asserts that the first element is less than the second
471//
472// assert.Lessf(t, 1, 2, "error message %s", "formatted")
473// assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted")
474// assert.Lessf(t, "a", "b", "error message %s", "formatted")
475func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
476 if h, ok := t.(tHelper); ok {
477 h.Helper()
478 }
479 return Less(t, e1, e2, append([]interface{}{msg}, args...)...)
480}
481
482// LessOrEqualf asserts that the first element is less than or equal to the second
483//
484// assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted")
485// assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted")
486// assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted")
487// assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted")
488func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
489 if h, ok := t.(tHelper); ok {
490 h.Helper()
491 }
492 return LessOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...)
493}
494
495// Negativef asserts that the specified element is negative
496//
497// assert.Negativef(t, -1, "error message %s", "formatted")
498// assert.Negativef(t, -1.23, "error message %s", "formatted")
499func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) bool {
500 if h, ok := t.(tHelper); ok {
501 h.Helper()
502 }
503 return Negative(t, e, append([]interface{}{msg}, args...)...)
504}
505
506// Neverf asserts that the given condition doesn't satisfy in waitFor time,
507// periodically checking the target function each tick.
508//
509// assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
510func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
511 if h, ok := t.(tHelper); ok {
512 h.Helper()
513 }
514 return Never(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...)
515}
516
517// Nilf asserts that the specified object is nil.
518//
519// assert.Nilf(t, err, "error message %s", "formatted")
520func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
521 if h, ok := t.(tHelper); ok {
522 h.Helper()
523 }
524 return Nil(t, object, append([]interface{}{msg}, args...)...)
525}
526
527// NoDirExistsf checks whether a directory does not exist in the given path.
528// It fails if the path points to an existing _directory_ only.
529func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
530 if h, ok := t.(tHelper); ok {
531 h.Helper()
532 }
533 return NoDirExists(t, path, append([]interface{}{msg}, args...)...)
534}
535
536// NoErrorf asserts that a function returned no error (i.e. `nil`).
537//
538// actualObj, err := SomeFunction()
539// if assert.NoErrorf(t, err, "error message %s", "formatted") {
540// assert.Equal(t, expectedObj, actualObj)
541// }
542func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool {
543 if h, ok := t.(tHelper); ok {
544 h.Helper()
545 }
546 return NoError(t, err, append([]interface{}{msg}, args...)...)
547}
548
549// NoFileExistsf checks whether a file does not exist in a given path. It fails
550// if the path points to an existing _file_ only.
551func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
552 if h, ok := t.(tHelper); ok {
553 h.Helper()
554 }
555 return NoFileExists(t, path, append([]interface{}{msg}, args...)...)
556}
557
558// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
559// specified substring or element.
560//
561// assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
562// assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
563// assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
564func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool {
565 if h, ok := t.(tHelper); ok {
566 h.Helper()
567 }
568 return NotContains(t, s, contains, append([]interface{}{msg}, args...)...)
569}
570
571// NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified
572// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
573// the number of appearances of each of them in both lists should not match.
574// This is an inverse of ElementsMatch.
575//
576// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false
577//
578// assert.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true
579//
580// assert.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true
581func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
582 if h, ok := t.(tHelper); ok {
583 h.Helper()
584 }
585 return NotElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
586}
587
588// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
589// a slice or a channel with len == 0.
590//
591// if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
592// assert.Equal(t, "two", obj[1])
593// }
594func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
595 if h, ok := t.(tHelper); ok {
596 h.Helper()
597 }
598 return NotEmpty(t, object, append([]interface{}{msg}, args...)...)
599}
600
601// NotEqualf asserts that the specified values are NOT equal.
602//
603// assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
604//
605// Pointer variable equality is determined based on the equality of the
606// referenced values (as opposed to the memory addresses).
607func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
608 if h, ok := t.(tHelper); ok {
609 h.Helper()
610 }
611 return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...)
612}
613
614// NotEqualValuesf asserts that two objects are not equal even when converted to the same type
615//
616// assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")
617func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
618 if h, ok := t.(tHelper); ok {
619 h.Helper()
620 }
621 return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...)
622}
623
624// NotErrorAsf asserts that none of the errors in err's chain matches target,
625// but if so, sets target to that error value.
626func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool {
627 if h, ok := t.(tHelper); ok {
628 h.Helper()
629 }
630 return NotErrorAs(t, err, target, append([]interface{}{msg}, args...)...)
631}
632
633// NotErrorIsf asserts that none of the errors in err's chain matches target.
634// This is a wrapper for errors.Is.
635func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool {
636 if h, ok := t.(tHelper); ok {
637 h.Helper()
638 }
639 return NotErrorIs(t, err, target, append([]interface{}{msg}, args...)...)
640}
641
642// NotImplementsf asserts that an object does not implement the specified interface.
643//
644// assert.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
645func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
646 if h, ok := t.(tHelper); ok {
647 h.Helper()
648 }
649 return NotImplements(t, interfaceObject, object, append([]interface{}{msg}, args...)...)
650}
651
652// NotNilf asserts that the specified object is not nil.
653//
654// assert.NotNilf(t, err, "error message %s", "formatted")
655func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
656 if h, ok := t.(tHelper); ok {
657 h.Helper()
658 }
659 return NotNil(t, object, append([]interface{}{msg}, args...)...)
660}
661
662// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
663//
664// assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
665func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool {
666 if h, ok := t.(tHelper); ok {
667 h.Helper()
668 }
669 return NotPanics(t, f, append([]interface{}{msg}, args...)...)
670}
671
672// NotRegexpf asserts that a specified regexp does not match a string.
673//
674// assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")
675// assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
676func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool {
677 if h, ok := t.(tHelper); ok {
678 h.Helper()
679 }
680 return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...)
681}
682
683// NotSamef asserts that two pointers do not reference the same object.
684//
685// assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted")
686//
687// Both arguments must be pointer variables. Pointer variable sameness is
688// determined based on the equality of both type and value.
689func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
690 if h, ok := t.(tHelper); ok {
691 h.Helper()
692 }
693 return NotSame(t, expected, actual, append([]interface{}{msg}, args...)...)
694}
695
696// NotSubsetf asserts that the specified list(array, slice...) or map does NOT
697// contain all elements given in the specified subset list(array, slice...) or
698// map.
699//
700// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
701// assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
702func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
703 if h, ok := t.(tHelper); ok {
704 h.Helper()
705 }
706 return NotSubset(t, list, subset, append([]interface{}{msg}, args...)...)
707}
708
709// NotZerof asserts that i is not the zero value for its type.
710func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
711 if h, ok := t.(tHelper); ok {
712 h.Helper()
713 }
714 return NotZero(t, i, append([]interface{}{msg}, args...)...)
715}
716
717// Panicsf asserts that the code inside the specified PanicTestFunc panics.
718//
719// assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
720func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool {
721 if h, ok := t.(tHelper); ok {
722 h.Helper()
723 }
724 return Panics(t, f, append([]interface{}{msg}, args...)...)
725}
726
727// PanicsWithErrorf asserts that the code inside the specified PanicTestFunc
728// panics, and that the recovered panic value is an error that satisfies the
729// EqualError comparison.
730//
731// assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
732func PanicsWithErrorf(t TestingT, errString string, f PanicTestFunc, msg string, args ...interface{}) bool {
733 if h, ok := t.(tHelper); ok {
734 h.Helper()
735 }
736 return PanicsWithError(t, errString, f, append([]interface{}{msg}, args...)...)
737}
738
739// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
740// the recovered panic value equals the expected panic value.
741//
742// assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
743func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool {
744 if h, ok := t.(tHelper); ok {
745 h.Helper()
746 }
747 return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...)
748}
749
750// Positivef asserts that the specified element is positive
751//
752// assert.Positivef(t, 1, "error message %s", "formatted")
753// assert.Positivef(t, 1.23, "error message %s", "formatted")
754func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) bool {
755 if h, ok := t.(tHelper); ok {
756 h.Helper()
757 }
758 return Positive(t, e, append([]interface{}{msg}, args...)...)
759}
760
761// Regexpf asserts that a specified regexp matches a string.
762//
763// assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")
764// assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
765func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool {
766 if h, ok := t.(tHelper); ok {
767 h.Helper()
768 }
769 return Regexp(t, rx, str, append([]interface{}{msg}, args...)...)
770}
771
772// Samef asserts that two pointers reference the same object.
773//
774// assert.Samef(t, ptr1, ptr2, "error message %s", "formatted")
775//
776// Both arguments must be pointer variables. Pointer variable sameness is
777// determined based on the equality of both type and value.
778func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
779 if h, ok := t.(tHelper); ok {
780 h.Helper()
781 }
782 return Same(t, expected, actual, append([]interface{}{msg}, args...)...)
783}
784
785// Subsetf asserts that the specified list(array, slice...) or map contains all
786// elements given in the specified subset list(array, slice...) or map.
787//
788// assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
789// assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
790func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
791 if h, ok := t.(tHelper); ok {
792 h.Helper()
793 }
794 return Subset(t, list, subset, append([]interface{}{msg}, args...)...)
795}
796
797// Truef asserts that the specified value is true.
798//
799// assert.Truef(t, myBool, "error message %s", "formatted")
800func Truef(t TestingT, value bool, msg string, args ...interface{}) bool {
801 if h, ok := t.(tHelper); ok {
802 h.Helper()
803 }
804 return True(t, value, append([]interface{}{msg}, args...)...)
805}
806
807// WithinDurationf asserts that the two times are within duration delta of each other.
808//
809// assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
810func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool {
811 if h, ok := t.(tHelper); ok {
812 h.Helper()
813 }
814 return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
815}
816
817// WithinRangef asserts that a time is within a time range (inclusive).
818//
819// assert.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted")
820func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) bool {
821 if h, ok := t.(tHelper); ok {
822 h.Helper()
823 }
824 return WithinRange(t, actual, start, end, append([]interface{}{msg}, args...)...)
825}
826
827// YAMLEqf asserts that two YAML strings are equivalent.
828func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool {
829 if h, ok := t.(tHelper); ok {
830 h.Helper()
831 }
832 return YAMLEq(t, expected, actual, append([]interface{}{msg}, args...)...)
833}
834
835// Zerof asserts that i is the zero value for its type.
836func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
837 if h, ok := t.(tHelper); ok {
838 h.Helper()
839 }
840 return Zero(t, i, append([]interface{}{msg}, args...)...)
841}