assertion_format.go 32 KB

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