assertion_format.go 32 KB

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