require.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. /*
  2. * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
  3. * THIS FILE MUST NOT BE EDITED BY HAND
  4. */
  5. package require
  6. import (
  7. assert "github.com/stretchr/testify/assert"
  8. http "net/http"
  9. url "net/url"
  10. time "time"
  11. )
  12. // Condition uses a Comparison to assert a complex condition.
  13. func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
  14. if !assert.Condition(t, comp, msgAndArgs...) {
  15. t.FailNow()
  16. }
  17. }
  18. // Conditionf uses a Comparison to assert a complex condition.
  19. func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) {
  20. if !assert.Conditionf(t, comp, msg, args...) {
  21. t.FailNow()
  22. }
  23. }
  24. // Contains asserts that the specified string, list(array, slice...) or map contains the
  25. // specified substring or element.
  26. //
  27. // assert.Contains(t, "Hello World", "World")
  28. // assert.Contains(t, ["Hello", "World"], "World")
  29. // assert.Contains(t, {"Hello": "World"}, "Hello")
  30. //
  31. // Returns whether the assertion was successful (true) or not (false).
  32. func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  33. if !assert.Contains(t, s, contains, msgAndArgs...) {
  34. t.FailNow()
  35. }
  36. }
  37. // Containsf asserts that the specified string, list(array, slice...) or map contains the
  38. // specified substring or element.
  39. //
  40. // assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
  41. // assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
  42. // assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
  43. //
  44. // Returns whether the assertion was successful (true) or not (false).
  45. func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
  46. if !assert.Containsf(t, s, contains, msg, args...) {
  47. t.FailNow()
  48. }
  49. }
  50. // DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
  51. func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {
  52. if !assert.DirExists(t, path, msgAndArgs...) {
  53. t.FailNow()
  54. }
  55. }
  56. // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
  57. func DirExistsf(t TestingT, path string, msg string, args ...interface{}) {
  58. if !assert.DirExistsf(t, path, msg, args...) {
  59. t.FailNow()
  60. }
  61. }
  62. // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
  63. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  64. // the number of appearances of each of them in both lists should match.
  65. //
  66. // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]))
  67. //
  68. // Returns whether the assertion was successful (true) or not (false).
  69. func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
  70. if !assert.ElementsMatch(t, listA, listB, msgAndArgs...) {
  71. t.FailNow()
  72. }
  73. }
  74. // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
  75. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  76. // the number of appearances of each of them in both lists should match.
  77. //
  78. // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted"))
  79. //
  80. // Returns whether the assertion was successful (true) or not (false).
  81. func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) {
  82. if !assert.ElementsMatchf(t, listA, listB, msg, args...) {
  83. t.FailNow()
  84. }
  85. }
  86. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  87. // a slice or a channel with len == 0.
  88. //
  89. // assert.Empty(t, obj)
  90. //
  91. // Returns whether the assertion was successful (true) or not (false).
  92. func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  93. if !assert.Empty(t, object, msgAndArgs...) {
  94. t.FailNow()
  95. }
  96. }
  97. // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  98. // a slice or a channel with len == 0.
  99. //
  100. // assert.Emptyf(t, obj, "error message %s", "formatted")
  101. //
  102. // Returns whether the assertion was successful (true) or not (false).
  103. func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  104. if !assert.Emptyf(t, object, msg, args...) {
  105. t.FailNow()
  106. }
  107. }
  108. // Equal asserts that two objects are equal.
  109. //
  110. // assert.Equal(t, 123, 123)
  111. //
  112. // Returns whether the assertion was successful (true) or not (false).
  113. //
  114. // Pointer variable equality is determined based on the equality of the
  115. // referenced values (as opposed to the memory addresses). Function equality
  116. // cannot be determined and will always fail.
  117. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  118. if !assert.Equal(t, expected, actual, msgAndArgs...) {
  119. t.FailNow()
  120. }
  121. }
  122. // EqualError asserts that a function returned an error (i.e. not `nil`)
  123. // and that it is equal to the provided error.
  124. //
  125. // actualObj, err := SomeFunction()
  126. // assert.EqualError(t, err, expectedErrorString)
  127. //
  128. // Returns whether the assertion was successful (true) or not (false).
  129. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
  130. if !assert.EqualError(t, theError, errString, msgAndArgs...) {
  131. t.FailNow()
  132. }
  133. }
  134. // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
  135. // and that it is equal to the provided error.
  136. //
  137. // actualObj, err := SomeFunction()
  138. // assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
  139. //
  140. // Returns whether the assertion was successful (true) or not (false).
  141. func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) {
  142. if !assert.EqualErrorf(t, theError, errString, msg, args...) {
  143. t.FailNow()
  144. }
  145. }
  146. // EqualValues asserts that two objects are equal or convertable to the same types
  147. // and equal.
  148. //
  149. // assert.EqualValues(t, uint32(123), int32(123))
  150. //
  151. // Returns whether the assertion was successful (true) or not (false).
  152. func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  153. if !assert.EqualValues(t, expected, actual, msgAndArgs...) {
  154. t.FailNow()
  155. }
  156. }
  157. // EqualValuesf asserts that two objects are equal or convertable to the same types
  158. // and equal.
  159. //
  160. // assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123))
  161. //
  162. // Returns whether the assertion was successful (true) or not (false).
  163. func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  164. if !assert.EqualValuesf(t, expected, actual, msg, args...) {
  165. t.FailNow()
  166. }
  167. }
  168. // Equalf asserts that two objects are equal.
  169. //
  170. // assert.Equalf(t, 123, 123, "error message %s", "formatted")
  171. //
  172. // Returns whether the assertion was successful (true) or not (false).
  173. //
  174. // Pointer variable equality is determined based on the equality of the
  175. // referenced values (as opposed to the memory addresses). Function equality
  176. // cannot be determined and will always fail.
  177. func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  178. if !assert.Equalf(t, expected, actual, msg, args...) {
  179. t.FailNow()
  180. }
  181. }
  182. // Error asserts that a function returned an error (i.e. not `nil`).
  183. //
  184. // actualObj, err := SomeFunction()
  185. // if assert.Error(t, err) {
  186. // assert.Equal(t, expectedError, err)
  187. // }
  188. //
  189. // Returns whether the assertion was successful (true) or not (false).
  190. func Error(t TestingT, err error, msgAndArgs ...interface{}) {
  191. if !assert.Error(t, err, msgAndArgs...) {
  192. t.FailNow()
  193. }
  194. }
  195. // Errorf asserts that a function returned an error (i.e. not `nil`).
  196. //
  197. // actualObj, err := SomeFunction()
  198. // if assert.Errorf(t, err, "error message %s", "formatted") {
  199. // assert.Equal(t, expectedErrorf, err)
  200. // }
  201. //
  202. // Returns whether the assertion was successful (true) or not (false).
  203. func Errorf(t TestingT, err error, msg string, args ...interface{}) {
  204. if !assert.Errorf(t, err, msg, args...) {
  205. t.FailNow()
  206. }
  207. }
  208. // Exactly asserts that two objects are equal in value and type.
  209. //
  210. // assert.Exactly(t, int32(123), int64(123))
  211. //
  212. // Returns whether the assertion was successful (true) or not (false).
  213. func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  214. if !assert.Exactly(t, expected, actual, msgAndArgs...) {
  215. t.FailNow()
  216. }
  217. }
  218. // Exactlyf asserts that two objects are equal in value and type.
  219. //
  220. // assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123))
  221. //
  222. // Returns whether the assertion was successful (true) or not (false).
  223. func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  224. if !assert.Exactlyf(t, expected, actual, msg, args...) {
  225. t.FailNow()
  226. }
  227. }
  228. // Fail reports a failure through
  229. func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  230. if !assert.Fail(t, failureMessage, msgAndArgs...) {
  231. t.FailNow()
  232. }
  233. }
  234. // FailNow fails test
  235. func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  236. if !assert.FailNow(t, failureMessage, msgAndArgs...) {
  237. t.FailNow()
  238. }
  239. }
  240. // FailNowf fails test
  241. func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {
  242. if !assert.FailNowf(t, failureMessage, msg, args...) {
  243. t.FailNow()
  244. }
  245. }
  246. // Failf reports a failure through
  247. func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) {
  248. if !assert.Failf(t, failureMessage, msg, args...) {
  249. t.FailNow()
  250. }
  251. }
  252. // False asserts that the specified value is false.
  253. //
  254. // assert.False(t, myBool)
  255. //
  256. // Returns whether the assertion was successful (true) or not (false).
  257. func False(t TestingT, value bool, msgAndArgs ...interface{}) {
  258. if !assert.False(t, value, msgAndArgs...) {
  259. t.FailNow()
  260. }
  261. }
  262. // Falsef asserts that the specified value is false.
  263. //
  264. // assert.Falsef(t, myBool, "error message %s", "formatted")
  265. //
  266. // Returns whether the assertion was successful (true) or not (false).
  267. func Falsef(t TestingT, value bool, msg string, args ...interface{}) {
  268. if !assert.Falsef(t, value, msg, args...) {
  269. t.FailNow()
  270. }
  271. }
  272. // FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
  273. func FileExists(t TestingT, path string, msgAndArgs ...interface{}) {
  274. if !assert.FileExists(t, path, msgAndArgs...) {
  275. t.FailNow()
  276. }
  277. }
  278. // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
  279. func FileExistsf(t TestingT, path string, msg string, args ...interface{}) {
  280. if !assert.FileExistsf(t, path, msg, args...) {
  281. t.FailNow()
  282. }
  283. }
  284. // HTTPBodyContains asserts that a specified handler returns a
  285. // body that contains a string.
  286. //
  287. // assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
  288. //
  289. // Returns whether the assertion was successful (true) or not (false).
  290. func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  291. if !assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) {
  292. t.FailNow()
  293. }
  294. }
  295. // HTTPBodyContainsf asserts that a specified handler returns a
  296. // body that contains a string.
  297. //
  298. // assert.HTTPBodyContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  299. //
  300. // Returns whether the assertion was successful (true) or not (false).
  301. func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  302. if !assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) {
  303. t.FailNow()
  304. }
  305. }
  306. // HTTPBodyNotContains asserts that a specified handler returns a
  307. // body that does not contain a string.
  308. //
  309. // assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
  310. //
  311. // Returns whether the assertion was successful (true) or not (false).
  312. func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  313. if !assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) {
  314. t.FailNow()
  315. }
  316. }
  317. // HTTPBodyNotContainsf asserts that a specified handler returns a
  318. // body that does not contain a string.
  319. //
  320. // assert.HTTPBodyNotContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  321. //
  322. // Returns whether the assertion was successful (true) or not (false).
  323. func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  324. if !assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) {
  325. t.FailNow()
  326. }
  327. }
  328. // HTTPError asserts that a specified handler returns an error status code.
  329. //
  330. // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  331. //
  332. // Returns whether the assertion was successful (true) or not (false).
  333. func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  334. if !assert.HTTPError(t, handler, method, url, values, msgAndArgs...) {
  335. t.FailNow()
  336. }
  337. }
  338. // HTTPErrorf asserts that a specified handler returns an error status code.
  339. //
  340. // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  341. //
  342. // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
  343. func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  344. if !assert.HTTPErrorf(t, handler, method, url, values, msg, args...) {
  345. t.FailNow()
  346. }
  347. }
  348. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  349. //
  350. // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  351. //
  352. // Returns whether the assertion was successful (true) or not (false).
  353. func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  354. if !assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) {
  355. t.FailNow()
  356. }
  357. }
  358. // HTTPRedirectf asserts that a specified handler returns a redirect status code.
  359. //
  360. // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  361. //
  362. // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
  363. func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  364. if !assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) {
  365. t.FailNow()
  366. }
  367. }
  368. // HTTPSuccess asserts that a specified handler returns a success status code.
  369. //
  370. // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
  371. //
  372. // Returns whether the assertion was successful (true) or not (false).
  373. func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  374. if !assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) {
  375. t.FailNow()
  376. }
  377. }
  378. // HTTPSuccessf asserts that a specified handler returns a success status code.
  379. //
  380. // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
  381. //
  382. // Returns whether the assertion was successful (true) or not (false).
  383. func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  384. if !assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) {
  385. t.FailNow()
  386. }
  387. }
  388. // Implements asserts that an object is implemented by the specified interface.
  389. //
  390. // assert.Implements(t, (*MyInterface)(nil), new(MyObject))
  391. func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  392. if !assert.Implements(t, interfaceObject, object, msgAndArgs...) {
  393. t.FailNow()
  394. }
  395. }
  396. // Implementsf asserts that an object is implemented by the specified interface.
  397. //
  398. // assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject))
  399. func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {
  400. if !assert.Implementsf(t, interfaceObject, object, msg, args...) {
  401. t.FailNow()
  402. }
  403. }
  404. // InDelta asserts that the two numerals are within delta of each other.
  405. //
  406. // assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
  407. //
  408. // Returns whether the assertion was successful (true) or not (false).
  409. func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  410. if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
  411. t.FailNow()
  412. }
  413. }
  414. // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  415. func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  416. if !assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) {
  417. t.FailNow()
  418. }
  419. }
  420. // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  421. func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  422. if !assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) {
  423. t.FailNow()
  424. }
  425. }
  426. // InDeltaSlice is the same as InDelta, except it compares two slices.
  427. func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  428. if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
  429. t.FailNow()
  430. }
  431. }
  432. // InDeltaSlicef is the same as InDelta, except it compares two slices.
  433. func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  434. if !assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) {
  435. t.FailNow()
  436. }
  437. }
  438. // InDeltaf asserts that the two numerals are within delta of each other.
  439. //
  440. // assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01)
  441. //
  442. // Returns whether the assertion was successful (true) or not (false).
  443. func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  444. if !assert.InDeltaf(t, expected, actual, delta, msg, args...) {
  445. t.FailNow()
  446. }
  447. }
  448. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  449. //
  450. // Returns whether the assertion was successful (true) or not (false).
  451. func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  452. if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
  453. t.FailNow()
  454. }
  455. }
  456. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  457. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  458. if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
  459. t.FailNow()
  460. }
  461. }
  462. // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
  463. func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  464. if !assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) {
  465. t.FailNow()
  466. }
  467. }
  468. // InEpsilonf asserts that expected and actual have a relative error less than epsilon
  469. //
  470. // Returns whether the assertion was successful (true) or not (false).
  471. func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  472. if !assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) {
  473. t.FailNow()
  474. }
  475. }
  476. // IsType asserts that the specified objects are of the same type.
  477. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
  478. if !assert.IsType(t, expectedType, object, msgAndArgs...) {
  479. t.FailNow()
  480. }
  481. }
  482. // IsTypef asserts that the specified objects are of the same type.
  483. func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {
  484. if !assert.IsTypef(t, expectedType, object, msg, args...) {
  485. t.FailNow()
  486. }
  487. }
  488. // JSONEq asserts that two JSON strings are equivalent.
  489. //
  490. // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  491. //
  492. // Returns whether the assertion was successful (true) or not (false).
  493. func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  494. if !assert.JSONEq(t, expected, actual, msgAndArgs...) {
  495. t.FailNow()
  496. }
  497. }
  498. // JSONEqf asserts that two JSON strings are equivalent.
  499. //
  500. // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
  501. //
  502. // Returns whether the assertion was successful (true) or not (false).
  503. func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {
  504. if !assert.JSONEqf(t, expected, actual, msg, args...) {
  505. t.FailNow()
  506. }
  507. }
  508. // Len asserts that the specified object has specific length.
  509. // Len also fails if the object has a type that len() not accept.
  510. //
  511. // assert.Len(t, mySlice, 3)
  512. //
  513. // Returns whether the assertion was successful (true) or not (false).
  514. func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
  515. if !assert.Len(t, object, length, msgAndArgs...) {
  516. t.FailNow()
  517. }
  518. }
  519. // Lenf asserts that the specified object has specific length.
  520. // Lenf also fails if the object has a type that len() not accept.
  521. //
  522. // assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
  523. //
  524. // Returns whether the assertion was successful (true) or not (false).
  525. func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) {
  526. if !assert.Lenf(t, object, length, msg, args...) {
  527. t.FailNow()
  528. }
  529. }
  530. // Nil asserts that the specified object is nil.
  531. //
  532. // assert.Nil(t, err)
  533. //
  534. // Returns whether the assertion was successful (true) or not (false).
  535. func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  536. if !assert.Nil(t, object, msgAndArgs...) {
  537. t.FailNow()
  538. }
  539. }
  540. // Nilf asserts that the specified object is nil.
  541. //
  542. // assert.Nilf(t, err, "error message %s", "formatted")
  543. //
  544. // Returns whether the assertion was successful (true) or not (false).
  545. func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  546. if !assert.Nilf(t, object, msg, args...) {
  547. t.FailNow()
  548. }
  549. }
  550. // NoError asserts that a function returned no error (i.e. `nil`).
  551. //
  552. // actualObj, err := SomeFunction()
  553. // if assert.NoError(t, err) {
  554. // assert.Equal(t, expectedObj, actualObj)
  555. // }
  556. //
  557. // Returns whether the assertion was successful (true) or not (false).
  558. func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
  559. if !assert.NoError(t, err, msgAndArgs...) {
  560. t.FailNow()
  561. }
  562. }
  563. // NoErrorf asserts that a function returned no error (i.e. `nil`).
  564. //
  565. // actualObj, err := SomeFunction()
  566. // if assert.NoErrorf(t, err, "error message %s", "formatted") {
  567. // assert.Equal(t, expectedObj, actualObj)
  568. // }
  569. //
  570. // Returns whether the assertion was successful (true) or not (false).
  571. func NoErrorf(t TestingT, err error, msg string, args ...interface{}) {
  572. if !assert.NoErrorf(t, err, msg, args...) {
  573. t.FailNow()
  574. }
  575. }
  576. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  577. // specified substring or element.
  578. //
  579. // assert.NotContains(t, "Hello World", "Earth")
  580. // assert.NotContains(t, ["Hello", "World"], "Earth")
  581. // assert.NotContains(t, {"Hello": "World"}, "Earth")
  582. //
  583. // Returns whether the assertion was successful (true) or not (false).
  584. func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  585. if !assert.NotContains(t, s, contains, msgAndArgs...) {
  586. t.FailNow()
  587. }
  588. }
  589. // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
  590. // specified substring or element.
  591. //
  592. // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
  593. // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
  594. // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
  595. //
  596. // Returns whether the assertion was successful (true) or not (false).
  597. func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
  598. if !assert.NotContainsf(t, s, contains, msg, args...) {
  599. t.FailNow()
  600. }
  601. }
  602. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  603. // a slice or a channel with len == 0.
  604. //
  605. // if assert.NotEmpty(t, obj) {
  606. // assert.Equal(t, "two", obj[1])
  607. // }
  608. //
  609. // Returns whether the assertion was successful (true) or not (false).
  610. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  611. if !assert.NotEmpty(t, object, msgAndArgs...) {
  612. t.FailNow()
  613. }
  614. }
  615. // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  616. // a slice or a channel with len == 0.
  617. //
  618. // if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
  619. // assert.Equal(t, "two", obj[1])
  620. // }
  621. //
  622. // Returns whether the assertion was successful (true) or not (false).
  623. func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  624. if !assert.NotEmptyf(t, object, msg, args...) {
  625. t.FailNow()
  626. }
  627. }
  628. // NotEqual asserts that the specified values are NOT equal.
  629. //
  630. // assert.NotEqual(t, obj1, obj2)
  631. //
  632. // Returns whether the assertion was successful (true) or not (false).
  633. //
  634. // Pointer variable equality is determined based on the equality of the
  635. // referenced values (as opposed to the memory addresses).
  636. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  637. if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
  638. t.FailNow()
  639. }
  640. }
  641. // NotEqualf asserts that the specified values are NOT equal.
  642. //
  643. // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
  644. //
  645. // Returns whether the assertion was successful (true) or not (false).
  646. //
  647. // Pointer variable equality is determined based on the equality of the
  648. // referenced values (as opposed to the memory addresses).
  649. func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  650. if !assert.NotEqualf(t, expected, actual, msg, args...) {
  651. t.FailNow()
  652. }
  653. }
  654. // NotNil asserts that the specified object is not nil.
  655. //
  656. // assert.NotNil(t, err)
  657. //
  658. // Returns whether the assertion was successful (true) or not (false).
  659. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  660. if !assert.NotNil(t, object, msgAndArgs...) {
  661. t.FailNow()
  662. }
  663. }
  664. // NotNilf asserts that the specified object is not nil.
  665. //
  666. // assert.NotNilf(t, err, "error message %s", "formatted")
  667. //
  668. // Returns whether the assertion was successful (true) or not (false).
  669. func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  670. if !assert.NotNilf(t, object, msg, args...) {
  671. t.FailNow()
  672. }
  673. }
  674. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  675. //
  676. // assert.NotPanics(t, func(){ RemainCalm() })
  677. //
  678. // Returns whether the assertion was successful (true) or not (false).
  679. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  680. if !assert.NotPanics(t, f, msgAndArgs...) {
  681. t.FailNow()
  682. }
  683. }
  684. // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
  685. //
  686. // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
  687. //
  688. // Returns whether the assertion was successful (true) or not (false).
  689. func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  690. if !assert.NotPanicsf(t, f, msg, args...) {
  691. t.FailNow()
  692. }
  693. }
  694. // NotRegexp asserts that a specified regexp does not match a string.
  695. //
  696. // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
  697. // assert.NotRegexp(t, "^start", "it's not starting")
  698. //
  699. // Returns whether the assertion was successful (true) or not (false).
  700. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  701. if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
  702. t.FailNow()
  703. }
  704. }
  705. // NotRegexpf asserts that a specified regexp does not match a string.
  706. //
  707. // assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
  708. // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
  709. //
  710. // Returns whether the assertion was successful (true) or not (false).
  711. func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  712. if !assert.NotRegexpf(t, rx, str, msg, args...) {
  713. t.FailNow()
  714. }
  715. }
  716. // NotSubset asserts that the specified list(array, slice...) contains not all
  717. // elements given in the specified subset(array, slice...).
  718. //
  719. // assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
  720. //
  721. // Returns whether the assertion was successful (true) or not (false).
  722. func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  723. if !assert.NotSubset(t, list, subset, msgAndArgs...) {
  724. t.FailNow()
  725. }
  726. }
  727. // NotSubsetf asserts that the specified list(array, slice...) contains not all
  728. // elements given in the specified subset(array, slice...).
  729. //
  730. // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")
  731. //
  732. // Returns whether the assertion was successful (true) or not (false).
  733. func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  734. if !assert.NotSubsetf(t, list, subset, msg, args...) {
  735. t.FailNow()
  736. }
  737. }
  738. // NotZero asserts that i is not the zero value for its type and returns the truth.
  739. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  740. if !assert.NotZero(t, i, msgAndArgs...) {
  741. t.FailNow()
  742. }
  743. }
  744. // NotZerof asserts that i is not the zero value for its type and returns the truth.
  745. func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  746. if !assert.NotZerof(t, i, msg, args...) {
  747. t.FailNow()
  748. }
  749. }
  750. // Panics asserts that the code inside the specified PanicTestFunc panics.
  751. //
  752. // assert.Panics(t, func(){ GoCrazy() })
  753. //
  754. // Returns whether the assertion was successful (true) or not (false).
  755. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  756. if !assert.Panics(t, f, msgAndArgs...) {
  757. t.FailNow()
  758. }
  759. }
  760. // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
  761. // the recovered panic value equals the expected panic value.
  762. //
  763. // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
  764. //
  765. // Returns whether the assertion was successful (true) or not (false).
  766. func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  767. if !assert.PanicsWithValue(t, expected, f, msgAndArgs...) {
  768. t.FailNow()
  769. }
  770. }
  771. // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
  772. // the recovered panic value equals the expected panic value.
  773. //
  774. // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  775. //
  776. // Returns whether the assertion was successful (true) or not (false).
  777. func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {
  778. if !assert.PanicsWithValuef(t, expected, f, msg, args...) {
  779. t.FailNow()
  780. }
  781. }
  782. // Panicsf asserts that the code inside the specified PanicTestFunc panics.
  783. //
  784. // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
  785. //
  786. // Returns whether the assertion was successful (true) or not (false).
  787. func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  788. if !assert.Panicsf(t, f, msg, args...) {
  789. t.FailNow()
  790. }
  791. }
  792. // Regexp asserts that a specified regexp matches a string.
  793. //
  794. // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
  795. // assert.Regexp(t, "start...$", "it's not starting")
  796. //
  797. // Returns whether the assertion was successful (true) or not (false).
  798. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  799. if !assert.Regexp(t, rx, str, msgAndArgs...) {
  800. t.FailNow()
  801. }
  802. }
  803. // Regexpf asserts that a specified regexp matches a string.
  804. //
  805. // assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
  806. // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
  807. //
  808. // Returns whether the assertion was successful (true) or not (false).
  809. func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  810. if !assert.Regexpf(t, rx, str, msg, args...) {
  811. t.FailNow()
  812. }
  813. }
  814. // Subset asserts that the specified list(array, slice...) contains all
  815. // elements given in the specified subset(array, slice...).
  816. //
  817. // assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
  818. //
  819. // Returns whether the assertion was successful (true) or not (false).
  820. func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  821. if !assert.Subset(t, list, subset, msgAndArgs...) {
  822. t.FailNow()
  823. }
  824. }
  825. // Subsetf asserts that the specified list(array, slice...) contains all
  826. // elements given in the specified subset(array, slice...).
  827. //
  828. // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")
  829. //
  830. // Returns whether the assertion was successful (true) or not (false).
  831. func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  832. if !assert.Subsetf(t, list, subset, msg, args...) {
  833. t.FailNow()
  834. }
  835. }
  836. // True asserts that the specified value is true.
  837. //
  838. // assert.True(t, myBool)
  839. //
  840. // Returns whether the assertion was successful (true) or not (false).
  841. func True(t TestingT, value bool, msgAndArgs ...interface{}) {
  842. if !assert.True(t, value, msgAndArgs...) {
  843. t.FailNow()
  844. }
  845. }
  846. // Truef asserts that the specified value is true.
  847. //
  848. // assert.Truef(t, myBool, "error message %s", "formatted")
  849. //
  850. // Returns whether the assertion was successful (true) or not (false).
  851. func Truef(t TestingT, value bool, msg string, args ...interface{}) {
  852. if !assert.Truef(t, value, msg, args...) {
  853. t.FailNow()
  854. }
  855. }
  856. // WithinDuration asserts that the two times are within duration delta of each other.
  857. //
  858. // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
  859. //
  860. // Returns whether the assertion was successful (true) or not (false).
  861. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  862. if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
  863. t.FailNow()
  864. }
  865. }
  866. // WithinDurationf asserts that the two times are within duration delta of each other.
  867. //
  868. // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
  869. //
  870. // Returns whether the assertion was successful (true) or not (false).
  871. func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {
  872. if !assert.WithinDurationf(t, expected, actual, delta, msg, args...) {
  873. t.FailNow()
  874. }
  875. }
  876. // Zero asserts that i is the zero value for its type and returns the truth.
  877. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  878. if !assert.Zero(t, i, msgAndArgs...) {
  879. t.FailNow()
  880. }
  881. }
  882. // Zerof asserts that i is the zero value for its type and returns the truth.
  883. func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  884. if !assert.Zerof(t, i, msg, args...) {
  885. t.FailNow()
  886. }
  887. }