require.go 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  1. // Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT.
  2. package require
  3. import (
  4. assert "github.com/stretchr/testify/assert"
  5. http "net/http"
  6. url "net/url"
  7. time "time"
  8. )
  9. // Condition uses a Comparison to assert a complex condition.
  10. func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
  11. if h, ok := t.(tHelper); ok {
  12. h.Helper()
  13. }
  14. if assert.Condition(t, comp, msgAndArgs...) {
  15. return
  16. }
  17. t.FailNow()
  18. }
  19. // Conditionf uses a Comparison to assert a complex condition.
  20. func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) {
  21. if h, ok := t.(tHelper); ok {
  22. h.Helper()
  23. }
  24. if assert.Conditionf(t, comp, msg, args...) {
  25. return
  26. }
  27. t.FailNow()
  28. }
  29. // Contains asserts that the specified string, list(array, slice...) or map contains the
  30. // specified substring or element.
  31. //
  32. // require.Contains(t, "Hello World", "World")
  33. // require.Contains(t, ["Hello", "World"], "World")
  34. // require.Contains(t, {"Hello": "World"}, "Hello")
  35. func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  36. if h, ok := t.(tHelper); ok {
  37. h.Helper()
  38. }
  39. if assert.Contains(t, s, contains, msgAndArgs...) {
  40. return
  41. }
  42. t.FailNow()
  43. }
  44. // Containsf asserts that the specified string, list(array, slice...) or map contains the
  45. // specified substring or element.
  46. //
  47. // require.Containsf(t, "Hello World", "World", "error message %s", "formatted")
  48. // require.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
  49. // require.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
  50. func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
  51. if h, ok := t.(tHelper); ok {
  52. h.Helper()
  53. }
  54. if assert.Containsf(t, s, contains, msg, args...) {
  55. return
  56. }
  57. t.FailNow()
  58. }
  59. // DirExists checks whether a directory exists in the given path. It also fails
  60. // if the path is a file rather a directory or there is an error checking whether it exists.
  61. func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {
  62. if h, ok := t.(tHelper); ok {
  63. h.Helper()
  64. }
  65. if assert.DirExists(t, path, msgAndArgs...) {
  66. return
  67. }
  68. t.FailNow()
  69. }
  70. // DirExistsf checks whether a directory exists in the given path. It also fails
  71. // if the path is a file rather a directory or there is an error checking whether it exists.
  72. func DirExistsf(t TestingT, path string, msg string, args ...interface{}) {
  73. if h, ok := t.(tHelper); ok {
  74. h.Helper()
  75. }
  76. if assert.DirExistsf(t, path, msg, args...) {
  77. return
  78. }
  79. t.FailNow()
  80. }
  81. // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
  82. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  83. // the number of appearances of each of them in both lists should match.
  84. //
  85. // require.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
  86. func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
  87. if h, ok := t.(tHelper); ok {
  88. h.Helper()
  89. }
  90. if assert.ElementsMatch(t, listA, listB, msgAndArgs...) {
  91. return
  92. }
  93. t.FailNow()
  94. }
  95. // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
  96. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  97. // the number of appearances of each of them in both lists should match.
  98. //
  99. // require.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
  100. func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) {
  101. if h, ok := t.(tHelper); ok {
  102. h.Helper()
  103. }
  104. if assert.ElementsMatchf(t, listA, listB, msg, args...) {
  105. return
  106. }
  107. t.FailNow()
  108. }
  109. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  110. // a slice or a channel with len == 0.
  111. //
  112. // require.Empty(t, obj)
  113. func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  114. if h, ok := t.(tHelper); ok {
  115. h.Helper()
  116. }
  117. if assert.Empty(t, object, msgAndArgs...) {
  118. return
  119. }
  120. t.FailNow()
  121. }
  122. // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  123. // a slice or a channel with len == 0.
  124. //
  125. // require.Emptyf(t, obj, "error message %s", "formatted")
  126. func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  127. if h, ok := t.(tHelper); ok {
  128. h.Helper()
  129. }
  130. if assert.Emptyf(t, object, msg, args...) {
  131. return
  132. }
  133. t.FailNow()
  134. }
  135. // Equal asserts that two objects are equal.
  136. //
  137. // require.Equal(t, 123, 123)
  138. //
  139. // Pointer variable equality is determined based on the equality of the
  140. // referenced values (as opposed to the memory addresses). Function equality
  141. // cannot be determined and will always fail.
  142. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  143. if h, ok := t.(tHelper); ok {
  144. h.Helper()
  145. }
  146. if assert.Equal(t, expected, actual, msgAndArgs...) {
  147. return
  148. }
  149. t.FailNow()
  150. }
  151. // EqualError asserts that a function returned an error (i.e. not `nil`)
  152. // and that it is equal to the provided error.
  153. //
  154. // actualObj, err := SomeFunction()
  155. // require.EqualError(t, err, expectedErrorString)
  156. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
  157. if h, ok := t.(tHelper); ok {
  158. h.Helper()
  159. }
  160. if assert.EqualError(t, theError, errString, msgAndArgs...) {
  161. return
  162. }
  163. t.FailNow()
  164. }
  165. // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
  166. // and that it is equal to the provided error.
  167. //
  168. // actualObj, err := SomeFunction()
  169. // require.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
  170. func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) {
  171. if h, ok := t.(tHelper); ok {
  172. h.Helper()
  173. }
  174. if assert.EqualErrorf(t, theError, errString, msg, args...) {
  175. return
  176. }
  177. t.FailNow()
  178. }
  179. // EqualExportedValues asserts that the types of two objects are equal and their public
  180. // fields are also equal. This is useful for comparing structs that have private fields
  181. // that could potentially differ.
  182. //
  183. // type S struct {
  184. // Exported int
  185. // notExported int
  186. // }
  187. // require.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
  188. // require.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
  189. func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  190. if h, ok := t.(tHelper); ok {
  191. h.Helper()
  192. }
  193. if assert.EqualExportedValues(t, expected, actual, msgAndArgs...) {
  194. return
  195. }
  196. t.FailNow()
  197. }
  198. // EqualExportedValuesf asserts that the types of two objects are equal and their public
  199. // fields are also equal. This is useful for comparing structs that have private fields
  200. // that could potentially differ.
  201. //
  202. // type S struct {
  203. // Exported int
  204. // notExported int
  205. // }
  206. // require.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true
  207. // require.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false
  208. func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  209. if h, ok := t.(tHelper); ok {
  210. h.Helper()
  211. }
  212. if assert.EqualExportedValuesf(t, expected, actual, msg, args...) {
  213. return
  214. }
  215. t.FailNow()
  216. }
  217. // EqualValues asserts that two objects are equal or convertible to the larger
  218. // type and equal.
  219. //
  220. // require.EqualValues(t, uint32(123), int32(123))
  221. func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  222. if h, ok := t.(tHelper); ok {
  223. h.Helper()
  224. }
  225. if assert.EqualValues(t, expected, actual, msgAndArgs...) {
  226. return
  227. }
  228. t.FailNow()
  229. }
  230. // EqualValuesf asserts that two objects are equal or convertible to the larger
  231. // type and equal.
  232. //
  233. // require.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")
  234. func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  235. if h, ok := t.(tHelper); ok {
  236. h.Helper()
  237. }
  238. if assert.EqualValuesf(t, expected, actual, msg, args...) {
  239. return
  240. }
  241. t.FailNow()
  242. }
  243. // Equalf asserts that two objects are equal.
  244. //
  245. // require.Equalf(t, 123, 123, "error message %s", "formatted")
  246. //
  247. // Pointer variable equality is determined based on the equality of the
  248. // referenced values (as opposed to the memory addresses). Function equality
  249. // cannot be determined and will always fail.
  250. func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  251. if h, ok := t.(tHelper); ok {
  252. h.Helper()
  253. }
  254. if assert.Equalf(t, expected, actual, msg, args...) {
  255. return
  256. }
  257. t.FailNow()
  258. }
  259. // Error asserts that a function returned an error (i.e. not `nil`).
  260. //
  261. // actualObj, err := SomeFunction()
  262. // if require.Error(t, err) {
  263. // require.Equal(t, expectedError, err)
  264. // }
  265. func Error(t TestingT, err error, msgAndArgs ...interface{}) {
  266. if h, ok := t.(tHelper); ok {
  267. h.Helper()
  268. }
  269. if assert.Error(t, err, msgAndArgs...) {
  270. return
  271. }
  272. t.FailNow()
  273. }
  274. // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
  275. // This is a wrapper for errors.As.
  276. func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) {
  277. if h, ok := t.(tHelper); ok {
  278. h.Helper()
  279. }
  280. if assert.ErrorAs(t, err, target, msgAndArgs...) {
  281. return
  282. }
  283. t.FailNow()
  284. }
  285. // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
  286. // This is a wrapper for errors.As.
  287. func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) {
  288. if h, ok := t.(tHelper); ok {
  289. h.Helper()
  290. }
  291. if assert.ErrorAsf(t, err, target, msg, args...) {
  292. return
  293. }
  294. t.FailNow()
  295. }
  296. // ErrorContains asserts that a function returned an error (i.e. not `nil`)
  297. // and that the error contains the specified substring.
  298. //
  299. // actualObj, err := SomeFunction()
  300. // require.ErrorContains(t, err, expectedErrorSubString)
  301. func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) {
  302. if h, ok := t.(tHelper); ok {
  303. h.Helper()
  304. }
  305. if assert.ErrorContains(t, theError, contains, msgAndArgs...) {
  306. return
  307. }
  308. t.FailNow()
  309. }
  310. // ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
  311. // and that the error contains the specified substring.
  312. //
  313. // actualObj, err := SomeFunction()
  314. // require.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
  315. func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) {
  316. if h, ok := t.(tHelper); ok {
  317. h.Helper()
  318. }
  319. if assert.ErrorContainsf(t, theError, contains, msg, args...) {
  320. return
  321. }
  322. t.FailNow()
  323. }
  324. // ErrorIs asserts that at least one of the errors in err's chain matches target.
  325. // This is a wrapper for errors.Is.
  326. func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) {
  327. if h, ok := t.(tHelper); ok {
  328. h.Helper()
  329. }
  330. if assert.ErrorIs(t, err, target, msgAndArgs...) {
  331. return
  332. }
  333. t.FailNow()
  334. }
  335. // ErrorIsf asserts that at least one of the errors in err's chain matches target.
  336. // This is a wrapper for errors.Is.
  337. func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) {
  338. if h, ok := t.(tHelper); ok {
  339. h.Helper()
  340. }
  341. if assert.ErrorIsf(t, err, target, msg, args...) {
  342. return
  343. }
  344. t.FailNow()
  345. }
  346. // Errorf asserts that a function returned an error (i.e. not `nil`).
  347. //
  348. // actualObj, err := SomeFunction()
  349. // if require.Errorf(t, err, "error message %s", "formatted") {
  350. // require.Equal(t, expectedErrorf, err)
  351. // }
  352. func Errorf(t TestingT, err error, msg string, args ...interface{}) {
  353. if h, ok := t.(tHelper); ok {
  354. h.Helper()
  355. }
  356. if assert.Errorf(t, err, msg, args...) {
  357. return
  358. }
  359. t.FailNow()
  360. }
  361. // Eventually asserts that given condition will be met in waitFor time,
  362. // periodically checking target function each tick.
  363. //
  364. // require.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
  365. func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
  366. if h, ok := t.(tHelper); ok {
  367. h.Helper()
  368. }
  369. if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) {
  370. return
  371. }
  372. t.FailNow()
  373. }
  374. // EventuallyWithT asserts that given condition will be met in waitFor time,
  375. // periodically checking target function each tick. In contrast to Eventually,
  376. // it supplies a CollectT to the condition function, so that the condition
  377. // function can use the CollectT to call other assertions.
  378. // The condition is considered "met" if no errors are raised in a tick.
  379. // The supplied CollectT collects all errors from one tick (if there are any).
  380. // If the condition is not met before waitFor, the collected errors of
  381. // the last tick are copied to t.
  382. //
  383. // externalValue := false
  384. // go func() {
  385. // time.Sleep(8*time.Second)
  386. // externalValue = true
  387. // }()
  388. // require.EventuallyWithT(t, func(c *require.CollectT) {
  389. // // add assertions as needed; any assertion failure will fail the current tick
  390. // require.True(c, externalValue, "expected 'externalValue' to be true")
  391. // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
  392. func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
  393. if h, ok := t.(tHelper); ok {
  394. h.Helper()
  395. }
  396. if assert.EventuallyWithT(t, condition, waitFor, tick, msgAndArgs...) {
  397. return
  398. }
  399. t.FailNow()
  400. }
  401. // EventuallyWithTf asserts that given condition will be met in waitFor time,
  402. // periodically checking target function each tick. In contrast to Eventually,
  403. // it supplies a CollectT to the condition function, so that the condition
  404. // function can use the CollectT to call other assertions.
  405. // The condition is considered "met" if no errors are raised in a tick.
  406. // The supplied CollectT collects all errors from one tick (if there are any).
  407. // If the condition is not met before waitFor, the collected errors of
  408. // the last tick are copied to t.
  409. //
  410. // externalValue := false
  411. // go func() {
  412. // time.Sleep(8*time.Second)
  413. // externalValue = true
  414. // }()
  415. // require.EventuallyWithTf(t, func(c *require.CollectT, "error message %s", "formatted") {
  416. // // add assertions as needed; any assertion failure will fail the current tick
  417. // require.True(c, externalValue, "expected 'externalValue' to be true")
  418. // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
  419. func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
  420. if h, ok := t.(tHelper); ok {
  421. h.Helper()
  422. }
  423. if assert.EventuallyWithTf(t, condition, waitFor, tick, msg, args...) {
  424. return
  425. }
  426. t.FailNow()
  427. }
  428. // Eventuallyf asserts that given condition will be met in waitFor time,
  429. // periodically checking target function each tick.
  430. //
  431. // require.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
  432. func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
  433. if h, ok := t.(tHelper); ok {
  434. h.Helper()
  435. }
  436. if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) {
  437. return
  438. }
  439. t.FailNow()
  440. }
  441. // Exactly asserts that two objects are equal in value and type.
  442. //
  443. // require.Exactly(t, int32(123), int64(123))
  444. func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  445. if h, ok := t.(tHelper); ok {
  446. h.Helper()
  447. }
  448. if assert.Exactly(t, expected, actual, msgAndArgs...) {
  449. return
  450. }
  451. t.FailNow()
  452. }
  453. // Exactlyf asserts that two objects are equal in value and type.
  454. //
  455. // require.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted")
  456. func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  457. if h, ok := t.(tHelper); ok {
  458. h.Helper()
  459. }
  460. if assert.Exactlyf(t, expected, actual, msg, args...) {
  461. return
  462. }
  463. t.FailNow()
  464. }
  465. // Fail reports a failure through
  466. func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  467. if h, ok := t.(tHelper); ok {
  468. h.Helper()
  469. }
  470. if assert.Fail(t, failureMessage, msgAndArgs...) {
  471. return
  472. }
  473. t.FailNow()
  474. }
  475. // FailNow fails test
  476. func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  477. if h, ok := t.(tHelper); ok {
  478. h.Helper()
  479. }
  480. if assert.FailNow(t, failureMessage, msgAndArgs...) {
  481. return
  482. }
  483. t.FailNow()
  484. }
  485. // FailNowf fails test
  486. func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {
  487. if h, ok := t.(tHelper); ok {
  488. h.Helper()
  489. }
  490. if assert.FailNowf(t, failureMessage, msg, args...) {
  491. return
  492. }
  493. t.FailNow()
  494. }
  495. // Failf reports a failure through
  496. func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) {
  497. if h, ok := t.(tHelper); ok {
  498. h.Helper()
  499. }
  500. if assert.Failf(t, failureMessage, msg, args...) {
  501. return
  502. }
  503. t.FailNow()
  504. }
  505. // False asserts that the specified value is false.
  506. //
  507. // require.False(t, myBool)
  508. func False(t TestingT, value bool, msgAndArgs ...interface{}) {
  509. if h, ok := t.(tHelper); ok {
  510. h.Helper()
  511. }
  512. if assert.False(t, value, msgAndArgs...) {
  513. return
  514. }
  515. t.FailNow()
  516. }
  517. // Falsef asserts that the specified value is false.
  518. //
  519. // require.Falsef(t, myBool, "error message %s", "formatted")
  520. func Falsef(t TestingT, value bool, msg string, args ...interface{}) {
  521. if h, ok := t.(tHelper); ok {
  522. h.Helper()
  523. }
  524. if assert.Falsef(t, value, msg, args...) {
  525. return
  526. }
  527. t.FailNow()
  528. }
  529. // FileExists checks whether a file exists in the given path. It also fails if
  530. // the path points to a directory or there is an error when trying to check the file.
  531. func FileExists(t TestingT, path string, msgAndArgs ...interface{}) {
  532. if h, ok := t.(tHelper); ok {
  533. h.Helper()
  534. }
  535. if assert.FileExists(t, path, msgAndArgs...) {
  536. return
  537. }
  538. t.FailNow()
  539. }
  540. // FileExistsf checks whether a file exists in the given path. It also fails if
  541. // the path points to a directory or there is an error when trying to check the file.
  542. func FileExistsf(t TestingT, path string, msg string, args ...interface{}) {
  543. if h, ok := t.(tHelper); ok {
  544. h.Helper()
  545. }
  546. if assert.FileExistsf(t, path, msg, args...) {
  547. return
  548. }
  549. t.FailNow()
  550. }
  551. // Greater asserts that the first element is greater than the second
  552. //
  553. // require.Greater(t, 2, 1)
  554. // require.Greater(t, float64(2), float64(1))
  555. // require.Greater(t, "b", "a")
  556. func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  557. if h, ok := t.(tHelper); ok {
  558. h.Helper()
  559. }
  560. if assert.Greater(t, e1, e2, msgAndArgs...) {
  561. return
  562. }
  563. t.FailNow()
  564. }
  565. // GreaterOrEqual asserts that the first element is greater than or equal to the second
  566. //
  567. // require.GreaterOrEqual(t, 2, 1)
  568. // require.GreaterOrEqual(t, 2, 2)
  569. // require.GreaterOrEqual(t, "b", "a")
  570. // require.GreaterOrEqual(t, "b", "b")
  571. func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  572. if h, ok := t.(tHelper); ok {
  573. h.Helper()
  574. }
  575. if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) {
  576. return
  577. }
  578. t.FailNow()
  579. }
  580. // GreaterOrEqualf asserts that the first element is greater than or equal to the second
  581. //
  582. // require.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")
  583. // require.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")
  584. // require.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")
  585. // require.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")
  586. func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  587. if h, ok := t.(tHelper); ok {
  588. h.Helper()
  589. }
  590. if assert.GreaterOrEqualf(t, e1, e2, msg, args...) {
  591. return
  592. }
  593. t.FailNow()
  594. }
  595. // Greaterf asserts that the first element is greater than the second
  596. //
  597. // require.Greaterf(t, 2, 1, "error message %s", "formatted")
  598. // require.Greaterf(t, float64(2), float64(1), "error message %s", "formatted")
  599. // require.Greaterf(t, "b", "a", "error message %s", "formatted")
  600. func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  601. if h, ok := t.(tHelper); ok {
  602. h.Helper()
  603. }
  604. if assert.Greaterf(t, e1, e2, msg, args...) {
  605. return
  606. }
  607. t.FailNow()
  608. }
  609. // HTTPBodyContains asserts that a specified handler returns a
  610. // body that contains a string.
  611. //
  612. // require.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  613. //
  614. // Returns whether the assertion was successful (true) or not (false).
  615. func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  616. if h, ok := t.(tHelper); ok {
  617. h.Helper()
  618. }
  619. if assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) {
  620. return
  621. }
  622. t.FailNow()
  623. }
  624. // HTTPBodyContainsf asserts that a specified handler returns a
  625. // body that contains a string.
  626. //
  627. // require.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  628. //
  629. // Returns whether the assertion was successful (true) or not (false).
  630. func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  631. if h, ok := t.(tHelper); ok {
  632. h.Helper()
  633. }
  634. if assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) {
  635. return
  636. }
  637. t.FailNow()
  638. }
  639. // HTTPBodyNotContains asserts that a specified handler returns a
  640. // body that does not contain a string.
  641. //
  642. // require.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  643. //
  644. // Returns whether the assertion was successful (true) or not (false).
  645. func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  646. if h, ok := t.(tHelper); ok {
  647. h.Helper()
  648. }
  649. if assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) {
  650. return
  651. }
  652. t.FailNow()
  653. }
  654. // HTTPBodyNotContainsf asserts that a specified handler returns a
  655. // body that does not contain a string.
  656. //
  657. // require.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  658. //
  659. // Returns whether the assertion was successful (true) or not (false).
  660. func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  661. if h, ok := t.(tHelper); ok {
  662. h.Helper()
  663. }
  664. if assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) {
  665. return
  666. }
  667. t.FailNow()
  668. }
  669. // HTTPError asserts that a specified handler returns an error status code.
  670. //
  671. // require.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  672. //
  673. // Returns whether the assertion was successful (true) or not (false).
  674. func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  675. if h, ok := t.(tHelper); ok {
  676. h.Helper()
  677. }
  678. if assert.HTTPError(t, handler, method, url, values, msgAndArgs...) {
  679. return
  680. }
  681. t.FailNow()
  682. }
  683. // HTTPErrorf asserts that a specified handler returns an error status code.
  684. //
  685. // require.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  686. //
  687. // Returns whether the assertion was successful (true) or not (false).
  688. func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  689. if h, ok := t.(tHelper); ok {
  690. h.Helper()
  691. }
  692. if assert.HTTPErrorf(t, handler, method, url, values, msg, args...) {
  693. return
  694. }
  695. t.FailNow()
  696. }
  697. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  698. //
  699. // require.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  700. //
  701. // Returns whether the assertion was successful (true) or not (false).
  702. func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  703. if h, ok := t.(tHelper); ok {
  704. h.Helper()
  705. }
  706. if assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) {
  707. return
  708. }
  709. t.FailNow()
  710. }
  711. // HTTPRedirectf asserts that a specified handler returns a redirect status code.
  712. //
  713. // require.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  714. //
  715. // Returns whether the assertion was successful (true) or not (false).
  716. func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  717. if h, ok := t.(tHelper); ok {
  718. h.Helper()
  719. }
  720. if assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) {
  721. return
  722. }
  723. t.FailNow()
  724. }
  725. // HTTPStatusCode asserts that a specified handler returns a specified status code.
  726. //
  727. // require.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501)
  728. //
  729. // Returns whether the assertion was successful (true) or not (false).
  730. func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) {
  731. if h, ok := t.(tHelper); ok {
  732. h.Helper()
  733. }
  734. if assert.HTTPStatusCode(t, handler, method, url, values, statuscode, msgAndArgs...) {
  735. return
  736. }
  737. t.FailNow()
  738. }
  739. // HTTPStatusCodef asserts that a specified handler returns a specified status code.
  740. //
  741. // require.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")
  742. //
  743. // Returns whether the assertion was successful (true) or not (false).
  744. func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) {
  745. if h, ok := t.(tHelper); ok {
  746. h.Helper()
  747. }
  748. if assert.HTTPStatusCodef(t, handler, method, url, values, statuscode, msg, args...) {
  749. return
  750. }
  751. t.FailNow()
  752. }
  753. // HTTPSuccess asserts that a specified handler returns a success status code.
  754. //
  755. // require.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
  756. //
  757. // Returns whether the assertion was successful (true) or not (false).
  758. func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  759. if h, ok := t.(tHelper); ok {
  760. h.Helper()
  761. }
  762. if assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) {
  763. return
  764. }
  765. t.FailNow()
  766. }
  767. // HTTPSuccessf asserts that a specified handler returns a success status code.
  768. //
  769. // require.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
  770. //
  771. // Returns whether the assertion was successful (true) or not (false).
  772. func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  773. if h, ok := t.(tHelper); ok {
  774. h.Helper()
  775. }
  776. if assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) {
  777. return
  778. }
  779. t.FailNow()
  780. }
  781. // Implements asserts that an object is implemented by the specified interface.
  782. //
  783. // require.Implements(t, (*MyInterface)(nil), new(MyObject))
  784. func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  785. if h, ok := t.(tHelper); ok {
  786. h.Helper()
  787. }
  788. if assert.Implements(t, interfaceObject, object, msgAndArgs...) {
  789. return
  790. }
  791. t.FailNow()
  792. }
  793. // Implementsf asserts that an object is implemented by the specified interface.
  794. //
  795. // require.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
  796. func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {
  797. if h, ok := t.(tHelper); ok {
  798. h.Helper()
  799. }
  800. if assert.Implementsf(t, interfaceObject, object, msg, args...) {
  801. return
  802. }
  803. t.FailNow()
  804. }
  805. // InDelta asserts that the two numerals are within delta of each other.
  806. //
  807. // require.InDelta(t, math.Pi, 22/7.0, 0.01)
  808. func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  809. if h, ok := t.(tHelper); ok {
  810. h.Helper()
  811. }
  812. if assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
  813. return
  814. }
  815. t.FailNow()
  816. }
  817. // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  818. func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  819. if h, ok := t.(tHelper); ok {
  820. h.Helper()
  821. }
  822. if assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) {
  823. return
  824. }
  825. t.FailNow()
  826. }
  827. // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  828. func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  829. if h, ok := t.(tHelper); ok {
  830. h.Helper()
  831. }
  832. if assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) {
  833. return
  834. }
  835. t.FailNow()
  836. }
  837. // InDeltaSlice is the same as InDelta, except it compares two slices.
  838. func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  839. if h, ok := t.(tHelper); ok {
  840. h.Helper()
  841. }
  842. if assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
  843. return
  844. }
  845. t.FailNow()
  846. }
  847. // InDeltaSlicef is the same as InDelta, except it compares two slices.
  848. func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  849. if h, ok := t.(tHelper); ok {
  850. h.Helper()
  851. }
  852. if assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) {
  853. return
  854. }
  855. t.FailNow()
  856. }
  857. // InDeltaf asserts that the two numerals are within delta of each other.
  858. //
  859. // require.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted")
  860. func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  861. if h, ok := t.(tHelper); ok {
  862. h.Helper()
  863. }
  864. if assert.InDeltaf(t, expected, actual, delta, msg, args...) {
  865. return
  866. }
  867. t.FailNow()
  868. }
  869. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  870. func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  871. if h, ok := t.(tHelper); ok {
  872. h.Helper()
  873. }
  874. if assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
  875. return
  876. }
  877. t.FailNow()
  878. }
  879. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  880. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  881. if h, ok := t.(tHelper); ok {
  882. h.Helper()
  883. }
  884. if assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
  885. return
  886. }
  887. t.FailNow()
  888. }
  889. // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
  890. func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  891. if h, ok := t.(tHelper); ok {
  892. h.Helper()
  893. }
  894. if assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) {
  895. return
  896. }
  897. t.FailNow()
  898. }
  899. // InEpsilonf asserts that expected and actual have a relative error less than epsilon
  900. func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  901. if h, ok := t.(tHelper); ok {
  902. h.Helper()
  903. }
  904. if assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) {
  905. return
  906. }
  907. t.FailNow()
  908. }
  909. // IsDecreasing asserts that the collection is decreasing
  910. //
  911. // require.IsDecreasing(t, []int{2, 1, 0})
  912. // require.IsDecreasing(t, []float{2, 1})
  913. // require.IsDecreasing(t, []string{"b", "a"})
  914. func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  915. if h, ok := t.(tHelper); ok {
  916. h.Helper()
  917. }
  918. if assert.IsDecreasing(t, object, msgAndArgs...) {
  919. return
  920. }
  921. t.FailNow()
  922. }
  923. // IsDecreasingf asserts that the collection is decreasing
  924. //
  925. // require.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted")
  926. // require.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted")
  927. // require.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted")
  928. func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) {
  929. if h, ok := t.(tHelper); ok {
  930. h.Helper()
  931. }
  932. if assert.IsDecreasingf(t, object, msg, args...) {
  933. return
  934. }
  935. t.FailNow()
  936. }
  937. // IsIncreasing asserts that the collection is increasing
  938. //
  939. // require.IsIncreasing(t, []int{1, 2, 3})
  940. // require.IsIncreasing(t, []float{1, 2})
  941. // require.IsIncreasing(t, []string{"a", "b"})
  942. func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  943. if h, ok := t.(tHelper); ok {
  944. h.Helper()
  945. }
  946. if assert.IsIncreasing(t, object, msgAndArgs...) {
  947. return
  948. }
  949. t.FailNow()
  950. }
  951. // IsIncreasingf asserts that the collection is increasing
  952. //
  953. // require.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted")
  954. // require.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted")
  955. // require.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted")
  956. func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) {
  957. if h, ok := t.(tHelper); ok {
  958. h.Helper()
  959. }
  960. if assert.IsIncreasingf(t, object, msg, args...) {
  961. return
  962. }
  963. t.FailNow()
  964. }
  965. // IsNonDecreasing asserts that the collection is not decreasing
  966. //
  967. // require.IsNonDecreasing(t, []int{1, 1, 2})
  968. // require.IsNonDecreasing(t, []float{1, 2})
  969. // require.IsNonDecreasing(t, []string{"a", "b"})
  970. func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  971. if h, ok := t.(tHelper); ok {
  972. h.Helper()
  973. }
  974. if assert.IsNonDecreasing(t, object, msgAndArgs...) {
  975. return
  976. }
  977. t.FailNow()
  978. }
  979. // IsNonDecreasingf asserts that the collection is not decreasing
  980. //
  981. // require.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted")
  982. // require.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted")
  983. // require.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted")
  984. func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) {
  985. if h, ok := t.(tHelper); ok {
  986. h.Helper()
  987. }
  988. if assert.IsNonDecreasingf(t, object, msg, args...) {
  989. return
  990. }
  991. t.FailNow()
  992. }
  993. // IsNonIncreasing asserts that the collection is not increasing
  994. //
  995. // require.IsNonIncreasing(t, []int{2, 1, 1})
  996. // require.IsNonIncreasing(t, []float{2, 1})
  997. // require.IsNonIncreasing(t, []string{"b", "a"})
  998. func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  999. if h, ok := t.(tHelper); ok {
  1000. h.Helper()
  1001. }
  1002. if assert.IsNonIncreasing(t, object, msgAndArgs...) {
  1003. return
  1004. }
  1005. t.FailNow()
  1006. }
  1007. // IsNonIncreasingf asserts that the collection is not increasing
  1008. //
  1009. // require.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted")
  1010. // require.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted")
  1011. // require.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted")
  1012. func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1013. if h, ok := t.(tHelper); ok {
  1014. h.Helper()
  1015. }
  1016. if assert.IsNonIncreasingf(t, object, msg, args...) {
  1017. return
  1018. }
  1019. t.FailNow()
  1020. }
  1021. // IsType asserts that the specified objects are of the same type.
  1022. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
  1023. if h, ok := t.(tHelper); ok {
  1024. h.Helper()
  1025. }
  1026. if assert.IsType(t, expectedType, object, msgAndArgs...) {
  1027. return
  1028. }
  1029. t.FailNow()
  1030. }
  1031. // IsTypef asserts that the specified objects are of the same type.
  1032. func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {
  1033. if h, ok := t.(tHelper); ok {
  1034. h.Helper()
  1035. }
  1036. if assert.IsTypef(t, expectedType, object, msg, args...) {
  1037. return
  1038. }
  1039. t.FailNow()
  1040. }
  1041. // JSONEq asserts that two JSON strings are equivalent.
  1042. //
  1043. // require.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  1044. func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  1045. if h, ok := t.(tHelper); ok {
  1046. h.Helper()
  1047. }
  1048. if assert.JSONEq(t, expected, actual, msgAndArgs...) {
  1049. return
  1050. }
  1051. t.FailNow()
  1052. }
  1053. // JSONEqf asserts that two JSON strings are equivalent.
  1054. //
  1055. // require.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
  1056. func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {
  1057. if h, ok := t.(tHelper); ok {
  1058. h.Helper()
  1059. }
  1060. if assert.JSONEqf(t, expected, actual, msg, args...) {
  1061. return
  1062. }
  1063. t.FailNow()
  1064. }
  1065. // Len asserts that the specified object has specific length.
  1066. // Len also fails if the object has a type that len() not accept.
  1067. //
  1068. // require.Len(t, mySlice, 3)
  1069. func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
  1070. if h, ok := t.(tHelper); ok {
  1071. h.Helper()
  1072. }
  1073. if assert.Len(t, object, length, msgAndArgs...) {
  1074. return
  1075. }
  1076. t.FailNow()
  1077. }
  1078. // Lenf asserts that the specified object has specific length.
  1079. // Lenf also fails if the object has a type that len() not accept.
  1080. //
  1081. // require.Lenf(t, mySlice, 3, "error message %s", "formatted")
  1082. func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) {
  1083. if h, ok := t.(tHelper); ok {
  1084. h.Helper()
  1085. }
  1086. if assert.Lenf(t, object, length, msg, args...) {
  1087. return
  1088. }
  1089. t.FailNow()
  1090. }
  1091. // Less asserts that the first element is less than the second
  1092. //
  1093. // require.Less(t, 1, 2)
  1094. // require.Less(t, float64(1), float64(2))
  1095. // require.Less(t, "a", "b")
  1096. func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  1097. if h, ok := t.(tHelper); ok {
  1098. h.Helper()
  1099. }
  1100. if assert.Less(t, e1, e2, msgAndArgs...) {
  1101. return
  1102. }
  1103. t.FailNow()
  1104. }
  1105. // LessOrEqual asserts that the first element is less than or equal to the second
  1106. //
  1107. // require.LessOrEqual(t, 1, 2)
  1108. // require.LessOrEqual(t, 2, 2)
  1109. // require.LessOrEqual(t, "a", "b")
  1110. // require.LessOrEqual(t, "b", "b")
  1111. func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  1112. if h, ok := t.(tHelper); ok {
  1113. h.Helper()
  1114. }
  1115. if assert.LessOrEqual(t, e1, e2, msgAndArgs...) {
  1116. return
  1117. }
  1118. t.FailNow()
  1119. }
  1120. // LessOrEqualf asserts that the first element is less than or equal to the second
  1121. //
  1122. // require.LessOrEqualf(t, 1, 2, "error message %s", "formatted")
  1123. // require.LessOrEqualf(t, 2, 2, "error message %s", "formatted")
  1124. // require.LessOrEqualf(t, "a", "b", "error message %s", "formatted")
  1125. // require.LessOrEqualf(t, "b", "b", "error message %s", "formatted")
  1126. func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  1127. if h, ok := t.(tHelper); ok {
  1128. h.Helper()
  1129. }
  1130. if assert.LessOrEqualf(t, e1, e2, msg, args...) {
  1131. return
  1132. }
  1133. t.FailNow()
  1134. }
  1135. // Lessf asserts that the first element is less than the second
  1136. //
  1137. // require.Lessf(t, 1, 2, "error message %s", "formatted")
  1138. // require.Lessf(t, float64(1), float64(2), "error message %s", "formatted")
  1139. // require.Lessf(t, "a", "b", "error message %s", "formatted")
  1140. func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  1141. if h, ok := t.(tHelper); ok {
  1142. h.Helper()
  1143. }
  1144. if assert.Lessf(t, e1, e2, msg, args...) {
  1145. return
  1146. }
  1147. t.FailNow()
  1148. }
  1149. // Negative asserts that the specified element is negative
  1150. //
  1151. // require.Negative(t, -1)
  1152. // require.Negative(t, -1.23)
  1153. func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) {
  1154. if h, ok := t.(tHelper); ok {
  1155. h.Helper()
  1156. }
  1157. if assert.Negative(t, e, msgAndArgs...) {
  1158. return
  1159. }
  1160. t.FailNow()
  1161. }
  1162. // Negativef asserts that the specified element is negative
  1163. //
  1164. // require.Negativef(t, -1, "error message %s", "formatted")
  1165. // require.Negativef(t, -1.23, "error message %s", "formatted")
  1166. func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) {
  1167. if h, ok := t.(tHelper); ok {
  1168. h.Helper()
  1169. }
  1170. if assert.Negativef(t, e, msg, args...) {
  1171. return
  1172. }
  1173. t.FailNow()
  1174. }
  1175. // Never asserts that the given condition doesn't satisfy in waitFor time,
  1176. // periodically checking the target function each tick.
  1177. //
  1178. // require.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
  1179. func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
  1180. if h, ok := t.(tHelper); ok {
  1181. h.Helper()
  1182. }
  1183. if assert.Never(t, condition, waitFor, tick, msgAndArgs...) {
  1184. return
  1185. }
  1186. t.FailNow()
  1187. }
  1188. // Neverf asserts that the given condition doesn't satisfy in waitFor time,
  1189. // periodically checking the target function each tick.
  1190. //
  1191. // require.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
  1192. func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
  1193. if h, ok := t.(tHelper); ok {
  1194. h.Helper()
  1195. }
  1196. if assert.Neverf(t, condition, waitFor, tick, msg, args...) {
  1197. return
  1198. }
  1199. t.FailNow()
  1200. }
  1201. // Nil asserts that the specified object is nil.
  1202. //
  1203. // require.Nil(t, err)
  1204. func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  1205. if h, ok := t.(tHelper); ok {
  1206. h.Helper()
  1207. }
  1208. if assert.Nil(t, object, msgAndArgs...) {
  1209. return
  1210. }
  1211. t.FailNow()
  1212. }
  1213. // Nilf asserts that the specified object is nil.
  1214. //
  1215. // require.Nilf(t, err, "error message %s", "formatted")
  1216. func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1217. if h, ok := t.(tHelper); ok {
  1218. h.Helper()
  1219. }
  1220. if assert.Nilf(t, object, msg, args...) {
  1221. return
  1222. }
  1223. t.FailNow()
  1224. }
  1225. // NoDirExists checks whether a directory does not exist in the given path.
  1226. // It fails if the path points to an existing _directory_ only.
  1227. func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) {
  1228. if h, ok := t.(tHelper); ok {
  1229. h.Helper()
  1230. }
  1231. if assert.NoDirExists(t, path, msgAndArgs...) {
  1232. return
  1233. }
  1234. t.FailNow()
  1235. }
  1236. // NoDirExistsf checks whether a directory does not exist in the given path.
  1237. // It fails if the path points to an existing _directory_ only.
  1238. func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) {
  1239. if h, ok := t.(tHelper); ok {
  1240. h.Helper()
  1241. }
  1242. if assert.NoDirExistsf(t, path, msg, args...) {
  1243. return
  1244. }
  1245. t.FailNow()
  1246. }
  1247. // NoError asserts that a function returned no error (i.e. `nil`).
  1248. //
  1249. // actualObj, err := SomeFunction()
  1250. // if require.NoError(t, err) {
  1251. // require.Equal(t, expectedObj, actualObj)
  1252. // }
  1253. func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
  1254. if h, ok := t.(tHelper); ok {
  1255. h.Helper()
  1256. }
  1257. if assert.NoError(t, err, msgAndArgs...) {
  1258. return
  1259. }
  1260. t.FailNow()
  1261. }
  1262. // NoErrorf asserts that a function returned no error (i.e. `nil`).
  1263. //
  1264. // actualObj, err := SomeFunction()
  1265. // if require.NoErrorf(t, err, "error message %s", "formatted") {
  1266. // require.Equal(t, expectedObj, actualObj)
  1267. // }
  1268. func NoErrorf(t TestingT, err error, msg string, args ...interface{}) {
  1269. if h, ok := t.(tHelper); ok {
  1270. h.Helper()
  1271. }
  1272. if assert.NoErrorf(t, err, msg, args...) {
  1273. return
  1274. }
  1275. t.FailNow()
  1276. }
  1277. // NoFileExists checks whether a file does not exist in a given path. It fails
  1278. // if the path points to an existing _file_ only.
  1279. func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) {
  1280. if h, ok := t.(tHelper); ok {
  1281. h.Helper()
  1282. }
  1283. if assert.NoFileExists(t, path, msgAndArgs...) {
  1284. return
  1285. }
  1286. t.FailNow()
  1287. }
  1288. // NoFileExistsf checks whether a file does not exist in a given path. It fails
  1289. // if the path points to an existing _file_ only.
  1290. func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) {
  1291. if h, ok := t.(tHelper); ok {
  1292. h.Helper()
  1293. }
  1294. if assert.NoFileExistsf(t, path, msg, args...) {
  1295. return
  1296. }
  1297. t.FailNow()
  1298. }
  1299. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  1300. // specified substring or element.
  1301. //
  1302. // require.NotContains(t, "Hello World", "Earth")
  1303. // require.NotContains(t, ["Hello", "World"], "Earth")
  1304. // require.NotContains(t, {"Hello": "World"}, "Earth")
  1305. func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  1306. if h, ok := t.(tHelper); ok {
  1307. h.Helper()
  1308. }
  1309. if assert.NotContains(t, s, contains, msgAndArgs...) {
  1310. return
  1311. }
  1312. t.FailNow()
  1313. }
  1314. // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
  1315. // specified substring or element.
  1316. //
  1317. // require.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
  1318. // require.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
  1319. // require.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
  1320. func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
  1321. if h, ok := t.(tHelper); ok {
  1322. h.Helper()
  1323. }
  1324. if assert.NotContainsf(t, s, contains, msg, args...) {
  1325. return
  1326. }
  1327. t.FailNow()
  1328. }
  1329. // NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified
  1330. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  1331. // the number of appearances of each of them in both lists should not match.
  1332. // This is an inverse of ElementsMatch.
  1333. //
  1334. // require.NotElementsMatch(t, [1, 1, 2, 3], [1, 1, 2, 3]) -> false
  1335. //
  1336. // require.NotElementsMatch(t, [1, 1, 2, 3], [1, 2, 3]) -> true
  1337. //
  1338. // require.NotElementsMatch(t, [1, 2, 3], [1, 2, 4]) -> true
  1339. func NotElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
  1340. if h, ok := t.(tHelper); ok {
  1341. h.Helper()
  1342. }
  1343. if assert.NotElementsMatch(t, listA, listB, msgAndArgs...) {
  1344. return
  1345. }
  1346. t.FailNow()
  1347. }
  1348. // NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified
  1349. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  1350. // the number of appearances of each of them in both lists should not match.
  1351. // This is an inverse of ElementsMatch.
  1352. //
  1353. // require.NotElementsMatchf(t, [1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false
  1354. //
  1355. // require.NotElementsMatchf(t, [1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true
  1356. //
  1357. // require.NotElementsMatchf(t, [1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true
  1358. func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) {
  1359. if h, ok := t.(tHelper); ok {
  1360. h.Helper()
  1361. }
  1362. if assert.NotElementsMatchf(t, listA, listB, msg, args...) {
  1363. return
  1364. }
  1365. t.FailNow()
  1366. }
  1367. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  1368. // a slice or a channel with len == 0.
  1369. //
  1370. // if require.NotEmpty(t, obj) {
  1371. // require.Equal(t, "two", obj[1])
  1372. // }
  1373. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  1374. if h, ok := t.(tHelper); ok {
  1375. h.Helper()
  1376. }
  1377. if assert.NotEmpty(t, object, msgAndArgs...) {
  1378. return
  1379. }
  1380. t.FailNow()
  1381. }
  1382. // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  1383. // a slice or a channel with len == 0.
  1384. //
  1385. // if require.NotEmptyf(t, obj, "error message %s", "formatted") {
  1386. // require.Equal(t, "two", obj[1])
  1387. // }
  1388. func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1389. if h, ok := t.(tHelper); ok {
  1390. h.Helper()
  1391. }
  1392. if assert.NotEmptyf(t, object, msg, args...) {
  1393. return
  1394. }
  1395. t.FailNow()
  1396. }
  1397. // NotEqual asserts that the specified values are NOT equal.
  1398. //
  1399. // require.NotEqual(t, obj1, obj2)
  1400. //
  1401. // Pointer variable equality is determined based on the equality of the
  1402. // referenced values (as opposed to the memory addresses).
  1403. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1404. if h, ok := t.(tHelper); ok {
  1405. h.Helper()
  1406. }
  1407. if assert.NotEqual(t, expected, actual, msgAndArgs...) {
  1408. return
  1409. }
  1410. t.FailNow()
  1411. }
  1412. // NotEqualValues asserts that two objects are not equal even when converted to the same type
  1413. //
  1414. // require.NotEqualValues(t, obj1, obj2)
  1415. func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1416. if h, ok := t.(tHelper); ok {
  1417. h.Helper()
  1418. }
  1419. if assert.NotEqualValues(t, expected, actual, msgAndArgs...) {
  1420. return
  1421. }
  1422. t.FailNow()
  1423. }
  1424. // NotEqualValuesf asserts that two objects are not equal even when converted to the same type
  1425. //
  1426. // require.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")
  1427. func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1428. if h, ok := t.(tHelper); ok {
  1429. h.Helper()
  1430. }
  1431. if assert.NotEqualValuesf(t, expected, actual, msg, args...) {
  1432. return
  1433. }
  1434. t.FailNow()
  1435. }
  1436. // NotEqualf asserts that the specified values are NOT equal.
  1437. //
  1438. // require.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
  1439. //
  1440. // Pointer variable equality is determined based on the equality of the
  1441. // referenced values (as opposed to the memory addresses).
  1442. func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1443. if h, ok := t.(tHelper); ok {
  1444. h.Helper()
  1445. }
  1446. if assert.NotEqualf(t, expected, actual, msg, args...) {
  1447. return
  1448. }
  1449. t.FailNow()
  1450. }
  1451. // NotErrorAs asserts that none of the errors in err's chain matches target,
  1452. // but if so, sets target to that error value.
  1453. func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) {
  1454. if h, ok := t.(tHelper); ok {
  1455. h.Helper()
  1456. }
  1457. if assert.NotErrorAs(t, err, target, msgAndArgs...) {
  1458. return
  1459. }
  1460. t.FailNow()
  1461. }
  1462. // NotErrorAsf asserts that none of the errors in err's chain matches target,
  1463. // but if so, sets target to that error value.
  1464. func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) {
  1465. if h, ok := t.(tHelper); ok {
  1466. h.Helper()
  1467. }
  1468. if assert.NotErrorAsf(t, err, target, msg, args...) {
  1469. return
  1470. }
  1471. t.FailNow()
  1472. }
  1473. // NotErrorIs asserts that none of the errors in err's chain matches target.
  1474. // This is a wrapper for errors.Is.
  1475. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) {
  1476. if h, ok := t.(tHelper); ok {
  1477. h.Helper()
  1478. }
  1479. if assert.NotErrorIs(t, err, target, msgAndArgs...) {
  1480. return
  1481. }
  1482. t.FailNow()
  1483. }
  1484. // NotErrorIsf asserts that none of the errors in err's chain matches target.
  1485. // This is a wrapper for errors.Is.
  1486. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) {
  1487. if h, ok := t.(tHelper); ok {
  1488. h.Helper()
  1489. }
  1490. if assert.NotErrorIsf(t, err, target, msg, args...) {
  1491. return
  1492. }
  1493. t.FailNow()
  1494. }
  1495. // NotImplements asserts that an object does not implement the specified interface.
  1496. //
  1497. // require.NotImplements(t, (*MyInterface)(nil), new(MyObject))
  1498. func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  1499. if h, ok := t.(tHelper); ok {
  1500. h.Helper()
  1501. }
  1502. if assert.NotImplements(t, interfaceObject, object, msgAndArgs...) {
  1503. return
  1504. }
  1505. t.FailNow()
  1506. }
  1507. // NotImplementsf asserts that an object does not implement the specified interface.
  1508. //
  1509. // require.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
  1510. func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {
  1511. if h, ok := t.(tHelper); ok {
  1512. h.Helper()
  1513. }
  1514. if assert.NotImplementsf(t, interfaceObject, object, msg, args...) {
  1515. return
  1516. }
  1517. t.FailNow()
  1518. }
  1519. // NotNil asserts that the specified object is not nil.
  1520. //
  1521. // require.NotNil(t, err)
  1522. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  1523. if h, ok := t.(tHelper); ok {
  1524. h.Helper()
  1525. }
  1526. if assert.NotNil(t, object, msgAndArgs...) {
  1527. return
  1528. }
  1529. t.FailNow()
  1530. }
  1531. // NotNilf asserts that the specified object is not nil.
  1532. //
  1533. // require.NotNilf(t, err, "error message %s", "formatted")
  1534. func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1535. if h, ok := t.(tHelper); ok {
  1536. h.Helper()
  1537. }
  1538. if assert.NotNilf(t, object, msg, args...) {
  1539. return
  1540. }
  1541. t.FailNow()
  1542. }
  1543. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  1544. //
  1545. // require.NotPanics(t, func(){ RemainCalm() })
  1546. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1547. if h, ok := t.(tHelper); ok {
  1548. h.Helper()
  1549. }
  1550. if assert.NotPanics(t, f, msgAndArgs...) {
  1551. return
  1552. }
  1553. t.FailNow()
  1554. }
  1555. // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
  1556. //
  1557. // require.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
  1558. func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1559. if h, ok := t.(tHelper); ok {
  1560. h.Helper()
  1561. }
  1562. if assert.NotPanicsf(t, f, msg, args...) {
  1563. return
  1564. }
  1565. t.FailNow()
  1566. }
  1567. // NotRegexp asserts that a specified regexp does not match a string.
  1568. //
  1569. // require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
  1570. // require.NotRegexp(t, "^start", "it's not starting")
  1571. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  1572. if h, ok := t.(tHelper); ok {
  1573. h.Helper()
  1574. }
  1575. if assert.NotRegexp(t, rx, str, msgAndArgs...) {
  1576. return
  1577. }
  1578. t.FailNow()
  1579. }
  1580. // NotRegexpf asserts that a specified regexp does not match a string.
  1581. //
  1582. // require.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")
  1583. // require.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
  1584. func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  1585. if h, ok := t.(tHelper); ok {
  1586. h.Helper()
  1587. }
  1588. if assert.NotRegexpf(t, rx, str, msg, args...) {
  1589. return
  1590. }
  1591. t.FailNow()
  1592. }
  1593. // NotSame asserts that two pointers do not reference the same object.
  1594. //
  1595. // require.NotSame(t, ptr1, ptr2)
  1596. //
  1597. // Both arguments must be pointer variables. Pointer variable sameness is
  1598. // determined based on the equality of both type and value.
  1599. func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1600. if h, ok := t.(tHelper); ok {
  1601. h.Helper()
  1602. }
  1603. if assert.NotSame(t, expected, actual, msgAndArgs...) {
  1604. return
  1605. }
  1606. t.FailNow()
  1607. }
  1608. // NotSamef asserts that two pointers do not reference the same object.
  1609. //
  1610. // require.NotSamef(t, ptr1, ptr2, "error message %s", "formatted")
  1611. //
  1612. // Both arguments must be pointer variables. Pointer variable sameness is
  1613. // determined based on the equality of both type and value.
  1614. func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1615. if h, ok := t.(tHelper); ok {
  1616. h.Helper()
  1617. }
  1618. if assert.NotSamef(t, expected, actual, msg, args...) {
  1619. return
  1620. }
  1621. t.FailNow()
  1622. }
  1623. // NotSubset asserts that the specified list(array, slice...) or map does NOT
  1624. // contain all elements given in the specified subset list(array, slice...) or
  1625. // map.
  1626. //
  1627. // require.NotSubset(t, [1, 3, 4], [1, 2])
  1628. // require.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
  1629. func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  1630. if h, ok := t.(tHelper); ok {
  1631. h.Helper()
  1632. }
  1633. if assert.NotSubset(t, list, subset, msgAndArgs...) {
  1634. return
  1635. }
  1636. t.FailNow()
  1637. }
  1638. // NotSubsetf asserts that the specified list(array, slice...) or map does NOT
  1639. // contain all elements given in the specified subset list(array, slice...) or
  1640. // map.
  1641. //
  1642. // require.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
  1643. // require.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
  1644. func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  1645. if h, ok := t.(tHelper); ok {
  1646. h.Helper()
  1647. }
  1648. if assert.NotSubsetf(t, list, subset, msg, args...) {
  1649. return
  1650. }
  1651. t.FailNow()
  1652. }
  1653. // NotZero asserts that i is not the zero value for its type.
  1654. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  1655. if h, ok := t.(tHelper); ok {
  1656. h.Helper()
  1657. }
  1658. if assert.NotZero(t, i, msgAndArgs...) {
  1659. return
  1660. }
  1661. t.FailNow()
  1662. }
  1663. // NotZerof asserts that i is not the zero value for its type.
  1664. func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  1665. if h, ok := t.(tHelper); ok {
  1666. h.Helper()
  1667. }
  1668. if assert.NotZerof(t, i, msg, args...) {
  1669. return
  1670. }
  1671. t.FailNow()
  1672. }
  1673. // Panics asserts that the code inside the specified PanicTestFunc panics.
  1674. //
  1675. // require.Panics(t, func(){ GoCrazy() })
  1676. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1677. if h, ok := t.(tHelper); ok {
  1678. h.Helper()
  1679. }
  1680. if assert.Panics(t, f, msgAndArgs...) {
  1681. return
  1682. }
  1683. t.FailNow()
  1684. }
  1685. // PanicsWithError asserts that the code inside the specified PanicTestFunc
  1686. // panics, and that the recovered panic value is an error that satisfies the
  1687. // EqualError comparison.
  1688. //
  1689. // require.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
  1690. func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1691. if h, ok := t.(tHelper); ok {
  1692. h.Helper()
  1693. }
  1694. if assert.PanicsWithError(t, errString, f, msgAndArgs...) {
  1695. return
  1696. }
  1697. t.FailNow()
  1698. }
  1699. // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc
  1700. // panics, and that the recovered panic value is an error that satisfies the
  1701. // EqualError comparison.
  1702. //
  1703. // require.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1704. func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1705. if h, ok := t.(tHelper); ok {
  1706. h.Helper()
  1707. }
  1708. if assert.PanicsWithErrorf(t, errString, f, msg, args...) {
  1709. return
  1710. }
  1711. t.FailNow()
  1712. }
  1713. // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
  1714. // the recovered panic value equals the expected panic value.
  1715. //
  1716. // require.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
  1717. func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1718. if h, ok := t.(tHelper); ok {
  1719. h.Helper()
  1720. }
  1721. if assert.PanicsWithValue(t, expected, f, msgAndArgs...) {
  1722. return
  1723. }
  1724. t.FailNow()
  1725. }
  1726. // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
  1727. // the recovered panic value equals the expected panic value.
  1728. //
  1729. // require.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1730. func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1731. if h, ok := t.(tHelper); ok {
  1732. h.Helper()
  1733. }
  1734. if assert.PanicsWithValuef(t, expected, f, msg, args...) {
  1735. return
  1736. }
  1737. t.FailNow()
  1738. }
  1739. // Panicsf asserts that the code inside the specified PanicTestFunc panics.
  1740. //
  1741. // require.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
  1742. func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1743. if h, ok := t.(tHelper); ok {
  1744. h.Helper()
  1745. }
  1746. if assert.Panicsf(t, f, msg, args...) {
  1747. return
  1748. }
  1749. t.FailNow()
  1750. }
  1751. // Positive asserts that the specified element is positive
  1752. //
  1753. // require.Positive(t, 1)
  1754. // require.Positive(t, 1.23)
  1755. func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) {
  1756. if h, ok := t.(tHelper); ok {
  1757. h.Helper()
  1758. }
  1759. if assert.Positive(t, e, msgAndArgs...) {
  1760. return
  1761. }
  1762. t.FailNow()
  1763. }
  1764. // Positivef asserts that the specified element is positive
  1765. //
  1766. // require.Positivef(t, 1, "error message %s", "formatted")
  1767. // require.Positivef(t, 1.23, "error message %s", "formatted")
  1768. func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) {
  1769. if h, ok := t.(tHelper); ok {
  1770. h.Helper()
  1771. }
  1772. if assert.Positivef(t, e, msg, args...) {
  1773. return
  1774. }
  1775. t.FailNow()
  1776. }
  1777. // Regexp asserts that a specified regexp matches a string.
  1778. //
  1779. // require.Regexp(t, regexp.MustCompile("start"), "it's starting")
  1780. // require.Regexp(t, "start...$", "it's not starting")
  1781. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  1782. if h, ok := t.(tHelper); ok {
  1783. h.Helper()
  1784. }
  1785. if assert.Regexp(t, rx, str, msgAndArgs...) {
  1786. return
  1787. }
  1788. t.FailNow()
  1789. }
  1790. // Regexpf asserts that a specified regexp matches a string.
  1791. //
  1792. // require.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")
  1793. // require.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
  1794. func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  1795. if h, ok := t.(tHelper); ok {
  1796. h.Helper()
  1797. }
  1798. if assert.Regexpf(t, rx, str, msg, args...) {
  1799. return
  1800. }
  1801. t.FailNow()
  1802. }
  1803. // Same asserts that two pointers reference the same object.
  1804. //
  1805. // require.Same(t, ptr1, ptr2)
  1806. //
  1807. // Both arguments must be pointer variables. Pointer variable sameness is
  1808. // determined based on the equality of both type and value.
  1809. func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1810. if h, ok := t.(tHelper); ok {
  1811. h.Helper()
  1812. }
  1813. if assert.Same(t, expected, actual, msgAndArgs...) {
  1814. return
  1815. }
  1816. t.FailNow()
  1817. }
  1818. // Samef asserts that two pointers reference the same object.
  1819. //
  1820. // require.Samef(t, ptr1, ptr2, "error message %s", "formatted")
  1821. //
  1822. // Both arguments must be pointer variables. Pointer variable sameness is
  1823. // determined based on the equality of both type and value.
  1824. func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1825. if h, ok := t.(tHelper); ok {
  1826. h.Helper()
  1827. }
  1828. if assert.Samef(t, expected, actual, msg, args...) {
  1829. return
  1830. }
  1831. t.FailNow()
  1832. }
  1833. // Subset asserts that the specified list(array, slice...) or map contains all
  1834. // elements given in the specified subset list(array, slice...) or map.
  1835. //
  1836. // require.Subset(t, [1, 2, 3], [1, 2])
  1837. // require.Subset(t, {"x": 1, "y": 2}, {"x": 1})
  1838. func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  1839. if h, ok := t.(tHelper); ok {
  1840. h.Helper()
  1841. }
  1842. if assert.Subset(t, list, subset, msgAndArgs...) {
  1843. return
  1844. }
  1845. t.FailNow()
  1846. }
  1847. // Subsetf asserts that the specified list(array, slice...) or map contains all
  1848. // elements given in the specified subset list(array, slice...) or map.
  1849. //
  1850. // require.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
  1851. // require.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
  1852. func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  1853. if h, ok := t.(tHelper); ok {
  1854. h.Helper()
  1855. }
  1856. if assert.Subsetf(t, list, subset, msg, args...) {
  1857. return
  1858. }
  1859. t.FailNow()
  1860. }
  1861. // True asserts that the specified value is true.
  1862. //
  1863. // require.True(t, myBool)
  1864. func True(t TestingT, value bool, msgAndArgs ...interface{}) {
  1865. if h, ok := t.(tHelper); ok {
  1866. h.Helper()
  1867. }
  1868. if assert.True(t, value, msgAndArgs...) {
  1869. return
  1870. }
  1871. t.FailNow()
  1872. }
  1873. // Truef asserts that the specified value is true.
  1874. //
  1875. // require.Truef(t, myBool, "error message %s", "formatted")
  1876. func Truef(t TestingT, value bool, msg string, args ...interface{}) {
  1877. if h, ok := t.(tHelper); ok {
  1878. h.Helper()
  1879. }
  1880. if assert.Truef(t, value, msg, args...) {
  1881. return
  1882. }
  1883. t.FailNow()
  1884. }
  1885. // WithinDuration asserts that the two times are within duration delta of each other.
  1886. //
  1887. // require.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
  1888. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  1889. if h, ok := t.(tHelper); ok {
  1890. h.Helper()
  1891. }
  1892. if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
  1893. return
  1894. }
  1895. t.FailNow()
  1896. }
  1897. // WithinDurationf asserts that the two times are within duration delta of each other.
  1898. //
  1899. // require.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
  1900. func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {
  1901. if h, ok := t.(tHelper); ok {
  1902. h.Helper()
  1903. }
  1904. if assert.WithinDurationf(t, expected, actual, delta, msg, args...) {
  1905. return
  1906. }
  1907. t.FailNow()
  1908. }
  1909. // WithinRange asserts that a time is within a time range (inclusive).
  1910. //
  1911. // require.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
  1912. func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) {
  1913. if h, ok := t.(tHelper); ok {
  1914. h.Helper()
  1915. }
  1916. if assert.WithinRange(t, actual, start, end, msgAndArgs...) {
  1917. return
  1918. }
  1919. t.FailNow()
  1920. }
  1921. // WithinRangef asserts that a time is within a time range (inclusive).
  1922. //
  1923. // require.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted")
  1924. func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) {
  1925. if h, ok := t.(tHelper); ok {
  1926. h.Helper()
  1927. }
  1928. if assert.WithinRangef(t, actual, start, end, msg, args...) {
  1929. return
  1930. }
  1931. t.FailNow()
  1932. }
  1933. // YAMLEq asserts that two YAML strings are equivalent.
  1934. func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  1935. if h, ok := t.(tHelper); ok {
  1936. h.Helper()
  1937. }
  1938. if assert.YAMLEq(t, expected, actual, msgAndArgs...) {
  1939. return
  1940. }
  1941. t.FailNow()
  1942. }
  1943. // YAMLEqf asserts that two YAML strings are equivalent.
  1944. func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {
  1945. if h, ok := t.(tHelper); ok {
  1946. h.Helper()
  1947. }
  1948. if assert.YAMLEqf(t, expected, actual, msg, args...) {
  1949. return
  1950. }
  1951. t.FailNow()
  1952. }
  1953. // Zero asserts that i is the zero value for its type.
  1954. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  1955. if h, ok := t.(tHelper); ok {
  1956. h.Helper()
  1957. }
  1958. if assert.Zero(t, i, msgAndArgs...) {
  1959. return
  1960. }
  1961. t.FailNow()
  1962. }
  1963. // Zerof asserts that i is the zero value for its type.
  1964. func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  1965. if h, ok := t.(tHelper); ok {
  1966. h.Helper()
  1967. }
  1968. if assert.Zerof(t, i, msg, args...) {
  1969. return
  1970. }
  1971. t.FailNow()
  1972. }