assertion_format.go 30 KB

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