require.go 32 KB

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