require.go 31 KB

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