require.go 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060
  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. // assert.Contains(t, "Hello World", "World")
  33. // assert.Contains(t, ["Hello", "World"], "World")
  34. // assert.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. // assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
  48. // assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
  49. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
  188. // assert.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. // assert.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true
  207. // assert.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 same types
  218. // and equal.
  219. //
  220. // assert.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 same types
  231. // and equal.
  232. //
  233. // assert.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. // assert.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 assert.Error(t, err) {
  263. // assert.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. // assert.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. // assert.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 assert.Errorf(t, err, "error message %s", "formatted") {
  350. // assert.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. // assert.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. // assert.EventuallyWithT(t, func(c *assert.CollectT) {
  389. // // add assertions as needed; any assertion failure will fail the current tick
  390. // assert.True(c, externalValue, "expected 'externalValue' to be true")
  391. // }, 1*time.Second, 10*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. // assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") {
  416. // // add assertions as needed; any assertion failure will fail the current tick
  417. // assert.True(c, externalValue, "expected 'externalValue' to be true")
  418. // }, 1*time.Second, 10*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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.Greater(t, 2, 1)
  554. // assert.Greater(t, float64(2), float64(1))
  555. // assert.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. // assert.GreaterOrEqual(t, 2, 1)
  568. // assert.GreaterOrEqual(t, 2, 2)
  569. // assert.GreaterOrEqual(t, "b", "a")
  570. // assert.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. // assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")
  583. // assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")
  584. // assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")
  585. // assert.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. // assert.Greaterf(t, 2, 1, "error message %s", "formatted")
  598. // assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted")
  599. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.IsDecreasing(t, []int{2, 1, 0})
  912. // assert.IsDecreasing(t, []float{2, 1})
  913. // assert.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. // assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted")
  926. // assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted")
  927. // assert.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. // assert.IsIncreasing(t, []int{1, 2, 3})
  940. // assert.IsIncreasing(t, []float{1, 2})
  941. // assert.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. // assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted")
  954. // assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted")
  955. // assert.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. // assert.IsNonDecreasing(t, []int{1, 1, 2})
  968. // assert.IsNonDecreasing(t, []float{1, 2})
  969. // assert.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. // assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted")
  982. // assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted")
  983. // assert.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. // assert.IsNonIncreasing(t, []int{2, 1, 1})
  996. // assert.IsNonIncreasing(t, []float{2, 1})
  997. // assert.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. // assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted")
  1010. // assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted")
  1011. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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. // assert.Less(t, 1, 2)
  1094. // assert.Less(t, float64(1), float64(2))
  1095. // assert.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. // assert.LessOrEqual(t, 1, 2)
  1108. // assert.LessOrEqual(t, 2, 2)
  1109. // assert.LessOrEqual(t, "a", "b")
  1110. // assert.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. // assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted")
  1123. // assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted")
  1124. // assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted")
  1125. // assert.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. // assert.Lessf(t, 1, 2, "error message %s", "formatted")
  1138. // assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted")
  1139. // assert.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. // assert.Negative(t, -1)
  1152. // assert.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. // assert.Negativef(t, -1, "error message %s", "formatted")
  1165. // assert.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. // assert.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. // assert.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. // assert.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. // assert.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 assert.NoError(t, err) {
  1251. // assert.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 assert.NoErrorf(t, err, "error message %s", "formatted") {
  1266. // assert.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. // assert.NotContains(t, "Hello World", "Earth")
  1303. // assert.NotContains(t, ["Hello", "World"], "Earth")
  1304. // assert.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. // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
  1318. // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
  1319. // assert.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. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  1330. // a slice or a channel with len == 0.
  1331. //
  1332. // if assert.NotEmpty(t, obj) {
  1333. // assert.Equal(t, "two", obj[1])
  1334. // }
  1335. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  1336. if h, ok := t.(tHelper); ok {
  1337. h.Helper()
  1338. }
  1339. if assert.NotEmpty(t, object, msgAndArgs...) {
  1340. return
  1341. }
  1342. t.FailNow()
  1343. }
  1344. // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  1345. // a slice or a channel with len == 0.
  1346. //
  1347. // if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
  1348. // assert.Equal(t, "two", obj[1])
  1349. // }
  1350. func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1351. if h, ok := t.(tHelper); ok {
  1352. h.Helper()
  1353. }
  1354. if assert.NotEmptyf(t, object, msg, args...) {
  1355. return
  1356. }
  1357. t.FailNow()
  1358. }
  1359. // NotEqual asserts that the specified values are NOT equal.
  1360. //
  1361. // assert.NotEqual(t, obj1, obj2)
  1362. //
  1363. // Pointer variable equality is determined based on the equality of the
  1364. // referenced values (as opposed to the memory addresses).
  1365. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1366. if h, ok := t.(tHelper); ok {
  1367. h.Helper()
  1368. }
  1369. if assert.NotEqual(t, expected, actual, msgAndArgs...) {
  1370. return
  1371. }
  1372. t.FailNow()
  1373. }
  1374. // NotEqualValues asserts that two objects are not equal even when converted to the same type
  1375. //
  1376. // assert.NotEqualValues(t, obj1, obj2)
  1377. func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1378. if h, ok := t.(tHelper); ok {
  1379. h.Helper()
  1380. }
  1381. if assert.NotEqualValues(t, expected, actual, msgAndArgs...) {
  1382. return
  1383. }
  1384. t.FailNow()
  1385. }
  1386. // NotEqualValuesf asserts that two objects are not equal even when converted to the same type
  1387. //
  1388. // assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")
  1389. func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1390. if h, ok := t.(tHelper); ok {
  1391. h.Helper()
  1392. }
  1393. if assert.NotEqualValuesf(t, expected, actual, msg, args...) {
  1394. return
  1395. }
  1396. t.FailNow()
  1397. }
  1398. // NotEqualf asserts that the specified values are NOT equal.
  1399. //
  1400. // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
  1401. //
  1402. // Pointer variable equality is determined based on the equality of the
  1403. // referenced values (as opposed to the memory addresses).
  1404. func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1405. if h, ok := t.(tHelper); ok {
  1406. h.Helper()
  1407. }
  1408. if assert.NotEqualf(t, expected, actual, msg, args...) {
  1409. return
  1410. }
  1411. t.FailNow()
  1412. }
  1413. // NotErrorIs asserts that at none of the errors in err's chain matches target.
  1414. // This is a wrapper for errors.Is.
  1415. func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) {
  1416. if h, ok := t.(tHelper); ok {
  1417. h.Helper()
  1418. }
  1419. if assert.NotErrorIs(t, err, target, msgAndArgs...) {
  1420. return
  1421. }
  1422. t.FailNow()
  1423. }
  1424. // NotErrorIsf asserts that at none of the errors in err's chain matches target.
  1425. // This is a wrapper for errors.Is.
  1426. func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) {
  1427. if h, ok := t.(tHelper); ok {
  1428. h.Helper()
  1429. }
  1430. if assert.NotErrorIsf(t, err, target, msg, args...) {
  1431. return
  1432. }
  1433. t.FailNow()
  1434. }
  1435. // NotImplements asserts that an object does not implement the specified interface.
  1436. //
  1437. // assert.NotImplements(t, (*MyInterface)(nil), new(MyObject))
  1438. func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  1439. if h, ok := t.(tHelper); ok {
  1440. h.Helper()
  1441. }
  1442. if assert.NotImplements(t, interfaceObject, object, msgAndArgs...) {
  1443. return
  1444. }
  1445. t.FailNow()
  1446. }
  1447. // NotImplementsf asserts that an object does not implement the specified interface.
  1448. //
  1449. // assert.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
  1450. func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {
  1451. if h, ok := t.(tHelper); ok {
  1452. h.Helper()
  1453. }
  1454. if assert.NotImplementsf(t, interfaceObject, object, msg, args...) {
  1455. return
  1456. }
  1457. t.FailNow()
  1458. }
  1459. // NotNil asserts that the specified object is not nil.
  1460. //
  1461. // assert.NotNil(t, err)
  1462. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  1463. if h, ok := t.(tHelper); ok {
  1464. h.Helper()
  1465. }
  1466. if assert.NotNil(t, object, msgAndArgs...) {
  1467. return
  1468. }
  1469. t.FailNow()
  1470. }
  1471. // NotNilf asserts that the specified object is not nil.
  1472. //
  1473. // assert.NotNilf(t, err, "error message %s", "formatted")
  1474. func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1475. if h, ok := t.(tHelper); ok {
  1476. h.Helper()
  1477. }
  1478. if assert.NotNilf(t, object, msg, args...) {
  1479. return
  1480. }
  1481. t.FailNow()
  1482. }
  1483. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  1484. //
  1485. // assert.NotPanics(t, func(){ RemainCalm() })
  1486. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1487. if h, ok := t.(tHelper); ok {
  1488. h.Helper()
  1489. }
  1490. if assert.NotPanics(t, f, msgAndArgs...) {
  1491. return
  1492. }
  1493. t.FailNow()
  1494. }
  1495. // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
  1496. //
  1497. // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
  1498. func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1499. if h, ok := t.(tHelper); ok {
  1500. h.Helper()
  1501. }
  1502. if assert.NotPanicsf(t, f, msg, args...) {
  1503. return
  1504. }
  1505. t.FailNow()
  1506. }
  1507. // NotRegexp asserts that a specified regexp does not match a string.
  1508. //
  1509. // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
  1510. // assert.NotRegexp(t, "^start", "it's not starting")
  1511. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  1512. if h, ok := t.(tHelper); ok {
  1513. h.Helper()
  1514. }
  1515. if assert.NotRegexp(t, rx, str, msgAndArgs...) {
  1516. return
  1517. }
  1518. t.FailNow()
  1519. }
  1520. // NotRegexpf asserts that a specified regexp does not match a string.
  1521. //
  1522. // assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")
  1523. // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
  1524. func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  1525. if h, ok := t.(tHelper); ok {
  1526. h.Helper()
  1527. }
  1528. if assert.NotRegexpf(t, rx, str, msg, args...) {
  1529. return
  1530. }
  1531. t.FailNow()
  1532. }
  1533. // NotSame asserts that two pointers do not reference the same object.
  1534. //
  1535. // assert.NotSame(t, ptr1, ptr2)
  1536. //
  1537. // Both arguments must be pointer variables. Pointer variable sameness is
  1538. // determined based on the equality of both type and value.
  1539. func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1540. if h, ok := t.(tHelper); ok {
  1541. h.Helper()
  1542. }
  1543. if assert.NotSame(t, expected, actual, msgAndArgs...) {
  1544. return
  1545. }
  1546. t.FailNow()
  1547. }
  1548. // NotSamef asserts that two pointers do not reference the same object.
  1549. //
  1550. // assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted")
  1551. //
  1552. // Both arguments must be pointer variables. Pointer variable sameness is
  1553. // determined based on the equality of both type and value.
  1554. func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1555. if h, ok := t.(tHelper); ok {
  1556. h.Helper()
  1557. }
  1558. if assert.NotSamef(t, expected, actual, msg, args...) {
  1559. return
  1560. }
  1561. t.FailNow()
  1562. }
  1563. // NotSubset asserts that the specified list(array, slice...) or map does NOT
  1564. // contain all elements given in the specified subset list(array, slice...) or
  1565. // map.
  1566. //
  1567. // assert.NotSubset(t, [1, 3, 4], [1, 2])
  1568. // assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
  1569. func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  1570. if h, ok := t.(tHelper); ok {
  1571. h.Helper()
  1572. }
  1573. if assert.NotSubset(t, list, subset, msgAndArgs...) {
  1574. return
  1575. }
  1576. t.FailNow()
  1577. }
  1578. // NotSubsetf asserts that the specified list(array, slice...) or map does NOT
  1579. // contain all elements given in the specified subset list(array, slice...) or
  1580. // map.
  1581. //
  1582. // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
  1583. // assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
  1584. func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  1585. if h, ok := t.(tHelper); ok {
  1586. h.Helper()
  1587. }
  1588. if assert.NotSubsetf(t, list, subset, msg, args...) {
  1589. return
  1590. }
  1591. t.FailNow()
  1592. }
  1593. // NotZero asserts that i is not the zero value for its type.
  1594. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  1595. if h, ok := t.(tHelper); ok {
  1596. h.Helper()
  1597. }
  1598. if assert.NotZero(t, i, msgAndArgs...) {
  1599. return
  1600. }
  1601. t.FailNow()
  1602. }
  1603. // NotZerof asserts that i is not the zero value for its type.
  1604. func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  1605. if h, ok := t.(tHelper); ok {
  1606. h.Helper()
  1607. }
  1608. if assert.NotZerof(t, i, msg, args...) {
  1609. return
  1610. }
  1611. t.FailNow()
  1612. }
  1613. // Panics asserts that the code inside the specified PanicTestFunc panics.
  1614. //
  1615. // assert.Panics(t, func(){ GoCrazy() })
  1616. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1617. if h, ok := t.(tHelper); ok {
  1618. h.Helper()
  1619. }
  1620. if assert.Panics(t, f, msgAndArgs...) {
  1621. return
  1622. }
  1623. t.FailNow()
  1624. }
  1625. // PanicsWithError asserts that the code inside the specified PanicTestFunc
  1626. // panics, and that the recovered panic value is an error that satisfies the
  1627. // EqualError comparison.
  1628. //
  1629. // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
  1630. func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1631. if h, ok := t.(tHelper); ok {
  1632. h.Helper()
  1633. }
  1634. if assert.PanicsWithError(t, errString, f, msgAndArgs...) {
  1635. return
  1636. }
  1637. t.FailNow()
  1638. }
  1639. // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc
  1640. // panics, and that the recovered panic value is an error that satisfies the
  1641. // EqualError comparison.
  1642. //
  1643. // assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1644. func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1645. if h, ok := t.(tHelper); ok {
  1646. h.Helper()
  1647. }
  1648. if assert.PanicsWithErrorf(t, errString, f, msg, args...) {
  1649. return
  1650. }
  1651. t.FailNow()
  1652. }
  1653. // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
  1654. // the recovered panic value equals the expected panic value.
  1655. //
  1656. // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
  1657. func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1658. if h, ok := t.(tHelper); ok {
  1659. h.Helper()
  1660. }
  1661. if assert.PanicsWithValue(t, expected, f, msgAndArgs...) {
  1662. return
  1663. }
  1664. t.FailNow()
  1665. }
  1666. // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
  1667. // the recovered panic value equals the expected panic value.
  1668. //
  1669. // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1670. func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1671. if h, ok := t.(tHelper); ok {
  1672. h.Helper()
  1673. }
  1674. if assert.PanicsWithValuef(t, expected, f, msg, args...) {
  1675. return
  1676. }
  1677. t.FailNow()
  1678. }
  1679. // Panicsf asserts that the code inside the specified PanicTestFunc panics.
  1680. //
  1681. // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
  1682. func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1683. if h, ok := t.(tHelper); ok {
  1684. h.Helper()
  1685. }
  1686. if assert.Panicsf(t, f, msg, args...) {
  1687. return
  1688. }
  1689. t.FailNow()
  1690. }
  1691. // Positive asserts that the specified element is positive
  1692. //
  1693. // assert.Positive(t, 1)
  1694. // assert.Positive(t, 1.23)
  1695. func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) {
  1696. if h, ok := t.(tHelper); ok {
  1697. h.Helper()
  1698. }
  1699. if assert.Positive(t, e, msgAndArgs...) {
  1700. return
  1701. }
  1702. t.FailNow()
  1703. }
  1704. // Positivef asserts that the specified element is positive
  1705. //
  1706. // assert.Positivef(t, 1, "error message %s", "formatted")
  1707. // assert.Positivef(t, 1.23, "error message %s", "formatted")
  1708. func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) {
  1709. if h, ok := t.(tHelper); ok {
  1710. h.Helper()
  1711. }
  1712. if assert.Positivef(t, e, msg, args...) {
  1713. return
  1714. }
  1715. t.FailNow()
  1716. }
  1717. // Regexp asserts that a specified regexp matches a string.
  1718. //
  1719. // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
  1720. // assert.Regexp(t, "start...$", "it's not starting")
  1721. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  1722. if h, ok := t.(tHelper); ok {
  1723. h.Helper()
  1724. }
  1725. if assert.Regexp(t, rx, str, msgAndArgs...) {
  1726. return
  1727. }
  1728. t.FailNow()
  1729. }
  1730. // Regexpf asserts that a specified regexp matches a string.
  1731. //
  1732. // assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")
  1733. // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
  1734. func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  1735. if h, ok := t.(tHelper); ok {
  1736. h.Helper()
  1737. }
  1738. if assert.Regexpf(t, rx, str, msg, args...) {
  1739. return
  1740. }
  1741. t.FailNow()
  1742. }
  1743. // Same asserts that two pointers reference the same object.
  1744. //
  1745. // assert.Same(t, ptr1, ptr2)
  1746. //
  1747. // Both arguments must be pointer variables. Pointer variable sameness is
  1748. // determined based on the equality of both type and value.
  1749. func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1750. if h, ok := t.(tHelper); ok {
  1751. h.Helper()
  1752. }
  1753. if assert.Same(t, expected, actual, msgAndArgs...) {
  1754. return
  1755. }
  1756. t.FailNow()
  1757. }
  1758. // Samef asserts that two pointers reference the same object.
  1759. //
  1760. // assert.Samef(t, ptr1, ptr2, "error message %s", "formatted")
  1761. //
  1762. // Both arguments must be pointer variables. Pointer variable sameness is
  1763. // determined based on the equality of both type and value.
  1764. func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1765. if h, ok := t.(tHelper); ok {
  1766. h.Helper()
  1767. }
  1768. if assert.Samef(t, expected, actual, msg, args...) {
  1769. return
  1770. }
  1771. t.FailNow()
  1772. }
  1773. // Subset asserts that the specified list(array, slice...) or map contains all
  1774. // elements given in the specified subset list(array, slice...) or map.
  1775. //
  1776. // assert.Subset(t, [1, 2, 3], [1, 2])
  1777. // assert.Subset(t, {"x": 1, "y": 2}, {"x": 1})
  1778. func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  1779. if h, ok := t.(tHelper); ok {
  1780. h.Helper()
  1781. }
  1782. if assert.Subset(t, list, subset, msgAndArgs...) {
  1783. return
  1784. }
  1785. t.FailNow()
  1786. }
  1787. // Subsetf asserts that the specified list(array, slice...) or map contains all
  1788. // elements given in the specified subset list(array, slice...) or map.
  1789. //
  1790. // assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
  1791. // assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
  1792. func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  1793. if h, ok := t.(tHelper); ok {
  1794. h.Helper()
  1795. }
  1796. if assert.Subsetf(t, list, subset, msg, args...) {
  1797. return
  1798. }
  1799. t.FailNow()
  1800. }
  1801. // True asserts that the specified value is true.
  1802. //
  1803. // assert.True(t, myBool)
  1804. func True(t TestingT, value bool, msgAndArgs ...interface{}) {
  1805. if h, ok := t.(tHelper); ok {
  1806. h.Helper()
  1807. }
  1808. if assert.True(t, value, msgAndArgs...) {
  1809. return
  1810. }
  1811. t.FailNow()
  1812. }
  1813. // Truef asserts that the specified value is true.
  1814. //
  1815. // assert.Truef(t, myBool, "error message %s", "formatted")
  1816. func Truef(t TestingT, value bool, msg string, args ...interface{}) {
  1817. if h, ok := t.(tHelper); ok {
  1818. h.Helper()
  1819. }
  1820. if assert.Truef(t, value, msg, args...) {
  1821. return
  1822. }
  1823. t.FailNow()
  1824. }
  1825. // WithinDuration asserts that the two times are within duration delta of each other.
  1826. //
  1827. // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
  1828. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  1829. if h, ok := t.(tHelper); ok {
  1830. h.Helper()
  1831. }
  1832. if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
  1833. return
  1834. }
  1835. t.FailNow()
  1836. }
  1837. // WithinDurationf asserts that the two times are within duration delta of each other.
  1838. //
  1839. // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
  1840. func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {
  1841. if h, ok := t.(tHelper); ok {
  1842. h.Helper()
  1843. }
  1844. if assert.WithinDurationf(t, expected, actual, delta, msg, args...) {
  1845. return
  1846. }
  1847. t.FailNow()
  1848. }
  1849. // WithinRange asserts that a time is within a time range (inclusive).
  1850. //
  1851. // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
  1852. func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) {
  1853. if h, ok := t.(tHelper); ok {
  1854. h.Helper()
  1855. }
  1856. if assert.WithinRange(t, actual, start, end, msgAndArgs...) {
  1857. return
  1858. }
  1859. t.FailNow()
  1860. }
  1861. // WithinRangef asserts that a time is within a time range (inclusive).
  1862. //
  1863. // assert.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted")
  1864. func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) {
  1865. if h, ok := t.(tHelper); ok {
  1866. h.Helper()
  1867. }
  1868. if assert.WithinRangef(t, actual, start, end, msg, args...) {
  1869. return
  1870. }
  1871. t.FailNow()
  1872. }
  1873. // YAMLEq asserts that two YAML strings are equivalent.
  1874. func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  1875. if h, ok := t.(tHelper); ok {
  1876. h.Helper()
  1877. }
  1878. if assert.YAMLEq(t, expected, actual, msgAndArgs...) {
  1879. return
  1880. }
  1881. t.FailNow()
  1882. }
  1883. // YAMLEqf asserts that two YAML strings are equivalent.
  1884. func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {
  1885. if h, ok := t.(tHelper); ok {
  1886. h.Helper()
  1887. }
  1888. if assert.YAMLEqf(t, expected, actual, msg, args...) {
  1889. return
  1890. }
  1891. t.FailNow()
  1892. }
  1893. // Zero asserts that i is the zero value for its type.
  1894. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  1895. if h, ok := t.(tHelper); ok {
  1896. h.Helper()
  1897. }
  1898. if assert.Zero(t, i, msgAndArgs...) {
  1899. return
  1900. }
  1901. t.FailNow()
  1902. }
  1903. // Zerof asserts that i is the zero value for its type.
  1904. func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  1905. if h, ok := t.(tHelper); ok {
  1906. h.Helper()
  1907. }
  1908. if assert.Zerof(t, i, msg, args...) {
  1909. return
  1910. }
  1911. t.FailNow()
  1912. }