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