Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 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 | // EqualValuesf asserts that two objects are equal or convertable to the same types |
| 94 | // and equal. |
| 95 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 96 | // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 97 | func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
| 98 | if h, ok := t.(tHelper); ok { |
| 99 | h.Helper() |
| 100 | } |
| 101 | return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 102 | } |
| 103 | |
| 104 | // Errorf asserts that a function returned an error (i.e. not `nil`). |
| 105 | // |
| 106 | // actualObj, err := SomeFunction() |
| 107 | // if assert.Errorf(t, err, "error message %s", "formatted") { |
| 108 | // assert.Equal(t, expectedErrorf, err) |
| 109 | // } |
| 110 | func Errorf(t TestingT, err error, msg string, args ...interface{}) bool { |
| 111 | if h, ok := t.(tHelper); ok { |
| 112 | h.Helper() |
| 113 | } |
| 114 | return Error(t, err, append([]interface{}{msg}, args...)...) |
| 115 | } |
| 116 | |
| 117 | // Eventuallyf asserts that given condition will be met in waitFor time, |
| 118 | // periodically checking target function each tick. |
| 119 | // |
| 120 | // assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") |
| 121 | func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { |
| 122 | if h, ok := t.(tHelper); ok { |
| 123 | h.Helper() |
| 124 | } |
| 125 | return Eventually(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...) |
| 126 | } |
| 127 | |
| 128 | // Exactlyf asserts that two objects are equal in value and type. |
| 129 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 130 | // assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 131 | func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
| 132 | if h, ok := t.(tHelper); ok { |
| 133 | h.Helper() |
| 134 | } |
| 135 | return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 136 | } |
| 137 | |
| 138 | // Failf reports a failure through |
| 139 | func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool { |
| 140 | if h, ok := t.(tHelper); ok { |
| 141 | h.Helper() |
| 142 | } |
| 143 | return Fail(t, failureMessage, append([]interface{}{msg}, args...)...) |
| 144 | } |
| 145 | |
| 146 | // FailNowf fails test |
| 147 | func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool { |
| 148 | if h, ok := t.(tHelper); ok { |
| 149 | h.Helper() |
| 150 | } |
| 151 | return FailNow(t, failureMessage, append([]interface{}{msg}, args...)...) |
| 152 | } |
| 153 | |
| 154 | // Falsef asserts that the specified value is false. |
| 155 | // |
| 156 | // assert.Falsef(t, myBool, "error message %s", "formatted") |
| 157 | func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool { |
| 158 | if h, ok := t.(tHelper); ok { |
| 159 | h.Helper() |
| 160 | } |
| 161 | return False(t, value, append([]interface{}{msg}, args...)...) |
| 162 | } |
| 163 | |
| 164 | // FileExistsf checks whether a file exists in the given path. It also fails if |
| 165 | // the path points to a directory or there is an error when trying to check the file. |
| 166 | func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
| 167 | if h, ok := t.(tHelper); ok { |
| 168 | h.Helper() |
| 169 | } |
| 170 | return FileExists(t, path, append([]interface{}{msg}, args...)...) |
| 171 | } |
| 172 | |
| 173 | // Greaterf asserts that the first element is greater than the second |
| 174 | // |
| 175 | // assert.Greaterf(t, 2, 1, "error message %s", "formatted") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 176 | // assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 177 | // assert.Greaterf(t, "b", "a", "error message %s", "formatted") |
| 178 | func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
| 179 | if h, ok := t.(tHelper); ok { |
| 180 | h.Helper() |
| 181 | } |
| 182 | return Greater(t, e1, e2, append([]interface{}{msg}, args...)...) |
| 183 | } |
| 184 | |
| 185 | // GreaterOrEqualf asserts that the first element is greater than or equal to the second |
| 186 | // |
| 187 | // assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") |
| 188 | // assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") |
| 189 | // assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") |
| 190 | // assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") |
| 191 | func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
| 192 | if h, ok := t.(tHelper); ok { |
| 193 | h.Helper() |
| 194 | } |
| 195 | return GreaterOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...) |
| 196 | } |
| 197 | |
| 198 | // HTTPBodyContainsf asserts that a specified handler returns a |
| 199 | // body that contains a string. |
| 200 | // |
| 201 | // assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") |
| 202 | // |
| 203 | // Returns whether the assertion was successful (true) or not (false). |
| 204 | func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { |
| 205 | if h, ok := t.(tHelper); ok { |
| 206 | h.Helper() |
| 207 | } |
| 208 | return HTTPBodyContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...) |
| 209 | } |
| 210 | |
| 211 | // HTTPBodyNotContainsf asserts that a specified handler returns a |
| 212 | // body that does not contain a string. |
| 213 | // |
| 214 | // assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") |
| 215 | // |
| 216 | // Returns whether the assertion was successful (true) or not (false). |
| 217 | func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { |
| 218 | if h, ok := t.(tHelper); ok { |
| 219 | h.Helper() |
| 220 | } |
| 221 | return HTTPBodyNotContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...) |
| 222 | } |
| 223 | |
| 224 | // HTTPErrorf asserts that a specified handler returns an error status code. |
| 225 | // |
| 226 | // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} |
| 227 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 228 | // Returns whether the assertion was successful (true) or not (false). |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 229 | func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
| 230 | if h, ok := t.(tHelper); ok { |
| 231 | h.Helper() |
| 232 | } |
| 233 | return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
| 234 | } |
| 235 | |
| 236 | // HTTPRedirectf asserts that a specified handler returns a redirect status code. |
| 237 | // |
| 238 | // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} |
| 239 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 240 | // Returns whether the assertion was successful (true) or not (false). |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 241 | func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
| 242 | if h, ok := t.(tHelper); ok { |
| 243 | h.Helper() |
| 244 | } |
| 245 | return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
| 246 | } |
| 247 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 248 | // HTTPStatusCodef asserts that a specified handler returns a specified status code. |
| 249 | // |
| 250 | // assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") |
| 251 | // |
| 252 | // Returns whether the assertion was successful (true) or not (false). |
| 253 | func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool { |
| 254 | if h, ok := t.(tHelper); ok { |
| 255 | h.Helper() |
| 256 | } |
| 257 | return HTTPStatusCode(t, handler, method, url, values, statuscode, append([]interface{}{msg}, args...)...) |
| 258 | } |
| 259 | |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 260 | // HTTPSuccessf asserts that a specified handler returns a success status code. |
| 261 | // |
| 262 | // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") |
| 263 | // |
| 264 | // Returns whether the assertion was successful (true) or not (false). |
| 265 | func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { |
| 266 | if h, ok := t.(tHelper); ok { |
| 267 | h.Helper() |
| 268 | } |
| 269 | return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...) |
| 270 | } |
| 271 | |
| 272 | // Implementsf asserts that an object is implemented by the specified interface. |
| 273 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 274 | // assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 275 | func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool { |
| 276 | if h, ok := t.(tHelper); ok { |
| 277 | h.Helper() |
| 278 | } |
| 279 | return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...) |
| 280 | } |
| 281 | |
| 282 | // InDeltaf asserts that the two numerals are within delta of each other. |
| 283 | // |
| 284 | // assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") |
| 285 | func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { |
| 286 | if h, ok := t.(tHelper); ok { |
| 287 | h.Helper() |
| 288 | } |
| 289 | return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
| 290 | } |
| 291 | |
| 292 | // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. |
| 293 | func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { |
| 294 | if h, ok := t.(tHelper); ok { |
| 295 | h.Helper() |
| 296 | } |
| 297 | return InDeltaMapValues(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
| 298 | } |
| 299 | |
| 300 | // InDeltaSlicef is the same as InDelta, except it compares two slices. |
| 301 | func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { |
| 302 | if h, ok := t.(tHelper); ok { |
| 303 | h.Helper() |
| 304 | } |
| 305 | return InDeltaSlice(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
| 306 | } |
| 307 | |
| 308 | // InEpsilonf asserts that expected and actual have a relative error less than epsilon |
| 309 | func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { |
| 310 | if h, ok := t.(tHelper); ok { |
| 311 | h.Helper() |
| 312 | } |
| 313 | return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) |
| 314 | } |
| 315 | |
| 316 | // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. |
| 317 | func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { |
| 318 | if h, ok := t.(tHelper); ok { |
| 319 | h.Helper() |
| 320 | } |
| 321 | return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) |
| 322 | } |
| 323 | |
| 324 | // IsTypef asserts that the specified objects are of the same type. |
| 325 | func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool { |
| 326 | if h, ok := t.(tHelper); ok { |
| 327 | h.Helper() |
| 328 | } |
| 329 | return IsType(t, expectedType, object, append([]interface{}{msg}, args...)...) |
| 330 | } |
| 331 | |
| 332 | // JSONEqf asserts that two JSON strings are equivalent. |
| 333 | // |
| 334 | // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") |
| 335 | func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool { |
| 336 | if h, ok := t.(tHelper); ok { |
| 337 | h.Helper() |
| 338 | } |
| 339 | return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 340 | } |
| 341 | |
| 342 | // Lenf asserts that the specified object has specific length. |
| 343 | // Lenf also fails if the object has a type that len() not accept. |
| 344 | // |
| 345 | // assert.Lenf(t, mySlice, 3, "error message %s", "formatted") |
| 346 | func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool { |
| 347 | if h, ok := t.(tHelper); ok { |
| 348 | h.Helper() |
| 349 | } |
| 350 | return Len(t, object, length, append([]interface{}{msg}, args...)...) |
| 351 | } |
| 352 | |
| 353 | // Lessf asserts that the first element is less than the second |
| 354 | // |
| 355 | // assert.Lessf(t, 1, 2, "error message %s", "formatted") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 356 | // assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 357 | // assert.Lessf(t, "a", "b", "error message %s", "formatted") |
| 358 | func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
| 359 | if h, ok := t.(tHelper); ok { |
| 360 | h.Helper() |
| 361 | } |
| 362 | return Less(t, e1, e2, append([]interface{}{msg}, args...)...) |
| 363 | } |
| 364 | |
| 365 | // LessOrEqualf asserts that the first element is less than or equal to the second |
| 366 | // |
| 367 | // assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") |
| 368 | // assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") |
| 369 | // assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") |
| 370 | // assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") |
| 371 | func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { |
| 372 | if h, ok := t.(tHelper); ok { |
| 373 | h.Helper() |
| 374 | } |
| 375 | return LessOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...) |
| 376 | } |
| 377 | |
| 378 | // Neverf asserts that the given condition doesn't satisfy in waitFor time, |
| 379 | // periodically checking the target function each tick. |
| 380 | // |
| 381 | // assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") |
| 382 | func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { |
| 383 | if h, ok := t.(tHelper); ok { |
| 384 | h.Helper() |
| 385 | } |
| 386 | return Never(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...) |
| 387 | } |
| 388 | |
| 389 | // Nilf asserts that the specified object is nil. |
| 390 | // |
| 391 | // assert.Nilf(t, err, "error message %s", "formatted") |
| 392 | func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
| 393 | if h, ok := t.(tHelper); ok { |
| 394 | h.Helper() |
| 395 | } |
| 396 | return Nil(t, object, append([]interface{}{msg}, args...)...) |
| 397 | } |
| 398 | |
| 399 | // NoDirExistsf checks whether a directory does not exist in the given path. |
| 400 | // It fails if the path points to an existing _directory_ only. |
| 401 | func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
| 402 | if h, ok := t.(tHelper); ok { |
| 403 | h.Helper() |
| 404 | } |
| 405 | return NoDirExists(t, path, append([]interface{}{msg}, args...)...) |
| 406 | } |
| 407 | |
| 408 | // NoErrorf asserts that a function returned no error (i.e. `nil`). |
| 409 | // |
| 410 | // actualObj, err := SomeFunction() |
| 411 | // if assert.NoErrorf(t, err, "error message %s", "formatted") { |
| 412 | // assert.Equal(t, expectedObj, actualObj) |
| 413 | // } |
| 414 | func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool { |
| 415 | if h, ok := t.(tHelper); ok { |
| 416 | h.Helper() |
| 417 | } |
| 418 | return NoError(t, err, append([]interface{}{msg}, args...)...) |
| 419 | } |
| 420 | |
| 421 | // NoFileExistsf checks whether a file does not exist in a given path. It fails |
| 422 | // if the path points to an existing _file_ only. |
| 423 | func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) bool { |
| 424 | if h, ok := t.(tHelper); ok { |
| 425 | h.Helper() |
| 426 | } |
| 427 | return NoFileExists(t, path, append([]interface{}{msg}, args...)...) |
| 428 | } |
| 429 | |
| 430 | // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the |
| 431 | // specified substring or element. |
| 432 | // |
| 433 | // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") |
| 434 | // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") |
| 435 | // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") |
| 436 | func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool { |
| 437 | if h, ok := t.(tHelper); ok { |
| 438 | h.Helper() |
| 439 | } |
| 440 | return NotContains(t, s, contains, append([]interface{}{msg}, args...)...) |
| 441 | } |
| 442 | |
| 443 | // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either |
| 444 | // a slice or a channel with len == 0. |
| 445 | // |
| 446 | // if assert.NotEmptyf(t, obj, "error message %s", "formatted") { |
| 447 | // assert.Equal(t, "two", obj[1]) |
| 448 | // } |
| 449 | func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
| 450 | if h, ok := t.(tHelper); ok { |
| 451 | h.Helper() |
| 452 | } |
| 453 | return NotEmpty(t, object, append([]interface{}{msg}, args...)...) |
| 454 | } |
| 455 | |
| 456 | // NotEqualf asserts that the specified values are NOT equal. |
| 457 | // |
| 458 | // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted") |
| 459 | // |
| 460 | // Pointer variable equality is determined based on the equality of the |
| 461 | // referenced values (as opposed to the memory addresses). |
| 462 | func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
| 463 | if h, ok := t.(tHelper); ok { |
| 464 | h.Helper() |
| 465 | } |
| 466 | return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 467 | } |
| 468 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 469 | // NotEqualValuesf asserts that two objects are not equal even when converted to the same type |
| 470 | // |
| 471 | // assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") |
| 472 | func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
| 473 | if h, ok := t.(tHelper); ok { |
| 474 | h.Helper() |
| 475 | } |
| 476 | return NotEqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 477 | } |
| 478 | |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 479 | // NotNilf asserts that the specified object is not nil. |
| 480 | // |
| 481 | // assert.NotNilf(t, err, "error message %s", "formatted") |
| 482 | func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { |
| 483 | if h, ok := t.(tHelper); ok { |
| 484 | h.Helper() |
| 485 | } |
| 486 | return NotNil(t, object, append([]interface{}{msg}, args...)...) |
| 487 | } |
| 488 | |
| 489 | // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. |
| 490 | // |
| 491 | // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") |
| 492 | func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool { |
| 493 | if h, ok := t.(tHelper); ok { |
| 494 | h.Helper() |
| 495 | } |
| 496 | return NotPanics(t, f, append([]interface{}{msg}, args...)...) |
| 497 | } |
| 498 | |
| 499 | // NotRegexpf asserts that a specified regexp does not match a string. |
| 500 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 501 | // assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 502 | // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") |
| 503 | func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { |
| 504 | if h, ok := t.(tHelper); ok { |
| 505 | h.Helper() |
| 506 | } |
| 507 | return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...) |
| 508 | } |
| 509 | |
| 510 | // NotSamef asserts that two pointers do not reference the same object. |
| 511 | // |
| 512 | // assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted") |
| 513 | // |
| 514 | // Both arguments must be pointer variables. Pointer variable sameness is |
| 515 | // determined based on the equality of both type and value. |
| 516 | func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
| 517 | if h, ok := t.(tHelper); ok { |
| 518 | h.Helper() |
| 519 | } |
| 520 | return NotSame(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 521 | } |
| 522 | |
| 523 | // NotSubsetf asserts that the specified list(array, slice...) contains not all |
| 524 | // elements given in the specified subset(array, slice...). |
| 525 | // |
| 526 | // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") |
| 527 | func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { |
| 528 | if h, ok := t.(tHelper); ok { |
| 529 | h.Helper() |
| 530 | } |
| 531 | return NotSubset(t, list, subset, append([]interface{}{msg}, args...)...) |
| 532 | } |
| 533 | |
| 534 | // NotZerof asserts that i is not the zero value for its type. |
| 535 | func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool { |
| 536 | if h, ok := t.(tHelper); ok { |
| 537 | h.Helper() |
| 538 | } |
| 539 | return NotZero(t, i, append([]interface{}{msg}, args...)...) |
| 540 | } |
| 541 | |
| 542 | // Panicsf asserts that the code inside the specified PanicTestFunc panics. |
| 543 | // |
| 544 | // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") |
| 545 | func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool { |
| 546 | if h, ok := t.(tHelper); ok { |
| 547 | h.Helper() |
| 548 | } |
| 549 | return Panics(t, f, append([]interface{}{msg}, args...)...) |
| 550 | } |
| 551 | |
| 552 | // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc |
| 553 | // panics, and that the recovered panic value is an error that satisfies the |
| 554 | // EqualError comparison. |
| 555 | // |
| 556 | // assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") |
| 557 | func PanicsWithErrorf(t TestingT, errString string, f PanicTestFunc, msg string, args ...interface{}) bool { |
| 558 | if h, ok := t.(tHelper); ok { |
| 559 | h.Helper() |
| 560 | } |
| 561 | return PanicsWithError(t, errString, f, append([]interface{}{msg}, args...)...) |
| 562 | } |
| 563 | |
| 564 | // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that |
| 565 | // the recovered panic value equals the expected panic value. |
| 566 | // |
| 567 | // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") |
| 568 | func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool { |
| 569 | if h, ok := t.(tHelper); ok { |
| 570 | h.Helper() |
| 571 | } |
| 572 | return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...) |
| 573 | } |
| 574 | |
| 575 | // Regexpf asserts that a specified regexp matches a string. |
| 576 | // |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 577 | // assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 578 | // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") |
| 579 | func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { |
| 580 | if h, ok := t.(tHelper); ok { |
| 581 | h.Helper() |
| 582 | } |
| 583 | return Regexp(t, rx, str, append([]interface{}{msg}, args...)...) |
| 584 | } |
| 585 | |
| 586 | // Samef asserts that two pointers reference the same object. |
| 587 | // |
| 588 | // assert.Samef(t, ptr1, ptr2, "error message %s", "formatted") |
| 589 | // |
| 590 | // Both arguments must be pointer variables. Pointer variable sameness is |
| 591 | // determined based on the equality of both type and value. |
| 592 | func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { |
| 593 | if h, ok := t.(tHelper); ok { |
| 594 | h.Helper() |
| 595 | } |
| 596 | return Same(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 597 | } |
| 598 | |
| 599 | // Subsetf asserts that the specified list(array, slice...) contains all |
| 600 | // elements given in the specified subset(array, slice...). |
| 601 | // |
| 602 | // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") |
| 603 | func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { |
| 604 | if h, ok := t.(tHelper); ok { |
| 605 | h.Helper() |
| 606 | } |
| 607 | return Subset(t, list, subset, append([]interface{}{msg}, args...)...) |
| 608 | } |
| 609 | |
| 610 | // Truef asserts that the specified value is true. |
| 611 | // |
| 612 | // assert.Truef(t, myBool, "error message %s", "formatted") |
| 613 | func Truef(t TestingT, value bool, msg string, args ...interface{}) bool { |
| 614 | if h, ok := t.(tHelper); ok { |
| 615 | h.Helper() |
| 616 | } |
| 617 | return True(t, value, append([]interface{}{msg}, args...)...) |
| 618 | } |
| 619 | |
| 620 | // WithinDurationf asserts that the two times are within duration delta of each other. |
| 621 | // |
| 622 | // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") |
| 623 | func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool { |
| 624 | if h, ok := t.(tHelper); ok { |
| 625 | h.Helper() |
| 626 | } |
| 627 | return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...) |
| 628 | } |
| 629 | |
| 630 | // YAMLEqf asserts that two YAML strings are equivalent. |
| 631 | func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool { |
| 632 | if h, ok := t.(tHelper); ok { |
| 633 | h.Helper() |
| 634 | } |
| 635 | return YAMLEq(t, expected, actual, append([]interface{}{msg}, args...)...) |
| 636 | } |
| 637 | |
| 638 | // Zerof asserts that i is the zero value for its type. |
| 639 | func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool { |
| 640 | if h, ok := t.(tHelper); ok { |
| 641 | h.Helper() |
| 642 | } |
| 643 | return Zero(t, i, append([]interface{}{msg}, args...)...) |
| 644 | } |