require.go (62044B)
1 /* 2 * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen 3 * THIS FILE MUST NOT BE EDITED BY HAND 4 */ 5 6 package require 7 8 import ( 9 assert "github.com/stretchr/testify/assert" 10 http "net/http" 11 url "net/url" 12 time "time" 13 ) 14 15 // Condition uses a Comparison to assert a complex condition. 16 func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { 17 if h, ok := t.(tHelper); ok { 18 h.Helper() 19 } 20 if assert.Condition(t, comp, msgAndArgs...) { 21 return 22 } 23 t.FailNow() 24 } 25 26 // Conditionf uses a Comparison to assert a complex condition. 27 func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) { 28 if h, ok := t.(tHelper); ok { 29 h.Helper() 30 } 31 if assert.Conditionf(t, comp, msg, args...) { 32 return 33 } 34 t.FailNow() 35 } 36 37 // Contains asserts that the specified string, list(array, slice...) or map contains the 38 // specified substring or element. 39 // 40 // assert.Contains(t, "Hello World", "World") 41 // assert.Contains(t, ["Hello", "World"], "World") 42 // assert.Contains(t, {"Hello": "World"}, "Hello") 43 func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { 44 if h, ok := t.(tHelper); ok { 45 h.Helper() 46 } 47 if assert.Contains(t, s, contains, msgAndArgs...) { 48 return 49 } 50 t.FailNow() 51 } 52 53 // Containsf asserts that the specified string, list(array, slice...) or map contains the 54 // specified substring or element. 55 // 56 // assert.Containsf(t, "Hello World", "World", "error message %s", "formatted") 57 // assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") 58 // assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") 59 func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { 60 if h, ok := t.(tHelper); ok { 61 h.Helper() 62 } 63 if assert.Containsf(t, s, contains, msg, args...) { 64 return 65 } 66 t.FailNow() 67 } 68 69 // DirExists checks whether a directory exists in the given path. It also fails 70 // if the path is a file rather a directory or there is an error checking whether it exists. 71 func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { 72 if h, ok := t.(tHelper); ok { 73 h.Helper() 74 } 75 if assert.DirExists(t, path, msgAndArgs...) { 76 return 77 } 78 t.FailNow() 79 } 80 81 // DirExistsf checks whether a directory exists in the given path. It also fails 82 // if the path is a file rather a directory or there is an error checking whether it exists. 83 func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { 84 if h, ok := t.(tHelper); ok { 85 h.Helper() 86 } 87 if assert.DirExistsf(t, path, msg, args...) { 88 return 89 } 90 t.FailNow() 91 } 92 93 // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified 94 // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 95 // the number of appearances of each of them in both lists should match. 96 // 97 // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) 98 func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { 99 if h, ok := t.(tHelper); ok { 100 h.Helper() 101 } 102 if assert.ElementsMatch(t, listA, listB, msgAndArgs...) { 103 return 104 } 105 t.FailNow() 106 } 107 108 // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified 109 // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 110 // the number of appearances of each of them in both lists should match. 111 // 112 // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") 113 func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { 114 if h, ok := t.(tHelper); ok { 115 h.Helper() 116 } 117 if assert.ElementsMatchf(t, listA, listB, msg, args...) { 118 return 119 } 120 t.FailNow() 121 } 122 123 // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either 124 // a slice or a channel with len == 0. 125 // 126 // assert.Empty(t, obj) 127 func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { 128 if h, ok := t.(tHelper); ok { 129 h.Helper() 130 } 131 if assert.Empty(t, object, msgAndArgs...) { 132 return 133 } 134 t.FailNow() 135 } 136 137 // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either 138 // a slice or a channel with len == 0. 139 // 140 // assert.Emptyf(t, obj, "error message %s", "formatted") 141 func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { 142 if h, ok := t.(tHelper); ok { 143 h.Helper() 144 } 145 if assert.Emptyf(t, object, msg, args...) { 146 return 147 } 148 t.FailNow() 149 } 150 151 // Equal asserts that two objects are equal. 152 // 153 // assert.Equal(t, 123, 123) 154 // 155 // Pointer variable equality is determined based on the equality of the 156 // referenced values (as opposed to the memory addresses). Function equality 157 // cannot be determined and will always fail. 158 func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 159 if h, ok := t.(tHelper); ok { 160 h.Helper() 161 } 162 if assert.Equal(t, expected, actual, msgAndArgs...) { 163 return 164 } 165 t.FailNow() 166 } 167 168 // EqualError asserts that a function returned an error (i.e. not `nil`) 169 // and that it is equal to the provided error. 170 // 171 // actualObj, err := SomeFunction() 172 // assert.EqualError(t, err, expectedErrorString) 173 func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { 174 if h, ok := t.(tHelper); ok { 175 h.Helper() 176 } 177 if assert.EqualError(t, theError, errString, msgAndArgs...) { 178 return 179 } 180 t.FailNow() 181 } 182 183 // EqualErrorf asserts that a function returned an error (i.e. not `nil`) 184 // and that it is equal to the provided error. 185 // 186 // actualObj, err := SomeFunction() 187 // assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") 188 func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { 189 if h, ok := t.(tHelper); ok { 190 h.Helper() 191 } 192 if assert.EqualErrorf(t, theError, errString, msg, args...) { 193 return 194 } 195 t.FailNow() 196 } 197 198 // EqualExportedValues asserts that the types of two objects are equal and their public 199 // fields are also equal. This is useful for comparing structs that have private fields 200 // that could potentially differ. 201 // 202 // type S struct { 203 // Exported int 204 // notExported int 205 // } 206 // assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true 207 // assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false 208 func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 209 if h, ok := t.(tHelper); ok { 210 h.Helper() 211 } 212 if assert.EqualExportedValues(t, expected, actual, msgAndArgs...) { 213 return 214 } 215 t.FailNow() 216 } 217 218 // EqualExportedValuesf asserts that the types of two objects are equal and their public 219 // fields are also equal. This is useful for comparing structs that have private fields 220 // that could potentially differ. 221 // 222 // type S struct { 223 // Exported int 224 // notExported int 225 // } 226 // assert.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true 227 // assert.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false 228 func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 229 if h, ok := t.(tHelper); ok { 230 h.Helper() 231 } 232 if assert.EqualExportedValuesf(t, expected, actual, msg, args...) { 233 return 234 } 235 t.FailNow() 236 } 237 238 // EqualValues asserts that two objects are equal or convertable to the same types 239 // and equal. 240 // 241 // assert.EqualValues(t, uint32(123), int32(123)) 242 func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 243 if h, ok := t.(tHelper); ok { 244 h.Helper() 245 } 246 if assert.EqualValues(t, expected, actual, msgAndArgs...) { 247 return 248 } 249 t.FailNow() 250 } 251 252 // EqualValuesf asserts that two objects are equal or convertable to the same types 253 // and equal. 254 // 255 // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") 256 func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 257 if h, ok := t.(tHelper); ok { 258 h.Helper() 259 } 260 if assert.EqualValuesf(t, expected, actual, msg, args...) { 261 return 262 } 263 t.FailNow() 264 } 265 266 // Equalf asserts that two objects are equal. 267 // 268 // assert.Equalf(t, 123, 123, "error message %s", "formatted") 269 // 270 // Pointer variable equality is determined based on the equality of the 271 // referenced values (as opposed to the memory addresses). Function equality 272 // cannot be determined and will always fail. 273 func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 274 if h, ok := t.(tHelper); ok { 275 h.Helper() 276 } 277 if assert.Equalf(t, expected, actual, msg, args...) { 278 return 279 } 280 t.FailNow() 281 } 282 283 // Error asserts that a function returned an error (i.e. not `nil`). 284 // 285 // actualObj, err := SomeFunction() 286 // if assert.Error(t, err) { 287 // assert.Equal(t, expectedError, err) 288 // } 289 func Error(t TestingT, err error, msgAndArgs ...interface{}) { 290 if h, ok := t.(tHelper); ok { 291 h.Helper() 292 } 293 if assert.Error(t, err, msgAndArgs...) { 294 return 295 } 296 t.FailNow() 297 } 298 299 // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. 300 // This is a wrapper for errors.As. 301 func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { 302 if h, ok := t.(tHelper); ok { 303 h.Helper() 304 } 305 if assert.ErrorAs(t, err, target, msgAndArgs...) { 306 return 307 } 308 t.FailNow() 309 } 310 311 // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. 312 // This is a wrapper for errors.As. 313 func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { 314 if h, ok := t.(tHelper); ok { 315 h.Helper() 316 } 317 if assert.ErrorAsf(t, err, target, msg, args...) { 318 return 319 } 320 t.FailNow() 321 } 322 323 // ErrorContains asserts that a function returned an error (i.e. not `nil`) 324 // and that the error contains the specified substring. 325 // 326 // actualObj, err := SomeFunction() 327 // assert.ErrorContains(t, err, expectedErrorSubString) 328 func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) { 329 if h, ok := t.(tHelper); ok { 330 h.Helper() 331 } 332 if assert.ErrorContains(t, theError, contains, msgAndArgs...) { 333 return 334 } 335 t.FailNow() 336 } 337 338 // ErrorContainsf asserts that a function returned an error (i.e. not `nil`) 339 // and that the error contains the specified substring. 340 // 341 // actualObj, err := SomeFunction() 342 // assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") 343 func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) { 344 if h, ok := t.(tHelper); ok { 345 h.Helper() 346 } 347 if assert.ErrorContainsf(t, theError, contains, msg, args...) { 348 return 349 } 350 t.FailNow() 351 } 352 353 // ErrorIs asserts that at least one of the errors in err's chain matches target. 354 // This is a wrapper for errors.Is. 355 func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { 356 if h, ok := t.(tHelper); ok { 357 h.Helper() 358 } 359 if assert.ErrorIs(t, err, target, msgAndArgs...) { 360 return 361 } 362 t.FailNow() 363 } 364 365 // ErrorIsf asserts that at least one of the errors in err's chain matches target. 366 // This is a wrapper for errors.Is. 367 func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { 368 if h, ok := t.(tHelper); ok { 369 h.Helper() 370 } 371 if assert.ErrorIsf(t, err, target, msg, args...) { 372 return 373 } 374 t.FailNow() 375 } 376 377 // Errorf asserts that a function returned an error (i.e. not `nil`). 378 // 379 // actualObj, err := SomeFunction() 380 // if assert.Errorf(t, err, "error message %s", "formatted") { 381 // assert.Equal(t, expectedErrorf, err) 382 // } 383 func Errorf(t TestingT, err error, msg string, args ...interface{}) { 384 if h, ok := t.(tHelper); ok { 385 h.Helper() 386 } 387 if assert.Errorf(t, err, msg, args...) { 388 return 389 } 390 t.FailNow() 391 } 392 393 // Eventually asserts that given condition will be met in waitFor time, 394 // periodically checking target function each tick. 395 // 396 // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) 397 func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { 398 if h, ok := t.(tHelper); ok { 399 h.Helper() 400 } 401 if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) { 402 return 403 } 404 t.FailNow() 405 } 406 407 // EventuallyWithT asserts that given condition will be met in waitFor time, 408 // periodically checking target function each tick. In contrast to Eventually, 409 // it supplies a CollectT to the condition function, so that the condition 410 // function can use the CollectT to call other assertions. 411 // The condition is considered "met" if no errors are raised in a tick. 412 // The supplied CollectT collects all errors from one tick (if there are any). 413 // If the condition is not met before waitFor, the collected errors of 414 // the last tick are copied to t. 415 // 416 // externalValue := false 417 // go func() { 418 // time.Sleep(8*time.Second) 419 // externalValue = true 420 // }() 421 // assert.EventuallyWithT(t, func(c *assert.CollectT) { 422 // // add assertions as needed; any assertion failure will fail the current tick 423 // assert.True(c, externalValue, "expected 'externalValue' to be true") 424 // }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") 425 func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { 426 if h, ok := t.(tHelper); ok { 427 h.Helper() 428 } 429 if assert.EventuallyWithT(t, condition, waitFor, tick, msgAndArgs...) { 430 return 431 } 432 t.FailNow() 433 } 434 435 // EventuallyWithTf asserts that given condition will be met in waitFor time, 436 // periodically checking target function each tick. In contrast to Eventually, 437 // it supplies a CollectT to the condition function, so that the condition 438 // function can use the CollectT to call other assertions. 439 // The condition is considered "met" if no errors are raised in a tick. 440 // The supplied CollectT collects all errors from one tick (if there are any). 441 // If the condition is not met before waitFor, the collected errors of 442 // the last tick are copied to t. 443 // 444 // externalValue := false 445 // go func() { 446 // time.Sleep(8*time.Second) 447 // externalValue = true 448 // }() 449 // assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") { 450 // // add assertions as needed; any assertion failure will fail the current tick 451 // assert.True(c, externalValue, "expected 'externalValue' to be true") 452 // }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") 453 func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { 454 if h, ok := t.(tHelper); ok { 455 h.Helper() 456 } 457 if assert.EventuallyWithTf(t, condition, waitFor, tick, msg, args...) { 458 return 459 } 460 t.FailNow() 461 } 462 463 // Eventuallyf asserts that given condition will be met in waitFor time, 464 // periodically checking target function each tick. 465 // 466 // assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") 467 func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { 468 if h, ok := t.(tHelper); ok { 469 h.Helper() 470 } 471 if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) { 472 return 473 } 474 t.FailNow() 475 } 476 477 // Exactly asserts that two objects are equal in value and type. 478 // 479 // assert.Exactly(t, int32(123), int64(123)) 480 func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 481 if h, ok := t.(tHelper); ok { 482 h.Helper() 483 } 484 if assert.Exactly(t, expected, actual, msgAndArgs...) { 485 return 486 } 487 t.FailNow() 488 } 489 490 // Exactlyf asserts that two objects are equal in value and type. 491 // 492 // assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") 493 func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 494 if h, ok := t.(tHelper); ok { 495 h.Helper() 496 } 497 if assert.Exactlyf(t, expected, actual, msg, args...) { 498 return 499 } 500 t.FailNow() 501 } 502 503 // Fail reports a failure through 504 func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { 505 if h, ok := t.(tHelper); ok { 506 h.Helper() 507 } 508 if assert.Fail(t, failureMessage, msgAndArgs...) { 509 return 510 } 511 t.FailNow() 512 } 513 514 // FailNow fails test 515 func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { 516 if h, ok := t.(tHelper); ok { 517 h.Helper() 518 } 519 if assert.FailNow(t, failureMessage, msgAndArgs...) { 520 return 521 } 522 t.FailNow() 523 } 524 525 // FailNowf fails test 526 func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) { 527 if h, ok := t.(tHelper); ok { 528 h.Helper() 529 } 530 if assert.FailNowf(t, failureMessage, msg, args...) { 531 return 532 } 533 t.FailNow() 534 } 535 536 // Failf reports a failure through 537 func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { 538 if h, ok := t.(tHelper); ok { 539 h.Helper() 540 } 541 if assert.Failf(t, failureMessage, msg, args...) { 542 return 543 } 544 t.FailNow() 545 } 546 547 // False asserts that the specified value is false. 548 // 549 // assert.False(t, myBool) 550 func False(t TestingT, value bool, msgAndArgs ...interface{}) { 551 if h, ok := t.(tHelper); ok { 552 h.Helper() 553 } 554 if assert.False(t, value, msgAndArgs...) { 555 return 556 } 557 t.FailNow() 558 } 559 560 // Falsef asserts that the specified value is false. 561 // 562 // assert.Falsef(t, myBool, "error message %s", "formatted") 563 func Falsef(t TestingT, value bool, msg string, args ...interface{}) { 564 if h, ok := t.(tHelper); ok { 565 h.Helper() 566 } 567 if assert.Falsef(t, value, msg, args...) { 568 return 569 } 570 t.FailNow() 571 } 572 573 // FileExists checks whether a file exists in the given path. It also fails if 574 // the path points to a directory or there is an error when trying to check the file. 575 func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { 576 if h, ok := t.(tHelper); ok { 577 h.Helper() 578 } 579 if assert.FileExists(t, path, msgAndArgs...) { 580 return 581 } 582 t.FailNow() 583 } 584 585 // FileExistsf checks whether a file exists in the given path. It also fails if 586 // the path points to a directory or there is an error when trying to check the file. 587 func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { 588 if h, ok := t.(tHelper); ok { 589 h.Helper() 590 } 591 if assert.FileExistsf(t, path, msg, args...) { 592 return 593 } 594 t.FailNow() 595 } 596 597 // Greater asserts that the first element is greater than the second 598 // 599 // assert.Greater(t, 2, 1) 600 // assert.Greater(t, float64(2), float64(1)) 601 // assert.Greater(t, "b", "a") 602 func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 603 if h, ok := t.(tHelper); ok { 604 h.Helper() 605 } 606 if assert.Greater(t, e1, e2, msgAndArgs...) { 607 return 608 } 609 t.FailNow() 610 } 611 612 // GreaterOrEqual asserts that the first element is greater than or equal to the second 613 // 614 // assert.GreaterOrEqual(t, 2, 1) 615 // assert.GreaterOrEqual(t, 2, 2) 616 // assert.GreaterOrEqual(t, "b", "a") 617 // assert.GreaterOrEqual(t, "b", "b") 618 func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 619 if h, ok := t.(tHelper); ok { 620 h.Helper() 621 } 622 if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) { 623 return 624 } 625 t.FailNow() 626 } 627 628 // GreaterOrEqualf asserts that the first element is greater than or equal to the second 629 // 630 // assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") 631 // assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") 632 // assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") 633 // assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") 634 func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 635 if h, ok := t.(tHelper); ok { 636 h.Helper() 637 } 638 if assert.GreaterOrEqualf(t, e1, e2, msg, args...) { 639 return 640 } 641 t.FailNow() 642 } 643 644 // Greaterf asserts that the first element is greater than the second 645 // 646 // assert.Greaterf(t, 2, 1, "error message %s", "formatted") 647 // assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") 648 // assert.Greaterf(t, "b", "a", "error message %s", "formatted") 649 func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 650 if h, ok := t.(tHelper); ok { 651 h.Helper() 652 } 653 if assert.Greaterf(t, e1, e2, msg, args...) { 654 return 655 } 656 t.FailNow() 657 } 658 659 // HTTPBodyContains asserts that a specified handler returns a 660 // body that contains a string. 661 // 662 // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 663 // 664 // Returns whether the assertion was successful (true) or not (false). 665 func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { 666 if h, ok := t.(tHelper); ok { 667 h.Helper() 668 } 669 if assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) { 670 return 671 } 672 t.FailNow() 673 } 674 675 // HTTPBodyContainsf asserts that a specified handler returns a 676 // body that contains a string. 677 // 678 // assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 679 // 680 // Returns whether the assertion was successful (true) or not (false). 681 func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { 682 if h, ok := t.(tHelper); ok { 683 h.Helper() 684 } 685 if assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) { 686 return 687 } 688 t.FailNow() 689 } 690 691 // HTTPBodyNotContains asserts that a specified handler returns a 692 // body that does not contain a string. 693 // 694 // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 695 // 696 // Returns whether the assertion was successful (true) or not (false). 697 func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { 698 if h, ok := t.(tHelper); ok { 699 h.Helper() 700 } 701 if assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) { 702 return 703 } 704 t.FailNow() 705 } 706 707 // HTTPBodyNotContainsf asserts that a specified handler returns a 708 // body that does not contain a string. 709 // 710 // assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 711 // 712 // Returns whether the assertion was successful (true) or not (false). 713 func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { 714 if h, ok := t.(tHelper); ok { 715 h.Helper() 716 } 717 if assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) { 718 return 719 } 720 t.FailNow() 721 } 722 723 // HTTPError asserts that a specified handler returns an error status code. 724 // 725 // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 726 // 727 // Returns whether the assertion was successful (true) or not (false). 728 func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 729 if h, ok := t.(tHelper); ok { 730 h.Helper() 731 } 732 if assert.HTTPError(t, handler, method, url, values, msgAndArgs...) { 733 return 734 } 735 t.FailNow() 736 } 737 738 // HTTPErrorf asserts that a specified handler returns an error status code. 739 // 740 // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 741 // 742 // Returns whether the assertion was successful (true) or not (false). 743 func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 744 if h, ok := t.(tHelper); ok { 745 h.Helper() 746 } 747 if assert.HTTPErrorf(t, handler, method, url, values, msg, args...) { 748 return 749 } 750 t.FailNow() 751 } 752 753 // HTTPRedirect asserts that a specified handler returns a redirect status code. 754 // 755 // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 756 // 757 // Returns whether the assertion was successful (true) or not (false). 758 func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 759 if h, ok := t.(tHelper); ok { 760 h.Helper() 761 } 762 if assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) { 763 return 764 } 765 t.FailNow() 766 } 767 768 // HTTPRedirectf asserts that a specified handler returns a redirect status code. 769 // 770 // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 771 // 772 // Returns whether the assertion was successful (true) or not (false). 773 func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 774 if h, ok := t.(tHelper); ok { 775 h.Helper() 776 } 777 if assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) { 778 return 779 } 780 t.FailNow() 781 } 782 783 // HTTPStatusCode asserts that a specified handler returns a specified status code. 784 // 785 // assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) 786 // 787 // Returns whether the assertion was successful (true) or not (false). 788 func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { 789 if h, ok := t.(tHelper); ok { 790 h.Helper() 791 } 792 if assert.HTTPStatusCode(t, handler, method, url, values, statuscode, msgAndArgs...) { 793 return 794 } 795 t.FailNow() 796 } 797 798 // HTTPStatusCodef asserts that a specified handler returns a specified status code. 799 // 800 // assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") 801 // 802 // Returns whether the assertion was successful (true) or not (false). 803 func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { 804 if h, ok := t.(tHelper); ok { 805 h.Helper() 806 } 807 if assert.HTTPStatusCodef(t, handler, method, url, values, statuscode, msg, args...) { 808 return 809 } 810 t.FailNow() 811 } 812 813 // HTTPSuccess asserts that a specified handler returns a success status code. 814 // 815 // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) 816 // 817 // Returns whether the assertion was successful (true) or not (false). 818 func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 819 if h, ok := t.(tHelper); ok { 820 h.Helper() 821 } 822 if assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) { 823 return 824 } 825 t.FailNow() 826 } 827 828 // HTTPSuccessf asserts that a specified handler returns a success status code. 829 // 830 // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") 831 // 832 // Returns whether the assertion was successful (true) or not (false). 833 func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 834 if h, ok := t.(tHelper); ok { 835 h.Helper() 836 } 837 if assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) { 838 return 839 } 840 t.FailNow() 841 } 842 843 // Implements asserts that an object is implemented by the specified interface. 844 // 845 // assert.Implements(t, (*MyInterface)(nil), new(MyObject)) 846 func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { 847 if h, ok := t.(tHelper); ok { 848 h.Helper() 849 } 850 if assert.Implements(t, interfaceObject, object, msgAndArgs...) { 851 return 852 } 853 t.FailNow() 854 } 855 856 // Implementsf asserts that an object is implemented by the specified interface. 857 // 858 // assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") 859 func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { 860 if h, ok := t.(tHelper); ok { 861 h.Helper() 862 } 863 if assert.Implementsf(t, interfaceObject, object, msg, args...) { 864 return 865 } 866 t.FailNow() 867 } 868 869 // InDelta asserts that the two numerals are within delta of each other. 870 // 871 // assert.InDelta(t, math.Pi, 22/7.0, 0.01) 872 func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 873 if h, ok := t.(tHelper); ok { 874 h.Helper() 875 } 876 if assert.InDelta(t, expected, actual, delta, msgAndArgs...) { 877 return 878 } 879 t.FailNow() 880 } 881 882 // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 883 func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 884 if h, ok := t.(tHelper); ok { 885 h.Helper() 886 } 887 if assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) { 888 return 889 } 890 t.FailNow() 891 } 892 893 // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 894 func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 895 if h, ok := t.(tHelper); ok { 896 h.Helper() 897 } 898 if assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) { 899 return 900 } 901 t.FailNow() 902 } 903 904 // InDeltaSlice is the same as InDelta, except it compares two slices. 905 func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 906 if h, ok := t.(tHelper); ok { 907 h.Helper() 908 } 909 if assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) { 910 return 911 } 912 t.FailNow() 913 } 914 915 // InDeltaSlicef is the same as InDelta, except it compares two slices. 916 func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 917 if h, ok := t.(tHelper); ok { 918 h.Helper() 919 } 920 if assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) { 921 return 922 } 923 t.FailNow() 924 } 925 926 // InDeltaf asserts that the two numerals are within delta of each other. 927 // 928 // assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") 929 func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 930 if h, ok := t.(tHelper); ok { 931 h.Helper() 932 } 933 if assert.InDeltaf(t, expected, actual, delta, msg, args...) { 934 return 935 } 936 t.FailNow() 937 } 938 939 // InEpsilon asserts that expected and actual have a relative error less than epsilon 940 func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { 941 if h, ok := t.(tHelper); ok { 942 h.Helper() 943 } 944 if assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) { 945 return 946 } 947 t.FailNow() 948 } 949 950 // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. 951 func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { 952 if h, ok := t.(tHelper); ok { 953 h.Helper() 954 } 955 if assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) { 956 return 957 } 958 t.FailNow() 959 } 960 961 // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. 962 func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { 963 if h, ok := t.(tHelper); ok { 964 h.Helper() 965 } 966 if assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) { 967 return 968 } 969 t.FailNow() 970 } 971 972 // InEpsilonf asserts that expected and actual have a relative error less than epsilon 973 func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { 974 if h, ok := t.(tHelper); ok { 975 h.Helper() 976 } 977 if assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) { 978 return 979 } 980 t.FailNow() 981 } 982 983 // IsDecreasing asserts that the collection is decreasing 984 // 985 // assert.IsDecreasing(t, []int{2, 1, 0}) 986 // assert.IsDecreasing(t, []float{2, 1}) 987 // assert.IsDecreasing(t, []string{"b", "a"}) 988 func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 989 if h, ok := t.(tHelper); ok { 990 h.Helper() 991 } 992 if assert.IsDecreasing(t, object, msgAndArgs...) { 993 return 994 } 995 t.FailNow() 996 } 997 998 // IsDecreasingf asserts that the collection is decreasing 999 // 1000 // assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") 1001 // assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") 1002 // assert.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") 1003 func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1004 if h, ok := t.(tHelper); ok { 1005 h.Helper() 1006 } 1007 if assert.IsDecreasingf(t, object, msg, args...) { 1008 return 1009 } 1010 t.FailNow() 1011 } 1012 1013 // IsIncreasing asserts that the collection is increasing 1014 // 1015 // assert.IsIncreasing(t, []int{1, 2, 3}) 1016 // assert.IsIncreasing(t, []float{1, 2}) 1017 // assert.IsIncreasing(t, []string{"a", "b"}) 1018 func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1019 if h, ok := t.(tHelper); ok { 1020 h.Helper() 1021 } 1022 if assert.IsIncreasing(t, object, msgAndArgs...) { 1023 return 1024 } 1025 t.FailNow() 1026 } 1027 1028 // IsIncreasingf asserts that the collection is increasing 1029 // 1030 // assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") 1031 // assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") 1032 // assert.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") 1033 func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1034 if h, ok := t.(tHelper); ok { 1035 h.Helper() 1036 } 1037 if assert.IsIncreasingf(t, object, msg, args...) { 1038 return 1039 } 1040 t.FailNow() 1041 } 1042 1043 // IsNonDecreasing asserts that the collection is not decreasing 1044 // 1045 // assert.IsNonDecreasing(t, []int{1, 1, 2}) 1046 // assert.IsNonDecreasing(t, []float{1, 2}) 1047 // assert.IsNonDecreasing(t, []string{"a", "b"}) 1048 func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1049 if h, ok := t.(tHelper); ok { 1050 h.Helper() 1051 } 1052 if assert.IsNonDecreasing(t, object, msgAndArgs...) { 1053 return 1054 } 1055 t.FailNow() 1056 } 1057 1058 // IsNonDecreasingf asserts that the collection is not decreasing 1059 // 1060 // assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") 1061 // assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") 1062 // assert.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") 1063 func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1064 if h, ok := t.(tHelper); ok { 1065 h.Helper() 1066 } 1067 if assert.IsNonDecreasingf(t, object, msg, args...) { 1068 return 1069 } 1070 t.FailNow() 1071 } 1072 1073 // IsNonIncreasing asserts that the collection is not increasing 1074 // 1075 // assert.IsNonIncreasing(t, []int{2, 1, 1}) 1076 // assert.IsNonIncreasing(t, []float{2, 1}) 1077 // assert.IsNonIncreasing(t, []string{"b", "a"}) 1078 func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1079 if h, ok := t.(tHelper); ok { 1080 h.Helper() 1081 } 1082 if assert.IsNonIncreasing(t, object, msgAndArgs...) { 1083 return 1084 } 1085 t.FailNow() 1086 } 1087 1088 // IsNonIncreasingf asserts that the collection is not increasing 1089 // 1090 // assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") 1091 // assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") 1092 // assert.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") 1093 func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1094 if h, ok := t.(tHelper); ok { 1095 h.Helper() 1096 } 1097 if assert.IsNonIncreasingf(t, object, msg, args...) { 1098 return 1099 } 1100 t.FailNow() 1101 } 1102 1103 // IsType asserts that the specified objects are of the same type. 1104 func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { 1105 if h, ok := t.(tHelper); ok { 1106 h.Helper() 1107 } 1108 if assert.IsType(t, expectedType, object, msgAndArgs...) { 1109 return 1110 } 1111 t.FailNow() 1112 } 1113 1114 // IsTypef asserts that the specified objects are of the same type. 1115 func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) { 1116 if h, ok := t.(tHelper); ok { 1117 h.Helper() 1118 } 1119 if assert.IsTypef(t, expectedType, object, msg, args...) { 1120 return 1121 } 1122 t.FailNow() 1123 } 1124 1125 // JSONEq asserts that two JSON strings are equivalent. 1126 // 1127 // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) 1128 func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { 1129 if h, ok := t.(tHelper); ok { 1130 h.Helper() 1131 } 1132 if assert.JSONEq(t, expected, actual, msgAndArgs...) { 1133 return 1134 } 1135 t.FailNow() 1136 } 1137 1138 // JSONEqf asserts that two JSON strings are equivalent. 1139 // 1140 // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") 1141 func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { 1142 if h, ok := t.(tHelper); ok { 1143 h.Helper() 1144 } 1145 if assert.JSONEqf(t, expected, actual, msg, args...) { 1146 return 1147 } 1148 t.FailNow() 1149 } 1150 1151 // Len asserts that the specified object has specific length. 1152 // Len also fails if the object has a type that len() not accept. 1153 // 1154 // assert.Len(t, mySlice, 3) 1155 func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { 1156 if h, ok := t.(tHelper); ok { 1157 h.Helper() 1158 } 1159 if assert.Len(t, object, length, msgAndArgs...) { 1160 return 1161 } 1162 t.FailNow() 1163 } 1164 1165 // Lenf asserts that the specified object has specific length. 1166 // Lenf also fails if the object has a type that len() not accept. 1167 // 1168 // assert.Lenf(t, mySlice, 3, "error message %s", "formatted") 1169 func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) { 1170 if h, ok := t.(tHelper); ok { 1171 h.Helper() 1172 } 1173 if assert.Lenf(t, object, length, msg, args...) { 1174 return 1175 } 1176 t.FailNow() 1177 } 1178 1179 // Less asserts that the first element is less than the second 1180 // 1181 // assert.Less(t, 1, 2) 1182 // assert.Less(t, float64(1), float64(2)) 1183 // assert.Less(t, "a", "b") 1184 func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 1185 if h, ok := t.(tHelper); ok { 1186 h.Helper() 1187 } 1188 if assert.Less(t, e1, e2, msgAndArgs...) { 1189 return 1190 } 1191 t.FailNow() 1192 } 1193 1194 // LessOrEqual asserts that the first element is less than or equal to the second 1195 // 1196 // assert.LessOrEqual(t, 1, 2) 1197 // assert.LessOrEqual(t, 2, 2) 1198 // assert.LessOrEqual(t, "a", "b") 1199 // assert.LessOrEqual(t, "b", "b") 1200 func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 1201 if h, ok := t.(tHelper); ok { 1202 h.Helper() 1203 } 1204 if assert.LessOrEqual(t, e1, e2, msgAndArgs...) { 1205 return 1206 } 1207 t.FailNow() 1208 } 1209 1210 // LessOrEqualf asserts that the first element is less than or equal to the second 1211 // 1212 // assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") 1213 // assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") 1214 // assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") 1215 // assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") 1216 func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 1217 if h, ok := t.(tHelper); ok { 1218 h.Helper() 1219 } 1220 if assert.LessOrEqualf(t, e1, e2, msg, args...) { 1221 return 1222 } 1223 t.FailNow() 1224 } 1225 1226 // Lessf asserts that the first element is less than the second 1227 // 1228 // assert.Lessf(t, 1, 2, "error message %s", "formatted") 1229 // assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") 1230 // assert.Lessf(t, "a", "b", "error message %s", "formatted") 1231 func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 1232 if h, ok := t.(tHelper); ok { 1233 h.Helper() 1234 } 1235 if assert.Lessf(t, e1, e2, msg, args...) { 1236 return 1237 } 1238 t.FailNow() 1239 } 1240 1241 // Negative asserts that the specified element is negative 1242 // 1243 // assert.Negative(t, -1) 1244 // assert.Negative(t, -1.23) 1245 func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { 1246 if h, ok := t.(tHelper); ok { 1247 h.Helper() 1248 } 1249 if assert.Negative(t, e, msgAndArgs...) { 1250 return 1251 } 1252 t.FailNow() 1253 } 1254 1255 // Negativef asserts that the specified element is negative 1256 // 1257 // assert.Negativef(t, -1, "error message %s", "formatted") 1258 // assert.Negativef(t, -1.23, "error message %s", "formatted") 1259 func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { 1260 if h, ok := t.(tHelper); ok { 1261 h.Helper() 1262 } 1263 if assert.Negativef(t, e, msg, args...) { 1264 return 1265 } 1266 t.FailNow() 1267 } 1268 1269 // Never asserts that the given condition doesn't satisfy in waitFor time, 1270 // periodically checking the target function each tick. 1271 // 1272 // assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) 1273 func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { 1274 if h, ok := t.(tHelper); ok { 1275 h.Helper() 1276 } 1277 if assert.Never(t, condition, waitFor, tick, msgAndArgs...) { 1278 return 1279 } 1280 t.FailNow() 1281 } 1282 1283 // Neverf asserts that the given condition doesn't satisfy in waitFor time, 1284 // periodically checking the target function each tick. 1285 // 1286 // assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") 1287 func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { 1288 if h, ok := t.(tHelper); ok { 1289 h.Helper() 1290 } 1291 if assert.Neverf(t, condition, waitFor, tick, msg, args...) { 1292 return 1293 } 1294 t.FailNow() 1295 } 1296 1297 // Nil asserts that the specified object is nil. 1298 // 1299 // assert.Nil(t, err) 1300 func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1301 if h, ok := t.(tHelper); ok { 1302 h.Helper() 1303 } 1304 if assert.Nil(t, object, msgAndArgs...) { 1305 return 1306 } 1307 t.FailNow() 1308 } 1309 1310 // Nilf asserts that the specified object is nil. 1311 // 1312 // assert.Nilf(t, err, "error message %s", "formatted") 1313 func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { 1314 if h, ok := t.(tHelper); ok { 1315 h.Helper() 1316 } 1317 if assert.Nilf(t, object, msg, args...) { 1318 return 1319 } 1320 t.FailNow() 1321 } 1322 1323 // NoDirExists checks whether a directory does not exist in the given path. 1324 // It fails if the path points to an existing _directory_ only. 1325 func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { 1326 if h, ok := t.(tHelper); ok { 1327 h.Helper() 1328 } 1329 if assert.NoDirExists(t, path, msgAndArgs...) { 1330 return 1331 } 1332 t.FailNow() 1333 } 1334 1335 // NoDirExistsf checks whether a directory does not exist in the given path. 1336 // It fails if the path points to an existing _directory_ only. 1337 func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { 1338 if h, ok := t.(tHelper); ok { 1339 h.Helper() 1340 } 1341 if assert.NoDirExistsf(t, path, msg, args...) { 1342 return 1343 } 1344 t.FailNow() 1345 } 1346 1347 // NoError asserts that a function returned no error (i.e. `nil`). 1348 // 1349 // actualObj, err := SomeFunction() 1350 // if assert.NoError(t, err) { 1351 // assert.Equal(t, expectedObj, actualObj) 1352 // } 1353 func NoError(t TestingT, err error, msgAndArgs ...interface{}) { 1354 if h, ok := t.(tHelper); ok { 1355 h.Helper() 1356 } 1357 if assert.NoError(t, err, msgAndArgs...) { 1358 return 1359 } 1360 t.FailNow() 1361 } 1362 1363 // NoErrorf asserts that a function returned no error (i.e. `nil`). 1364 // 1365 // actualObj, err := SomeFunction() 1366 // if assert.NoErrorf(t, err, "error message %s", "formatted") { 1367 // assert.Equal(t, expectedObj, actualObj) 1368 // } 1369 func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { 1370 if h, ok := t.(tHelper); ok { 1371 h.Helper() 1372 } 1373 if assert.NoErrorf(t, err, msg, args...) { 1374 return 1375 } 1376 t.FailNow() 1377 } 1378 1379 // NoFileExists checks whether a file does not exist in a given path. It fails 1380 // if the path points to an existing _file_ only. 1381 func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { 1382 if h, ok := t.(tHelper); ok { 1383 h.Helper() 1384 } 1385 if assert.NoFileExists(t, path, msgAndArgs...) { 1386 return 1387 } 1388 t.FailNow() 1389 } 1390 1391 // NoFileExistsf checks whether a file does not exist in a given path. It fails 1392 // if the path points to an existing _file_ only. 1393 func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { 1394 if h, ok := t.(tHelper); ok { 1395 h.Helper() 1396 } 1397 if assert.NoFileExistsf(t, path, msg, args...) { 1398 return 1399 } 1400 t.FailNow() 1401 } 1402 1403 // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the 1404 // specified substring or element. 1405 // 1406 // assert.NotContains(t, "Hello World", "Earth") 1407 // assert.NotContains(t, ["Hello", "World"], "Earth") 1408 // assert.NotContains(t, {"Hello": "World"}, "Earth") 1409 func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { 1410 if h, ok := t.(tHelper); ok { 1411 h.Helper() 1412 } 1413 if assert.NotContains(t, s, contains, msgAndArgs...) { 1414 return 1415 } 1416 t.FailNow() 1417 } 1418 1419 // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the 1420 // specified substring or element. 1421 // 1422 // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") 1423 // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") 1424 // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") 1425 func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { 1426 if h, ok := t.(tHelper); ok { 1427 h.Helper() 1428 } 1429 if assert.NotContainsf(t, s, contains, msg, args...) { 1430 return 1431 } 1432 t.FailNow() 1433 } 1434 1435 // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 1436 // a slice or a channel with len == 0. 1437 // 1438 // if assert.NotEmpty(t, obj) { 1439 // assert.Equal(t, "two", obj[1]) 1440 // } 1441 func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1442 if h, ok := t.(tHelper); ok { 1443 h.Helper() 1444 } 1445 if assert.NotEmpty(t, object, msgAndArgs...) { 1446 return 1447 } 1448 t.FailNow() 1449 } 1450 1451 // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 1452 // a slice or a channel with len == 0. 1453 // 1454 // if assert.NotEmptyf(t, obj, "error message %s", "formatted") { 1455 // assert.Equal(t, "two", obj[1]) 1456 // } 1457 func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { 1458 if h, ok := t.(tHelper); ok { 1459 h.Helper() 1460 } 1461 if assert.NotEmptyf(t, object, msg, args...) { 1462 return 1463 } 1464 t.FailNow() 1465 } 1466 1467 // NotEqual asserts that the specified values are NOT equal. 1468 // 1469 // assert.NotEqual(t, obj1, obj2) 1470 // 1471 // Pointer variable equality is determined based on the equality of the 1472 // referenced values (as opposed to the memory addresses). 1473 func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1474 if h, ok := t.(tHelper); ok { 1475 h.Helper() 1476 } 1477 if assert.NotEqual(t, expected, actual, msgAndArgs...) { 1478 return 1479 } 1480 t.FailNow() 1481 } 1482 1483 // NotEqualValues asserts that two objects are not equal even when converted to the same type 1484 // 1485 // assert.NotEqualValues(t, obj1, obj2) 1486 func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1487 if h, ok := t.(tHelper); ok { 1488 h.Helper() 1489 } 1490 if assert.NotEqualValues(t, expected, actual, msgAndArgs...) { 1491 return 1492 } 1493 t.FailNow() 1494 } 1495 1496 // NotEqualValuesf asserts that two objects are not equal even when converted to the same type 1497 // 1498 // assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") 1499 func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1500 if h, ok := t.(tHelper); ok { 1501 h.Helper() 1502 } 1503 if assert.NotEqualValuesf(t, expected, actual, msg, args...) { 1504 return 1505 } 1506 t.FailNow() 1507 } 1508 1509 // NotEqualf asserts that the specified values are NOT equal. 1510 // 1511 // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted") 1512 // 1513 // Pointer variable equality is determined based on the equality of the 1514 // referenced values (as opposed to the memory addresses). 1515 func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1516 if h, ok := t.(tHelper); ok { 1517 h.Helper() 1518 } 1519 if assert.NotEqualf(t, expected, actual, msg, args...) { 1520 return 1521 } 1522 t.FailNow() 1523 } 1524 1525 // NotErrorIs asserts that at none of the errors in err's chain matches target. 1526 // This is a wrapper for errors.Is. 1527 func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { 1528 if h, ok := t.(tHelper); ok { 1529 h.Helper() 1530 } 1531 if assert.NotErrorIs(t, err, target, msgAndArgs...) { 1532 return 1533 } 1534 t.FailNow() 1535 } 1536 1537 // NotErrorIsf asserts that at none of the errors in err's chain matches target. 1538 // This is a wrapper for errors.Is. 1539 func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { 1540 if h, ok := t.(tHelper); ok { 1541 h.Helper() 1542 } 1543 if assert.NotErrorIsf(t, err, target, msg, args...) { 1544 return 1545 } 1546 t.FailNow() 1547 } 1548 1549 // NotNil asserts that the specified object is not nil. 1550 // 1551 // assert.NotNil(t, err) 1552 func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1553 if h, ok := t.(tHelper); ok { 1554 h.Helper() 1555 } 1556 if assert.NotNil(t, object, msgAndArgs...) { 1557 return 1558 } 1559 t.FailNow() 1560 } 1561 1562 // NotNilf asserts that the specified object is not nil. 1563 // 1564 // assert.NotNilf(t, err, "error message %s", "formatted") 1565 func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { 1566 if h, ok := t.(tHelper); ok { 1567 h.Helper() 1568 } 1569 if assert.NotNilf(t, object, msg, args...) { 1570 return 1571 } 1572 t.FailNow() 1573 } 1574 1575 // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. 1576 // 1577 // assert.NotPanics(t, func(){ RemainCalm() }) 1578 func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1579 if h, ok := t.(tHelper); ok { 1580 h.Helper() 1581 } 1582 if assert.NotPanics(t, f, msgAndArgs...) { 1583 return 1584 } 1585 t.FailNow() 1586 } 1587 1588 // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. 1589 // 1590 // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") 1591 func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { 1592 if h, ok := t.(tHelper); ok { 1593 h.Helper() 1594 } 1595 if assert.NotPanicsf(t, f, msg, args...) { 1596 return 1597 } 1598 t.FailNow() 1599 } 1600 1601 // NotRegexp asserts that a specified regexp does not match a string. 1602 // 1603 // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") 1604 // assert.NotRegexp(t, "^start", "it's not starting") 1605 func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { 1606 if h, ok := t.(tHelper); ok { 1607 h.Helper() 1608 } 1609 if assert.NotRegexp(t, rx, str, msgAndArgs...) { 1610 return 1611 } 1612 t.FailNow() 1613 } 1614 1615 // NotRegexpf asserts that a specified regexp does not match a string. 1616 // 1617 // assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") 1618 // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") 1619 func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { 1620 if h, ok := t.(tHelper); ok { 1621 h.Helper() 1622 } 1623 if assert.NotRegexpf(t, rx, str, msg, args...) { 1624 return 1625 } 1626 t.FailNow() 1627 } 1628 1629 // NotSame asserts that two pointers do not reference the same object. 1630 // 1631 // assert.NotSame(t, ptr1, ptr2) 1632 // 1633 // Both arguments must be pointer variables. Pointer variable sameness is 1634 // determined based on the equality of both type and value. 1635 func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1636 if h, ok := t.(tHelper); ok { 1637 h.Helper() 1638 } 1639 if assert.NotSame(t, expected, actual, msgAndArgs...) { 1640 return 1641 } 1642 t.FailNow() 1643 } 1644 1645 // NotSamef asserts that two pointers do not reference the same object. 1646 // 1647 // assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted") 1648 // 1649 // Both arguments must be pointer variables. Pointer variable sameness is 1650 // determined based on the equality of both type and value. 1651 func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1652 if h, ok := t.(tHelper); ok { 1653 h.Helper() 1654 } 1655 if assert.NotSamef(t, expected, actual, msg, args...) { 1656 return 1657 } 1658 t.FailNow() 1659 } 1660 1661 // NotSubset asserts that the specified list(array, slice...) contains not all 1662 // elements given in the specified subset(array, slice...). 1663 // 1664 // assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") 1665 func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { 1666 if h, ok := t.(tHelper); ok { 1667 h.Helper() 1668 } 1669 if assert.NotSubset(t, list, subset, msgAndArgs...) { 1670 return 1671 } 1672 t.FailNow() 1673 } 1674 1675 // NotSubsetf asserts that the specified list(array, slice...) contains not all 1676 // elements given in the specified subset(array, slice...). 1677 // 1678 // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") 1679 func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { 1680 if h, ok := t.(tHelper); ok { 1681 h.Helper() 1682 } 1683 if assert.NotSubsetf(t, list, subset, msg, args...) { 1684 return 1685 } 1686 t.FailNow() 1687 } 1688 1689 // NotZero asserts that i is not the zero value for its type. 1690 func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { 1691 if h, ok := t.(tHelper); ok { 1692 h.Helper() 1693 } 1694 if assert.NotZero(t, i, msgAndArgs...) { 1695 return 1696 } 1697 t.FailNow() 1698 } 1699 1700 // NotZerof asserts that i is not the zero value for its type. 1701 func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { 1702 if h, ok := t.(tHelper); ok { 1703 h.Helper() 1704 } 1705 if assert.NotZerof(t, i, msg, args...) { 1706 return 1707 } 1708 t.FailNow() 1709 } 1710 1711 // Panics asserts that the code inside the specified PanicTestFunc panics. 1712 // 1713 // assert.Panics(t, func(){ GoCrazy() }) 1714 func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1715 if h, ok := t.(tHelper); ok { 1716 h.Helper() 1717 } 1718 if assert.Panics(t, f, msgAndArgs...) { 1719 return 1720 } 1721 t.FailNow() 1722 } 1723 1724 // PanicsWithError asserts that the code inside the specified PanicTestFunc 1725 // panics, and that the recovered panic value is an error that satisfies the 1726 // EqualError comparison. 1727 // 1728 // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) 1729 func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1730 if h, ok := t.(tHelper); ok { 1731 h.Helper() 1732 } 1733 if assert.PanicsWithError(t, errString, f, msgAndArgs...) { 1734 return 1735 } 1736 t.FailNow() 1737 } 1738 1739 // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc 1740 // panics, and that the recovered panic value is an error that satisfies the 1741 // EqualError comparison. 1742 // 1743 // assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") 1744 func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) { 1745 if h, ok := t.(tHelper); ok { 1746 h.Helper() 1747 } 1748 if assert.PanicsWithErrorf(t, errString, f, msg, args...) { 1749 return 1750 } 1751 t.FailNow() 1752 } 1753 1754 // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that 1755 // the recovered panic value equals the expected panic value. 1756 // 1757 // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) 1758 func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1759 if h, ok := t.(tHelper); ok { 1760 h.Helper() 1761 } 1762 if assert.PanicsWithValue(t, expected, f, msgAndArgs...) { 1763 return 1764 } 1765 t.FailNow() 1766 } 1767 1768 // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that 1769 // the recovered panic value equals the expected panic value. 1770 // 1771 // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") 1772 func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { 1773 if h, ok := t.(tHelper); ok { 1774 h.Helper() 1775 } 1776 if assert.PanicsWithValuef(t, expected, f, msg, args...) { 1777 return 1778 } 1779 t.FailNow() 1780 } 1781 1782 // Panicsf asserts that the code inside the specified PanicTestFunc panics. 1783 // 1784 // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") 1785 func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { 1786 if h, ok := t.(tHelper); ok { 1787 h.Helper() 1788 } 1789 if assert.Panicsf(t, f, msg, args...) { 1790 return 1791 } 1792 t.FailNow() 1793 } 1794 1795 // Positive asserts that the specified element is positive 1796 // 1797 // assert.Positive(t, 1) 1798 // assert.Positive(t, 1.23) 1799 func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { 1800 if h, ok := t.(tHelper); ok { 1801 h.Helper() 1802 } 1803 if assert.Positive(t, e, msgAndArgs...) { 1804 return 1805 } 1806 t.FailNow() 1807 } 1808 1809 // Positivef asserts that the specified element is positive 1810 // 1811 // assert.Positivef(t, 1, "error message %s", "formatted") 1812 // assert.Positivef(t, 1.23, "error message %s", "formatted") 1813 func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { 1814 if h, ok := t.(tHelper); ok { 1815 h.Helper() 1816 } 1817 if assert.Positivef(t, e, msg, args...) { 1818 return 1819 } 1820 t.FailNow() 1821 } 1822 1823 // Regexp asserts that a specified regexp matches a string. 1824 // 1825 // assert.Regexp(t, regexp.MustCompile("start"), "it's starting") 1826 // assert.Regexp(t, "start...$", "it's not starting") 1827 func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { 1828 if h, ok := t.(tHelper); ok { 1829 h.Helper() 1830 } 1831 if assert.Regexp(t, rx, str, msgAndArgs...) { 1832 return 1833 } 1834 t.FailNow() 1835 } 1836 1837 // Regexpf asserts that a specified regexp matches a string. 1838 // 1839 // assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") 1840 // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") 1841 func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { 1842 if h, ok := t.(tHelper); ok { 1843 h.Helper() 1844 } 1845 if assert.Regexpf(t, rx, str, msg, args...) { 1846 return 1847 } 1848 t.FailNow() 1849 } 1850 1851 // Same asserts that two pointers reference the same object. 1852 // 1853 // assert.Same(t, ptr1, ptr2) 1854 // 1855 // Both arguments must be pointer variables. Pointer variable sameness is 1856 // determined based on the equality of both type and value. 1857 func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1858 if h, ok := t.(tHelper); ok { 1859 h.Helper() 1860 } 1861 if assert.Same(t, expected, actual, msgAndArgs...) { 1862 return 1863 } 1864 t.FailNow() 1865 } 1866 1867 // Samef asserts that two pointers reference the same object. 1868 // 1869 // assert.Samef(t, ptr1, ptr2, "error message %s", "formatted") 1870 // 1871 // Both arguments must be pointer variables. Pointer variable sameness is 1872 // determined based on the equality of both type and value. 1873 func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1874 if h, ok := t.(tHelper); ok { 1875 h.Helper() 1876 } 1877 if assert.Samef(t, expected, actual, msg, args...) { 1878 return 1879 } 1880 t.FailNow() 1881 } 1882 1883 // Subset asserts that the specified list(array, slice...) contains all 1884 // elements given in the specified subset(array, slice...). 1885 // 1886 // assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") 1887 func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { 1888 if h, ok := t.(tHelper); ok { 1889 h.Helper() 1890 } 1891 if assert.Subset(t, list, subset, msgAndArgs...) { 1892 return 1893 } 1894 t.FailNow() 1895 } 1896 1897 // Subsetf asserts that the specified list(array, slice...) contains all 1898 // elements given in the specified subset(array, slice...). 1899 // 1900 // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") 1901 func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { 1902 if h, ok := t.(tHelper); ok { 1903 h.Helper() 1904 } 1905 if assert.Subsetf(t, list, subset, msg, args...) { 1906 return 1907 } 1908 t.FailNow() 1909 } 1910 1911 // True asserts that the specified value is true. 1912 // 1913 // assert.True(t, myBool) 1914 func True(t TestingT, value bool, msgAndArgs ...interface{}) { 1915 if h, ok := t.(tHelper); ok { 1916 h.Helper() 1917 } 1918 if assert.True(t, value, msgAndArgs...) { 1919 return 1920 } 1921 t.FailNow() 1922 } 1923 1924 // Truef asserts that the specified value is true. 1925 // 1926 // assert.Truef(t, myBool, "error message %s", "formatted") 1927 func Truef(t TestingT, value bool, msg string, args ...interface{}) { 1928 if h, ok := t.(tHelper); ok { 1929 h.Helper() 1930 } 1931 if assert.Truef(t, value, msg, args...) { 1932 return 1933 } 1934 t.FailNow() 1935 } 1936 1937 // WithinDuration asserts that the two times are within duration delta of each other. 1938 // 1939 // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) 1940 func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { 1941 if h, ok := t.(tHelper); ok { 1942 h.Helper() 1943 } 1944 if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) { 1945 return 1946 } 1947 t.FailNow() 1948 } 1949 1950 // WithinDurationf asserts that the two times are within duration delta of each other. 1951 // 1952 // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") 1953 func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { 1954 if h, ok := t.(tHelper); ok { 1955 h.Helper() 1956 } 1957 if assert.WithinDurationf(t, expected, actual, delta, msg, args...) { 1958 return 1959 } 1960 t.FailNow() 1961 } 1962 1963 // WithinRange asserts that a time is within a time range (inclusive). 1964 // 1965 // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) 1966 func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) { 1967 if h, ok := t.(tHelper); ok { 1968 h.Helper() 1969 } 1970 if assert.WithinRange(t, actual, start, end, msgAndArgs...) { 1971 return 1972 } 1973 t.FailNow() 1974 } 1975 1976 // WithinRangef asserts that a time is within a time range (inclusive). 1977 // 1978 // assert.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted") 1979 func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) { 1980 if h, ok := t.(tHelper); ok { 1981 h.Helper() 1982 } 1983 if assert.WithinRangef(t, actual, start, end, msg, args...) { 1984 return 1985 } 1986 t.FailNow() 1987 } 1988 1989 // YAMLEq asserts that two YAML strings are equivalent. 1990 func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { 1991 if h, ok := t.(tHelper); ok { 1992 h.Helper() 1993 } 1994 if assert.YAMLEq(t, expected, actual, msgAndArgs...) { 1995 return 1996 } 1997 t.FailNow() 1998 } 1999 2000 // YAMLEqf asserts that two YAML strings are equivalent. 2001 func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { 2002 if h, ok := t.(tHelper); ok { 2003 h.Helper() 2004 } 2005 if assert.YAMLEqf(t, expected, actual, msg, args...) { 2006 return 2007 } 2008 t.FailNow() 2009 } 2010 2011 // Zero asserts that i is the zero value for its type. 2012 func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { 2013 if h, ok := t.(tHelper); ok { 2014 h.Helper() 2015 } 2016 if assert.Zero(t, i, msgAndArgs...) { 2017 return 2018 } 2019 t.FailNow() 2020 } 2021 2022 // Zerof asserts that i is the zero value for its type. 2023 func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { 2024 if h, ok := t.(tHelper); ok { 2025 h.Helper() 2026 } 2027 if assert.Zerof(t, i, msg, args...) { 2028 return 2029 } 2030 t.FailNow() 2031 }