30 h.Helper() |
30 h.Helper() |
31 } |
31 } |
32 return Contains(t, s, contains, append([]interface{}{msg}, args...)...) |
32 return Contains(t, s, contains, append([]interface{}{msg}, args...)...) |
33 } |
33 } |
34 |
34 |
35 // 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. |
35 // DirExistsf checks whether a directory exists in the given path. It also fails |
|
36 // if the path is a file rather a directory or there is an error checking whether it exists. |
36 func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
37 func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
37 if h, ok := t.(tHelper); ok { |
38 if h, ok := t.(tHelper); ok { |
38 h.Helper() |
39 h.Helper() |
39 } |
40 } |
40 return DirExists(t, path, append([]interface{}{msg}, args...)...) |
41 return DirExists(t, path, append([]interface{}{msg}, args...)...) |
90 } |
91 } |
91 |
92 |
92 // EqualValuesf asserts that two objects are equal or convertable to the same types |
93 // EqualValuesf asserts that two objects are equal or convertable to the same types |
93 // and equal. |
94 // and equal. |
94 // |
95 // |
95 // assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123)) |
96 // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") |
96 func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
97 func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
97 if h, ok := t.(tHelper); ok { |
98 if h, ok := t.(tHelper); ok { |
98 h.Helper() |
99 h.Helper() |
99 } |
100 } |
100 return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) |
101 return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) |
111 h.Helper() |
112 h.Helper() |
112 } |
113 } |
113 return Error(t, err, append([]interface{}{msg}, args...)...) |
114 return Error(t, err, append([]interface{}{msg}, args...)...) |
114 } |
115 } |
115 |
116 |
|
117 // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. |
|
118 // This is a wrapper for errors.As. |
|
119 func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool { |
|
120 if h, ok := t.(tHelper); ok { |
|
121 h.Helper() |
|
122 } |
|
123 return ErrorAs(t, err, target, append([]interface{}{msg}, args...)...) |
|
124 } |
|
125 |
|
126 // ErrorIsf asserts that at least one of the errors in err's chain matches target. |
|
127 // This is a wrapper for errors.Is. |
|
128 func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool { |
|
129 if h, ok := t.(tHelper); ok { |
|
130 h.Helper() |
|
131 } |
|
132 return ErrorIs(t, err, target, append([]interface{}{msg}, args...)...) |
|
133 } |
|
134 |
|
135 // Eventuallyf asserts that given condition will be met in waitFor time, |
|
136 // periodically checking target function each tick. |
|
137 // |
|
138 // assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") |
|
139 func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { |
|
140 if h, ok := t.(tHelper); ok { |
|
141 h.Helper() |
|
142 } |
|
143 return Eventually(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...) |
|
144 } |
|
145 |
116 // Exactlyf asserts that two objects are equal in value and type. |
146 // Exactlyf asserts that two objects are equal in value and type. |
117 // |
147 // |
118 // assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123)) |
148 // assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") |
119 func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
149 func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
120 if h, ok := t.(tHelper); ok { |
150 if h, ok := t.(tHelper); ok { |
121 h.Helper() |
151 h.Helper() |
122 } |
152 } |
123 return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...) |
153 return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...) |
147 h.Helper() |
177 h.Helper() |
148 } |
178 } |
149 return False(t, value, append([]interface{}{msg}, args...)...) |
179 return False(t, value, append([]interface{}{msg}, args...)...) |
150 } |
180 } |
151 |
181 |
152 // 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. |
182 // FileExistsf checks whether a file exists in the given path. It also fails if |
|
183 // the path points to a directory or there is an error when trying to check the file. |
153 func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
184 func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
154 if h, ok := t.(tHelper); ok { |
185 if h, ok := t.(tHelper); ok { |
155 h.Helper() |
186 h.Helper() |
156 } |
187 } |
157 return FileExists(t, path, append([]interface{}{msg}, args...)...) |
188 return FileExists(t, path, append([]interface{}{msg}, args...)...) |
|
189 } |
|
190 |
|
191 // Greaterf asserts that the first element is greater than the second |
|
192 // |
|
193 // assert.Greaterf(t, 2, 1, "error message %s", "formatted") |
|
194 // assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") |
|
195 // assert.Greaterf(t, "b", "a", "error message %s", "formatted") |
|
196 func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
|
197 if h, ok := t.(tHelper); ok { |
|
198 h.Helper() |
|
199 } |
|
200 return Greater(t, e1, e2, append([]interface{}{msg}, args...)...) |
|
201 } |
|
202 |
|
203 // GreaterOrEqualf asserts that the first element is greater than or equal to the second |
|
204 // |
|
205 // assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") |
|
206 // assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") |
|
207 // assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") |
|
208 // assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") |
|
209 func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
|
210 if h, ok := t.(tHelper); ok { |
|
211 h.Helper() |
|
212 } |
|
213 return GreaterOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...) |
158 } |
214 } |
159 |
215 |
160 // HTTPBodyContainsf asserts that a specified handler returns a |
216 // HTTPBodyContainsf asserts that a specified handler returns a |
161 // body that contains a string. |
217 // body that contains a string. |
162 // |
218 // |
185 |
241 |
186 // HTTPErrorf asserts that a specified handler returns an error status code. |
242 // HTTPErrorf asserts that a specified handler returns an error status code. |
187 // |
243 // |
188 // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} |
244 // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} |
189 // |
245 // |
190 // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). |
246 // Returns whether the assertion was successful (true) or not (false). |
191 func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
247 func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
192 if h, ok := t.(tHelper); ok { |
248 if h, ok := t.(tHelper); ok { |
193 h.Helper() |
249 h.Helper() |
194 } |
250 } |
195 return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
251 return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
197 |
253 |
198 // HTTPRedirectf asserts that a specified handler returns a redirect status code. |
254 // HTTPRedirectf asserts that a specified handler returns a redirect status code. |
199 // |
255 // |
200 // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} |
256 // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} |
201 // |
257 // |
202 // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). |
258 // Returns whether the assertion was successful (true) or not (false). |
203 func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
259 func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
204 if h, ok := t.(tHelper); ok { |
260 if h, ok := t.(tHelper); ok { |
205 h.Helper() |
261 h.Helper() |
206 } |
262 } |
207 return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
263 return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
|
264 } |
|
265 |
|
266 // HTTPStatusCodef asserts that a specified handler returns a specified status code. |
|
267 // |
|
268 // assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") |
|
269 // |
|
270 // Returns whether the assertion was successful (true) or not (false). |
|
271 func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool { |
|
272 if h, ok := t.(tHelper); ok { |
|
273 h.Helper() |
|
274 } |
|
275 return HTTPStatusCode(t, handler, method, url, values, statuscode, append([]interface{}{msg}, args...)...) |
208 } |
276 } |
209 |
277 |
210 // HTTPSuccessf asserts that a specified handler returns a success status code. |
278 // HTTPSuccessf asserts that a specified handler returns a success status code. |
211 // |
279 // |
212 // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") |
280 // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") |
219 return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
287 return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
220 } |
288 } |
221 |
289 |
222 // Implementsf asserts that an object is implemented by the specified interface. |
290 // Implementsf asserts that an object is implemented by the specified interface. |
223 // |
291 // |
224 // assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject)) |
292 // assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") |
225 func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool { |
293 func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool { |
226 if h, ok := t.(tHelper); ok { |
294 if h, ok := t.(tHelper); ok { |
227 h.Helper() |
295 h.Helper() |
228 } |
296 } |
229 return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...) |
297 return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...) |
230 } |
298 } |
231 |
299 |
232 // InDeltaf asserts that the two numerals are within delta of each other. |
300 // InDeltaf asserts that the two numerals are within delta of each other. |
233 // |
301 // |
234 // assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01) |
302 // assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") |
235 func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { |
303 func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { |
236 if h, ok := t.(tHelper); ok { |
304 if h, ok := t.(tHelper); ok { |
237 h.Helper() |
305 h.Helper() |
238 } |
306 } |
239 return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
307 return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
269 h.Helper() |
337 h.Helper() |
270 } |
338 } |
271 return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) |
339 return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) |
272 } |
340 } |
273 |
341 |
|
342 // IsDecreasingf asserts that the collection is decreasing |
|
343 // |
|
344 // assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") |
|
345 // assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") |
|
346 // assert.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") |
|
347 func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
|
348 if h, ok := t.(tHelper); ok { |
|
349 h.Helper() |
|
350 } |
|
351 return IsDecreasing(t, object, append([]interface{}{msg}, args...)...) |
|
352 } |
|
353 |
|
354 // IsIncreasingf asserts that the collection is increasing |
|
355 // |
|
356 // assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") |
|
357 // assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") |
|
358 // assert.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") |
|
359 func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
|
360 if h, ok := t.(tHelper); ok { |
|
361 h.Helper() |
|
362 } |
|
363 return IsIncreasing(t, object, append([]interface{}{msg}, args...)...) |
|
364 } |
|
365 |
|
366 // IsNonDecreasingf asserts that the collection is not decreasing |
|
367 // |
|
368 // assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") |
|
369 // assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") |
|
370 // assert.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") |
|
371 func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
|
372 if h, ok := t.(tHelper); ok { |
|
373 h.Helper() |
|
374 } |
|
375 return IsNonDecreasing(t, object, append([]interface{}{msg}, args...)...) |
|
376 } |
|
377 |
|
378 // IsNonIncreasingf asserts that the collection is not increasing |
|
379 // |
|
380 // assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") |
|
381 // assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") |
|
382 // assert.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") |
|
383 func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
|
384 if h, ok := t.(tHelper); ok { |
|
385 h.Helper() |
|
386 } |
|
387 return IsNonIncreasing(t, object, append([]interface{}{msg}, args...)...) |
|
388 } |
|
389 |
274 // IsTypef asserts that the specified objects are of the same type. |
390 // IsTypef asserts that the specified objects are of the same type. |
275 func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool { |
391 func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool { |
276 if h, ok := t.(tHelper); ok { |
392 if h, ok := t.(tHelper); ok { |
277 h.Helper() |
393 h.Helper() |
278 } |
394 } |
298 h.Helper() |
414 h.Helper() |
299 } |
415 } |
300 return Len(t, object, length, append([]interface{}{msg}, args...)...) |
416 return Len(t, object, length, append([]interface{}{msg}, args...)...) |
301 } |
417 } |
302 |
418 |
|
419 // Lessf asserts that the first element is less than the second |
|
420 // |
|
421 // assert.Lessf(t, 1, 2, "error message %s", "formatted") |
|
422 // assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") |
|
423 // assert.Lessf(t, "a", "b", "error message %s", "formatted") |
|
424 func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
|
425 if h, ok := t.(tHelper); ok { |
|
426 h.Helper() |
|
427 } |
|
428 return Less(t, e1, e2, append([]interface{}{msg}, args...)...) |
|
429 } |
|
430 |
|
431 // LessOrEqualf asserts that the first element is less than or equal to the second |
|
432 // |
|
433 // assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") |
|
434 // assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") |
|
435 // assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") |
|
436 // assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") |
|
437 func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
|
438 if h, ok := t.(tHelper); ok { |
|
439 h.Helper() |
|
440 } |
|
441 return LessOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...) |
|
442 } |
|
443 |
|
444 // Negativef asserts that the specified element is negative |
|
445 // |
|
446 // assert.Negativef(t, -1, "error message %s", "formatted") |
|
447 // assert.Negativef(t, -1.23, "error message %s", "formatted") |
|
448 func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) bool { |
|
449 if h, ok := t.(tHelper); ok { |
|
450 h.Helper() |
|
451 } |
|
452 return Negative(t, e, append([]interface{}{msg}, args...)...) |
|
453 } |
|
454 |
|
455 // Neverf asserts that the given condition doesn't satisfy in waitFor time, |
|
456 // periodically checking the target function each tick. |
|
457 // |
|
458 // assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") |
|
459 func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { |
|
460 if h, ok := t.(tHelper); ok { |
|
461 h.Helper() |
|
462 } |
|
463 return Never(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...) |
|
464 } |
|
465 |
303 // Nilf asserts that the specified object is nil. |
466 // Nilf asserts that the specified object is nil. |
304 // |
467 // |
305 // assert.Nilf(t, err, "error message %s", "formatted") |
468 // assert.Nilf(t, err, "error message %s", "formatted") |
306 func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
469 func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
307 if h, ok := t.(tHelper); ok { |
470 if h, ok := t.(tHelper); ok { |
308 h.Helper() |
471 h.Helper() |
309 } |
472 } |
310 return Nil(t, object, append([]interface{}{msg}, args...)...) |
473 return Nil(t, object, append([]interface{}{msg}, args...)...) |
|
474 } |
|
475 |
|
476 // NoDirExistsf checks whether a directory does not exist in the given path. |
|
477 // It fails if the path points to an existing _directory_ only. |
|
478 func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
|
479 if h, ok := t.(tHelper); ok { |
|
480 h.Helper() |
|
481 } |
|
482 return NoDirExists(t, path, append([]interface{}{msg}, args...)...) |
311 } |
483 } |
312 |
484 |
313 // NoErrorf asserts that a function returned no error (i.e. `nil`). |
485 // NoErrorf asserts that a function returned no error (i.e. `nil`). |
314 // |
486 // |
315 // actualObj, err := SomeFunction() |
487 // actualObj, err := SomeFunction() |
321 h.Helper() |
493 h.Helper() |
322 } |
494 } |
323 return NoError(t, err, append([]interface{}{msg}, args...)...) |
495 return NoError(t, err, append([]interface{}{msg}, args...)...) |
324 } |
496 } |
325 |
497 |
|
498 // NoFileExistsf checks whether a file does not exist in a given path. It fails |
|
499 // if the path points to an existing _file_ only. |
|
500 func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
|
501 if h, ok := t.(tHelper); ok { |
|
502 h.Helper() |
|
503 } |
|
504 return NoFileExists(t, path, append([]interface{}{msg}, args...)...) |
|
505 } |
|
506 |
326 // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the |
507 // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the |
327 // specified substring or element. |
508 // specified substring or element. |
328 // |
509 // |
329 // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") |
510 // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") |
330 // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") |
511 // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") |
360 h.Helper() |
541 h.Helper() |
361 } |
542 } |
362 return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...) |
543 return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...) |
363 } |
544 } |
364 |
545 |
|
546 // NotEqualValuesf asserts that two objects are not equal even when converted to the same type |
|
547 // |
|
548 // assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") |
|
549 func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
|
550 if h, ok := t.(tHelper); ok { |
|
551 h.Helper() |
|
552 } |
|
553 return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) |
|
554 } |
|
555 |
|
556 // NotErrorIsf asserts that at none of the errors in err's chain matches target. |
|
557 // This is a wrapper for errors.Is. |
|
558 func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool { |
|
559 if h, ok := t.(tHelper); ok { |
|
560 h.Helper() |
|
561 } |
|
562 return NotErrorIs(t, err, target, append([]interface{}{msg}, args...)...) |
|
563 } |
|
564 |
365 // NotNilf asserts that the specified object is not nil. |
565 // NotNilf asserts that the specified object is not nil. |
366 // |
566 // |
367 // assert.NotNilf(t, err, "error message %s", "formatted") |
567 // assert.NotNilf(t, err, "error message %s", "formatted") |
368 func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
568 func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
369 if h, ok := t.(tHelper); ok { |
569 if h, ok := t.(tHelper); ok { |
382 return NotPanics(t, f, append([]interface{}{msg}, args...)...) |
582 return NotPanics(t, f, append([]interface{}{msg}, args...)...) |
383 } |
583 } |
384 |
584 |
385 // NotRegexpf asserts that a specified regexp does not match a string. |
585 // NotRegexpf asserts that a specified regexp does not match a string. |
386 // |
586 // |
387 // assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting") |
587 // assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") |
388 // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") |
588 // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") |
389 func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { |
589 func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { |
390 if h, ok := t.(tHelper); ok { |
590 if h, ok := t.(tHelper); ok { |
391 h.Helper() |
591 h.Helper() |
392 } |
592 } |
393 return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...) |
593 return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...) |
394 } |
594 } |
395 |
595 |
|
596 // NotSamef asserts that two pointers do not reference the same object. |
|
597 // |
|
598 // assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted") |
|
599 // |
|
600 // Both arguments must be pointer variables. Pointer variable sameness is |
|
601 // determined based on the equality of both type and value. |
|
602 func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
|
603 if h, ok := t.(tHelper); ok { |
|
604 h.Helper() |
|
605 } |
|
606 return NotSame(t, expected, actual, append([]interface{}{msg}, args...)...) |
|
607 } |
|
608 |
396 // NotSubsetf asserts that the specified list(array, slice...) contains not all |
609 // NotSubsetf asserts that the specified list(array, slice...) contains not all |
397 // elements given in the specified subset(array, slice...). |
610 // elements given in the specified subset(array, slice...). |
398 // |
611 // |
399 // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") |
612 // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") |
400 func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { |
613 func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { |
420 h.Helper() |
633 h.Helper() |
421 } |
634 } |
422 return Panics(t, f, append([]interface{}{msg}, args...)...) |
635 return Panics(t, f, append([]interface{}{msg}, args...)...) |
423 } |
636 } |
424 |
637 |
|
638 // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc |
|
639 // panics, and that the recovered panic value is an error that satisfies the |
|
640 // EqualError comparison. |
|
641 // |
|
642 // assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") |
|
643 func PanicsWithErrorf(t TestingT, errString string, f PanicTestFunc, msg string, args ...interface{}) bool { |
|
644 if h, ok := t.(tHelper); ok { |
|
645 h.Helper() |
|
646 } |
|
647 return PanicsWithError(t, errString, f, append([]interface{}{msg}, args...)...) |
|
648 } |
|
649 |
425 // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that |
650 // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that |
426 // the recovered panic value equals the expected panic value. |
651 // the recovered panic value equals the expected panic value. |
427 // |
652 // |
428 // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") |
653 // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") |
429 func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool { |
654 func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool { |
431 h.Helper() |
656 h.Helper() |
432 } |
657 } |
433 return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...) |
658 return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...) |
434 } |
659 } |
435 |
660 |
|
661 // Positivef asserts that the specified element is positive |
|
662 // |
|
663 // assert.Positivef(t, 1, "error message %s", "formatted") |
|
664 // assert.Positivef(t, 1.23, "error message %s", "formatted") |
|
665 func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) bool { |
|
666 if h, ok := t.(tHelper); ok { |
|
667 h.Helper() |
|
668 } |
|
669 return Positive(t, e, append([]interface{}{msg}, args...)...) |
|
670 } |
|
671 |
436 // Regexpf asserts that a specified regexp matches a string. |
672 // Regexpf asserts that a specified regexp matches a string. |
437 // |
673 // |
438 // assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting") |
674 // assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") |
439 // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") |
675 // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") |
440 func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { |
676 func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { |
441 if h, ok := t.(tHelper); ok { |
677 if h, ok := t.(tHelper); ok { |
442 h.Helper() |
678 h.Helper() |
443 } |
679 } |
444 return Regexp(t, rx, str, append([]interface{}{msg}, args...)...) |
680 return Regexp(t, rx, str, append([]interface{}{msg}, args...)...) |
445 } |
681 } |
446 |
682 |
|
683 // Samef asserts that two pointers reference the same object. |
|
684 // |
|
685 // assert.Samef(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. |
|
689 func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
|
690 if h, ok := t.(tHelper); ok { |
|
691 h.Helper() |
|
692 } |
|
693 return Same(t, expected, actual, append([]interface{}{msg}, args...)...) |
|
694 } |
|
695 |
447 // Subsetf asserts that the specified list(array, slice...) contains all |
696 // Subsetf asserts that the specified list(array, slice...) contains all |
448 // elements given in the specified subset(array, slice...). |
697 // elements given in the specified subset(array, slice...). |
449 // |
698 // |
450 // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") |
699 // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") |
451 func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { |
700 func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { |
473 h.Helper() |
722 h.Helper() |
474 } |
723 } |
475 return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
724 return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
476 } |
725 } |
477 |
726 |
|
727 // YAMLEqf asserts that two YAML strings are equivalent. |
|
728 func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool { |
|
729 if h, ok := t.(tHelper); ok { |
|
730 h.Helper() |
|
731 } |
|
732 return YAMLEq(t, expected, actual, append([]interface{}{msg}, args...)...) |
|
733 } |
|
734 |
478 // Zerof asserts that i is the zero value for its type. |
735 // Zerof asserts that i is the zero value for its type. |
479 func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool { |
736 func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool { |
480 if h, ok := t.(tHelper); ok { |
737 if h, ok := t.(tHelper); ok { |
481 h.Helper() |
738 h.Helper() |
482 } |
739 } |