require.go 61 KB

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