本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1434 lines
42KB

  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 if the path is a file rather a directory or there is an error checking whether it exists.
  63. func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {
  64. if h, ok := t.(tHelper); ok {
  65. h.Helper()
  66. }
  67. if assert.DirExists(t, path, msgAndArgs...) {
  68. return
  69. }
  70. t.FailNow()
  71. }
  72. // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
  73. func DirExistsf(t TestingT, path string, msg string, args ...interface{}) {
  74. if h, ok := t.(tHelper); ok {
  75. h.Helper()
  76. }
  77. if assert.DirExistsf(t, path, msg, args...) {
  78. return
  79. }
  80. t.FailNow()
  81. }
  82. // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
  83. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  84. // the number of appearances of each of them in both lists should match.
  85. //
  86. // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
  87. func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
  88. if h, ok := t.(tHelper); ok {
  89. h.Helper()
  90. }
  91. if assert.ElementsMatch(t, listA, listB, msgAndArgs...) {
  92. return
  93. }
  94. t.FailNow()
  95. }
  96. // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
  97. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  98. // the number of appearances of each of them in both lists should match.
  99. //
  100. // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
  101. func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) {
  102. if h, ok := t.(tHelper); ok {
  103. h.Helper()
  104. }
  105. if assert.ElementsMatchf(t, listA, listB, msg, args...) {
  106. return
  107. }
  108. t.FailNow()
  109. }
  110. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  111. // a slice or a channel with len == 0.
  112. //
  113. // assert.Empty(t, obj)
  114. func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  115. if h, ok := t.(tHelper); ok {
  116. h.Helper()
  117. }
  118. if assert.Empty(t, object, msgAndArgs...) {
  119. return
  120. }
  121. t.FailNow()
  122. }
  123. // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  124. // a slice or a channel with len == 0.
  125. //
  126. // assert.Emptyf(t, obj, "error message %s", "formatted")
  127. func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  128. if h, ok := t.(tHelper); ok {
  129. h.Helper()
  130. }
  131. if assert.Emptyf(t, object, msg, args...) {
  132. return
  133. }
  134. t.FailNow()
  135. }
  136. // Equal asserts that two objects are equal.
  137. //
  138. // assert.Equal(t, 123, 123)
  139. //
  140. // Pointer variable equality is determined based on the equality of the
  141. // referenced values (as opposed to the memory addresses). Function equality
  142. // cannot be determined and will always fail.
  143. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  144. if h, ok := t.(tHelper); ok {
  145. h.Helper()
  146. }
  147. if assert.Equal(t, expected, actual, msgAndArgs...) {
  148. return
  149. }
  150. t.FailNow()
  151. }
  152. // EqualError asserts that a function returned an error (i.e. not `nil`)
  153. // and that it is equal to the provided error.
  154. //
  155. // actualObj, err := SomeFunction()
  156. // assert.EqualError(t, err, expectedErrorString)
  157. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
  158. if h, ok := t.(tHelper); ok {
  159. h.Helper()
  160. }
  161. if assert.EqualError(t, theError, errString, msgAndArgs...) {
  162. return
  163. }
  164. t.FailNow()
  165. }
  166. // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
  167. // and that it is equal to the provided error.
  168. //
  169. // actualObj, err := SomeFunction()
  170. // assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
  171. func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) {
  172. if h, ok := t.(tHelper); ok {
  173. h.Helper()
  174. }
  175. if assert.EqualErrorf(t, theError, errString, msg, args...) {
  176. return
  177. }
  178. t.FailNow()
  179. }
  180. // EqualValues asserts that two objects are equal or convertable to the same types
  181. // and equal.
  182. //
  183. // assert.EqualValues(t, uint32(123), int32(123))
  184. func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  185. if h, ok := t.(tHelper); ok {
  186. h.Helper()
  187. }
  188. if assert.EqualValues(t, expected, actual, msgAndArgs...) {
  189. return
  190. }
  191. t.FailNow()
  192. }
  193. // EqualValuesf asserts that two objects are equal or convertable to the same types
  194. // and equal.
  195. //
  196. // assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123))
  197. func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  198. if h, ok := t.(tHelper); ok {
  199. h.Helper()
  200. }
  201. if assert.EqualValuesf(t, expected, actual, msg, args...) {
  202. return
  203. }
  204. t.FailNow()
  205. }
  206. // Equalf asserts that two objects are equal.
  207. //
  208. // assert.Equalf(t, 123, 123, "error message %s", "formatted")
  209. //
  210. // Pointer variable equality is determined based on the equality of the
  211. // referenced values (as opposed to the memory addresses). Function equality
  212. // cannot be determined and will always fail.
  213. func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  214. if h, ok := t.(tHelper); ok {
  215. h.Helper()
  216. }
  217. if assert.Equalf(t, expected, actual, msg, args...) {
  218. return
  219. }
  220. t.FailNow()
  221. }
  222. // Error asserts that a function returned an error (i.e. not `nil`).
  223. //
  224. // actualObj, err := SomeFunction()
  225. // if assert.Error(t, err) {
  226. // assert.Equal(t, expectedError, err)
  227. // }
  228. func Error(t TestingT, err error, msgAndArgs ...interface{}) {
  229. if h, ok := t.(tHelper); ok {
  230. h.Helper()
  231. }
  232. if assert.Error(t, err, msgAndArgs...) {
  233. return
  234. }
  235. t.FailNow()
  236. }
  237. // Errorf asserts that a function returned an error (i.e. not `nil`).
  238. //
  239. // actualObj, err := SomeFunction()
  240. // if assert.Errorf(t, err, "error message %s", "formatted") {
  241. // assert.Equal(t, expectedErrorf, err)
  242. // }
  243. func Errorf(t TestingT, err error, msg string, args ...interface{}) {
  244. if h, ok := t.(tHelper); ok {
  245. h.Helper()
  246. }
  247. if assert.Errorf(t, err, msg, args...) {
  248. return
  249. }
  250. t.FailNow()
  251. }
  252. // Eventually asserts that given condition will be met in waitFor time,
  253. // periodically checking target function each tick.
  254. //
  255. // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
  256. func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
  257. if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) {
  258. return
  259. }
  260. if h, ok := t.(tHelper); ok {
  261. h.Helper()
  262. }
  263. t.FailNow()
  264. }
  265. // Eventuallyf asserts that given condition will be met in waitFor time,
  266. // periodically checking target function each tick.
  267. //
  268. // assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
  269. func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
  270. if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) {
  271. return
  272. }
  273. if h, ok := t.(tHelper); ok {
  274. h.Helper()
  275. }
  276. t.FailNow()
  277. }
  278. // Exactly asserts that two objects are equal in value and type.
  279. //
  280. // assert.Exactly(t, int32(123), int64(123))
  281. func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  282. if h, ok := t.(tHelper); ok {
  283. h.Helper()
  284. }
  285. if assert.Exactly(t, expected, actual, msgAndArgs...) {
  286. return
  287. }
  288. t.FailNow()
  289. }
  290. // Exactlyf asserts that two objects are equal in value and type.
  291. //
  292. // assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123))
  293. func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  294. if h, ok := t.(tHelper); ok {
  295. h.Helper()
  296. }
  297. if assert.Exactlyf(t, expected, actual, msg, args...) {
  298. return
  299. }
  300. t.FailNow()
  301. }
  302. // Fail reports a failure through
  303. func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  304. if h, ok := t.(tHelper); ok {
  305. h.Helper()
  306. }
  307. if assert.Fail(t, failureMessage, msgAndArgs...) {
  308. return
  309. }
  310. t.FailNow()
  311. }
  312. // FailNow fails test
  313. func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  314. if h, ok := t.(tHelper); ok {
  315. h.Helper()
  316. }
  317. if assert.FailNow(t, failureMessage, msgAndArgs...) {
  318. return
  319. }
  320. t.FailNow()
  321. }
  322. // FailNowf fails test
  323. func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {
  324. if h, ok := t.(tHelper); ok {
  325. h.Helper()
  326. }
  327. if assert.FailNowf(t, failureMessage, msg, args...) {
  328. return
  329. }
  330. t.FailNow()
  331. }
  332. // Failf reports a failure through
  333. func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) {
  334. if h, ok := t.(tHelper); ok {
  335. h.Helper()
  336. }
  337. if assert.Failf(t, failureMessage, msg, args...) {
  338. return
  339. }
  340. t.FailNow()
  341. }
  342. // False asserts that the specified value is false.
  343. //
  344. // assert.False(t, myBool)
  345. func False(t TestingT, value bool, msgAndArgs ...interface{}) {
  346. if h, ok := t.(tHelper); ok {
  347. h.Helper()
  348. }
  349. if assert.False(t, value, msgAndArgs...) {
  350. return
  351. }
  352. t.FailNow()
  353. }
  354. // Falsef asserts that the specified value is false.
  355. //
  356. // assert.Falsef(t, myBool, "error message %s", "formatted")
  357. func Falsef(t TestingT, value bool, msg string, args ...interface{}) {
  358. if h, ok := t.(tHelper); ok {
  359. h.Helper()
  360. }
  361. if assert.Falsef(t, value, msg, args...) {
  362. return
  363. }
  364. t.FailNow()
  365. }
  366. // FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
  367. func FileExists(t TestingT, path string, msgAndArgs ...interface{}) {
  368. if h, ok := t.(tHelper); ok {
  369. h.Helper()
  370. }
  371. if assert.FileExists(t, path, msgAndArgs...) {
  372. return
  373. }
  374. t.FailNow()
  375. }
  376. // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
  377. func FileExistsf(t TestingT, path string, msg string, args ...interface{}) {
  378. if h, ok := t.(tHelper); ok {
  379. h.Helper()
  380. }
  381. if assert.FileExistsf(t, path, msg, args...) {
  382. return
  383. }
  384. t.FailNow()
  385. }
  386. // Greater asserts that the first element is greater than the second
  387. //
  388. // assert.Greater(t, 2, 1)
  389. // assert.Greater(t, float64(2), float64(1))
  390. // assert.Greater(t, "b", "a")
  391. func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  392. if h, ok := t.(tHelper); ok {
  393. h.Helper()
  394. }
  395. if assert.Greater(t, e1, e2, msgAndArgs...) {
  396. return
  397. }
  398. t.FailNow()
  399. }
  400. // GreaterOrEqual asserts that the first element is greater than or equal to the second
  401. //
  402. // assert.GreaterOrEqual(t, 2, 1)
  403. // assert.GreaterOrEqual(t, 2, 2)
  404. // assert.GreaterOrEqual(t, "b", "a")
  405. // assert.GreaterOrEqual(t, "b", "b")
  406. func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  407. if h, ok := t.(tHelper); ok {
  408. h.Helper()
  409. }
  410. if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) {
  411. return
  412. }
  413. t.FailNow()
  414. }
  415. // GreaterOrEqualf asserts that the first element is greater than or equal to the second
  416. //
  417. // assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")
  418. // assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")
  419. // assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")
  420. // assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")
  421. func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  422. if h, ok := t.(tHelper); ok {
  423. h.Helper()
  424. }
  425. if assert.GreaterOrEqualf(t, e1, e2, msg, args...) {
  426. return
  427. }
  428. t.FailNow()
  429. }
  430. // Greaterf asserts that the first element is greater than the second
  431. //
  432. // assert.Greaterf(t, 2, 1, "error message %s", "formatted")
  433. // assert.Greaterf(t, float64(2, "error message %s", "formatted"), float64(1))
  434. // assert.Greaterf(t, "b", "a", "error message %s", "formatted")
  435. func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  436. if h, ok := t.(tHelper); ok {
  437. h.Helper()
  438. }
  439. if assert.Greaterf(t, e1, e2, msg, args...) {
  440. return
  441. }
  442. t.FailNow()
  443. }
  444. // HTTPBodyContains asserts that a specified handler returns a
  445. // body that contains a string.
  446. //
  447. // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  448. //
  449. // Returns whether the assertion was successful (true) or not (false).
  450. func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  451. if h, ok := t.(tHelper); ok {
  452. h.Helper()
  453. }
  454. if assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) {
  455. return
  456. }
  457. t.FailNow()
  458. }
  459. // HTTPBodyContainsf asserts that a specified handler returns a
  460. // body that contains a string.
  461. //
  462. // assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  463. //
  464. // Returns whether the assertion was successful (true) or not (false).
  465. func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  466. if h, ok := t.(tHelper); ok {
  467. h.Helper()
  468. }
  469. if assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) {
  470. return
  471. }
  472. t.FailNow()
  473. }
  474. // HTTPBodyNotContains asserts that a specified handler returns a
  475. // body that does not contain a string.
  476. //
  477. // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  478. //
  479. // Returns whether the assertion was successful (true) or not (false).
  480. func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  481. if h, ok := t.(tHelper); ok {
  482. h.Helper()
  483. }
  484. if assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) {
  485. return
  486. }
  487. t.FailNow()
  488. }
  489. // HTTPBodyNotContainsf asserts that a specified handler returns a
  490. // body that does not contain a string.
  491. //
  492. // assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  493. //
  494. // Returns whether the assertion was successful (true) or not (false).
  495. func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  496. if h, ok := t.(tHelper); ok {
  497. h.Helper()
  498. }
  499. if assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) {
  500. return
  501. }
  502. t.FailNow()
  503. }
  504. // HTTPError asserts that a specified handler returns an error status code.
  505. //
  506. // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  507. //
  508. // Returns whether the assertion was successful (true) or not (false).
  509. func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  510. if h, ok := t.(tHelper); ok {
  511. h.Helper()
  512. }
  513. if assert.HTTPError(t, handler, method, url, values, msgAndArgs...) {
  514. return
  515. }
  516. t.FailNow()
  517. }
  518. // HTTPErrorf asserts that a specified handler returns an error status code.
  519. //
  520. // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  521. //
  522. // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
  523. func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  524. if h, ok := t.(tHelper); ok {
  525. h.Helper()
  526. }
  527. if assert.HTTPErrorf(t, handler, method, url, values, msg, args...) {
  528. return
  529. }
  530. t.FailNow()
  531. }
  532. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  533. //
  534. // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  535. //
  536. // Returns whether the assertion was successful (true) or not (false).
  537. func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  538. if h, ok := t.(tHelper); ok {
  539. h.Helper()
  540. }
  541. if assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) {
  542. return
  543. }
  544. t.FailNow()
  545. }
  546. // HTTPRedirectf asserts that a specified handler returns a redirect status code.
  547. //
  548. // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  549. //
  550. // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
  551. func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  552. if h, ok := t.(tHelper); ok {
  553. h.Helper()
  554. }
  555. if assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) {
  556. return
  557. }
  558. t.FailNow()
  559. }
  560. // HTTPSuccess asserts that a specified handler returns a success status code.
  561. //
  562. // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
  563. //
  564. // Returns whether the assertion was successful (true) or not (false).
  565. func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  566. if h, ok := t.(tHelper); ok {
  567. h.Helper()
  568. }
  569. if assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) {
  570. return
  571. }
  572. t.FailNow()
  573. }
  574. // HTTPSuccessf asserts that a specified handler returns a success status code.
  575. //
  576. // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
  577. //
  578. // Returns whether the assertion was successful (true) or not (false).
  579. func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  580. if h, ok := t.(tHelper); ok {
  581. h.Helper()
  582. }
  583. if assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) {
  584. return
  585. }
  586. t.FailNow()
  587. }
  588. // Implements asserts that an object is implemented by the specified interface.
  589. //
  590. // assert.Implements(t, (*MyInterface)(nil), new(MyObject))
  591. func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  592. if h, ok := t.(tHelper); ok {
  593. h.Helper()
  594. }
  595. if assert.Implements(t, interfaceObject, object, msgAndArgs...) {
  596. return
  597. }
  598. t.FailNow()
  599. }
  600. // Implementsf asserts that an object is implemented by the specified interface.
  601. //
  602. // assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject))
  603. func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {
  604. if h, ok := t.(tHelper); ok {
  605. h.Helper()
  606. }
  607. if assert.Implementsf(t, interfaceObject, object, msg, args...) {
  608. return
  609. }
  610. t.FailNow()
  611. }
  612. // InDelta asserts that the two numerals are within delta of each other.
  613. //
  614. // assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
  615. func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  616. if h, ok := t.(tHelper); ok {
  617. h.Helper()
  618. }
  619. if assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
  620. return
  621. }
  622. t.FailNow()
  623. }
  624. // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  625. func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  626. if h, ok := t.(tHelper); ok {
  627. h.Helper()
  628. }
  629. if assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) {
  630. return
  631. }
  632. t.FailNow()
  633. }
  634. // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  635. func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  636. if h, ok := t.(tHelper); ok {
  637. h.Helper()
  638. }
  639. if assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) {
  640. return
  641. }
  642. t.FailNow()
  643. }
  644. // InDeltaSlice is the same as InDelta, except it compares two slices.
  645. func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  646. if h, ok := t.(tHelper); ok {
  647. h.Helper()
  648. }
  649. if assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
  650. return
  651. }
  652. t.FailNow()
  653. }
  654. // InDeltaSlicef is the same as InDelta, except it compares two slices.
  655. func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  656. if h, ok := t.(tHelper); ok {
  657. h.Helper()
  658. }
  659. if assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) {
  660. return
  661. }
  662. t.FailNow()
  663. }
  664. // InDeltaf asserts that the two numerals are within delta of each other.
  665. //
  666. // assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01)
  667. func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  668. if h, ok := t.(tHelper); ok {
  669. h.Helper()
  670. }
  671. if assert.InDeltaf(t, expected, actual, delta, msg, args...) {
  672. return
  673. }
  674. t.FailNow()
  675. }
  676. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  677. func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  678. if h, ok := t.(tHelper); ok {
  679. h.Helper()
  680. }
  681. if assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
  682. return
  683. }
  684. t.FailNow()
  685. }
  686. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  687. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  688. if h, ok := t.(tHelper); ok {
  689. h.Helper()
  690. }
  691. if assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
  692. return
  693. }
  694. t.FailNow()
  695. }
  696. // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
  697. func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  698. if h, ok := t.(tHelper); ok {
  699. h.Helper()
  700. }
  701. if assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) {
  702. return
  703. }
  704. t.FailNow()
  705. }
  706. // InEpsilonf asserts that expected and actual have a relative error less than epsilon
  707. func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  708. if h, ok := t.(tHelper); ok {
  709. h.Helper()
  710. }
  711. if assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) {
  712. return
  713. }
  714. t.FailNow()
  715. }
  716. // IsType asserts that the specified objects are of the same type.
  717. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
  718. if h, ok := t.(tHelper); ok {
  719. h.Helper()
  720. }
  721. if assert.IsType(t, expectedType, object, msgAndArgs...) {
  722. return
  723. }
  724. t.FailNow()
  725. }
  726. // IsTypef asserts that the specified objects are of the same type.
  727. func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {
  728. if h, ok := t.(tHelper); ok {
  729. h.Helper()
  730. }
  731. if assert.IsTypef(t, expectedType, object, msg, args...) {
  732. return
  733. }
  734. t.FailNow()
  735. }
  736. // JSONEq asserts that two JSON strings are equivalent.
  737. //
  738. // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  739. func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  740. if h, ok := t.(tHelper); ok {
  741. h.Helper()
  742. }
  743. if assert.JSONEq(t, expected, actual, msgAndArgs...) {
  744. return
  745. }
  746. t.FailNow()
  747. }
  748. // JSONEqf asserts that two JSON strings are equivalent.
  749. //
  750. // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
  751. func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {
  752. if h, ok := t.(tHelper); ok {
  753. h.Helper()
  754. }
  755. if assert.JSONEqf(t, expected, actual, msg, args...) {
  756. return
  757. }
  758. t.FailNow()
  759. }
  760. // YAMLEq asserts that two YAML strings are equivalent.
  761. func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  762. if h, ok := t.(tHelper); ok {
  763. h.Helper()
  764. }
  765. if assert.YAMLEq(t, expected, actual, msgAndArgs...) {
  766. return
  767. }
  768. t.FailNow()
  769. }
  770. // YAMLEqf asserts that two YAML strings are equivalent.
  771. func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {
  772. if h, ok := t.(tHelper); ok {
  773. h.Helper()
  774. }
  775. if assert.YAMLEqf(t, expected, actual, msg, args...) {
  776. return
  777. }
  778. t.FailNow()
  779. }
  780. // Len asserts that the specified object has specific length.
  781. // Len also fails if the object has a type that len() not accept.
  782. //
  783. // assert.Len(t, mySlice, 3)
  784. func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
  785. if h, ok := t.(tHelper); ok {
  786. h.Helper()
  787. }
  788. if assert.Len(t, object, length, msgAndArgs...) {
  789. return
  790. }
  791. t.FailNow()
  792. }
  793. // Lenf asserts that the specified object has specific length.
  794. // Lenf also fails if the object has a type that len() not accept.
  795. //
  796. // assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
  797. func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) {
  798. if h, ok := t.(tHelper); ok {
  799. h.Helper()
  800. }
  801. if assert.Lenf(t, object, length, msg, args...) {
  802. return
  803. }
  804. t.FailNow()
  805. }
  806. // Less asserts that the first element is less than the second
  807. //
  808. // assert.Less(t, 1, 2)
  809. // assert.Less(t, float64(1), float64(2))
  810. // assert.Less(t, "a", "b")
  811. func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  812. if h, ok := t.(tHelper); ok {
  813. h.Helper()
  814. }
  815. if assert.Less(t, e1, e2, msgAndArgs...) {
  816. return
  817. }
  818. t.FailNow()
  819. }
  820. // LessOrEqual asserts that the first element is less than or equal to the second
  821. //
  822. // assert.LessOrEqual(t, 1, 2)
  823. // assert.LessOrEqual(t, 2, 2)
  824. // assert.LessOrEqual(t, "a", "b")
  825. // assert.LessOrEqual(t, "b", "b")
  826. func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
  827. if h, ok := t.(tHelper); ok {
  828. h.Helper()
  829. }
  830. if assert.LessOrEqual(t, e1, e2, msgAndArgs...) {
  831. return
  832. }
  833. t.FailNow()
  834. }
  835. // LessOrEqualf asserts that the first element is less than or equal to the second
  836. //
  837. // assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted")
  838. // assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted")
  839. // assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted")
  840. // assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted")
  841. func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  842. if h, ok := t.(tHelper); ok {
  843. h.Helper()
  844. }
  845. if assert.LessOrEqualf(t, e1, e2, msg, args...) {
  846. return
  847. }
  848. t.FailNow()
  849. }
  850. // Lessf asserts that the first element is less than the second
  851. //
  852. // assert.Lessf(t, 1, 2, "error message %s", "formatted")
  853. // assert.Lessf(t, float64(1, "error message %s", "formatted"), float64(2))
  854. // assert.Lessf(t, "a", "b", "error message %s", "formatted")
  855. func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {
  856. if h, ok := t.(tHelper); ok {
  857. h.Helper()
  858. }
  859. if assert.Lessf(t, e1, e2, msg, args...) {
  860. return
  861. }
  862. t.FailNow()
  863. }
  864. // Nil asserts that the specified object is nil.
  865. //
  866. // assert.Nil(t, err)
  867. func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  868. if h, ok := t.(tHelper); ok {
  869. h.Helper()
  870. }
  871. if assert.Nil(t, object, msgAndArgs...) {
  872. return
  873. }
  874. t.FailNow()
  875. }
  876. // Nilf asserts that the specified object is nil.
  877. //
  878. // assert.Nilf(t, err, "error message %s", "formatted")
  879. func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  880. if h, ok := t.(tHelper); ok {
  881. h.Helper()
  882. }
  883. if assert.Nilf(t, object, msg, args...) {
  884. return
  885. }
  886. t.FailNow()
  887. }
  888. // NoError asserts that a function returned no error (i.e. `nil`).
  889. //
  890. // actualObj, err := SomeFunction()
  891. // if assert.NoError(t, err) {
  892. // assert.Equal(t, expectedObj, actualObj)
  893. // }
  894. func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
  895. if h, ok := t.(tHelper); ok {
  896. h.Helper()
  897. }
  898. if assert.NoError(t, err, msgAndArgs...) {
  899. return
  900. }
  901. t.FailNow()
  902. }
  903. // NoErrorf asserts that a function returned no error (i.e. `nil`).
  904. //
  905. // actualObj, err := SomeFunction()
  906. // if assert.NoErrorf(t, err, "error message %s", "formatted") {
  907. // assert.Equal(t, expectedObj, actualObj)
  908. // }
  909. func NoErrorf(t TestingT, err error, msg string, args ...interface{}) {
  910. if h, ok := t.(tHelper); ok {
  911. h.Helper()
  912. }
  913. if assert.NoErrorf(t, err, msg, args...) {
  914. return
  915. }
  916. t.FailNow()
  917. }
  918. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  919. // specified substring or element.
  920. //
  921. // assert.NotContains(t, "Hello World", "Earth")
  922. // assert.NotContains(t, ["Hello", "World"], "Earth")
  923. // assert.NotContains(t, {"Hello": "World"}, "Earth")
  924. func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  925. if h, ok := t.(tHelper); ok {
  926. h.Helper()
  927. }
  928. if assert.NotContains(t, s, contains, msgAndArgs...) {
  929. return
  930. }
  931. t.FailNow()
  932. }
  933. // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
  934. // specified substring or element.
  935. //
  936. // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
  937. // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
  938. // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
  939. func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {
  940. if h, ok := t.(tHelper); ok {
  941. h.Helper()
  942. }
  943. if assert.NotContainsf(t, s, contains, msg, args...) {
  944. return
  945. }
  946. t.FailNow()
  947. }
  948. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  949. // a slice or a channel with len == 0.
  950. //
  951. // if assert.NotEmpty(t, obj) {
  952. // assert.Equal(t, "two", obj[1])
  953. // }
  954. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  955. if h, ok := t.(tHelper); ok {
  956. h.Helper()
  957. }
  958. if assert.NotEmpty(t, object, msgAndArgs...) {
  959. return
  960. }
  961. t.FailNow()
  962. }
  963. // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  964. // a slice or a channel with len == 0.
  965. //
  966. // if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
  967. // assert.Equal(t, "two", obj[1])
  968. // }
  969. func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) {
  970. if h, ok := t.(tHelper); ok {
  971. h.Helper()
  972. }
  973. if assert.NotEmptyf(t, object, msg, args...) {
  974. return
  975. }
  976. t.FailNow()
  977. }
  978. // NotEqual asserts that the specified values are NOT equal.
  979. //
  980. // assert.NotEqual(t, obj1, obj2)
  981. //
  982. // Pointer variable equality is determined based on the equality of the
  983. // referenced values (as opposed to the memory addresses).
  984. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  985. if h, ok := t.(tHelper); ok {
  986. h.Helper()
  987. }
  988. if assert.NotEqual(t, expected, actual, msgAndArgs...) {
  989. return
  990. }
  991. t.FailNow()
  992. }
  993. // NotEqualf asserts that the specified values are NOT equal.
  994. //
  995. // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
  996. //
  997. // Pointer variable equality is determined based on the equality of the
  998. // referenced values (as opposed to the memory addresses).
  999. func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1000. if h, ok := t.(tHelper); ok {
  1001. h.Helper()
  1002. }
  1003. if assert.NotEqualf(t, expected, actual, msg, args...) {
  1004. return
  1005. }
  1006. t.FailNow()
  1007. }
  1008. // NotNil asserts that the specified object is not nil.
  1009. //
  1010. // assert.NotNil(t, err)
  1011. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  1012. if h, ok := t.(tHelper); ok {
  1013. h.Helper()
  1014. }
  1015. if assert.NotNil(t, object, msgAndArgs...) {
  1016. return
  1017. }
  1018. t.FailNow()
  1019. }
  1020. // NotNilf asserts that the specified object is not nil.
  1021. //
  1022. // assert.NotNilf(t, err, "error message %s", "formatted")
  1023. func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) {
  1024. if h, ok := t.(tHelper); ok {
  1025. h.Helper()
  1026. }
  1027. if assert.NotNilf(t, object, msg, args...) {
  1028. return
  1029. }
  1030. t.FailNow()
  1031. }
  1032. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  1033. //
  1034. // assert.NotPanics(t, func(){ RemainCalm() })
  1035. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1036. if h, ok := t.(tHelper); ok {
  1037. h.Helper()
  1038. }
  1039. if assert.NotPanics(t, f, msgAndArgs...) {
  1040. return
  1041. }
  1042. t.FailNow()
  1043. }
  1044. // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
  1045. //
  1046. // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
  1047. func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1048. if h, ok := t.(tHelper); ok {
  1049. h.Helper()
  1050. }
  1051. if assert.NotPanicsf(t, f, msg, args...) {
  1052. return
  1053. }
  1054. t.FailNow()
  1055. }
  1056. // NotRegexp asserts that a specified regexp does not match a string.
  1057. //
  1058. // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
  1059. // assert.NotRegexp(t, "^start", "it's not starting")
  1060. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  1061. if h, ok := t.(tHelper); ok {
  1062. h.Helper()
  1063. }
  1064. if assert.NotRegexp(t, rx, str, msgAndArgs...) {
  1065. return
  1066. }
  1067. t.FailNow()
  1068. }
  1069. // NotRegexpf asserts that a specified regexp does not match a string.
  1070. //
  1071. // assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
  1072. // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
  1073. func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  1074. if h, ok := t.(tHelper); ok {
  1075. h.Helper()
  1076. }
  1077. if assert.NotRegexpf(t, rx, str, msg, args...) {
  1078. return
  1079. }
  1080. t.FailNow()
  1081. }
  1082. // NotSubset asserts that the specified list(array, slice...) contains not all
  1083. // elements given in the specified subset(array, slice...).
  1084. //
  1085. // assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
  1086. func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  1087. if h, ok := t.(tHelper); ok {
  1088. h.Helper()
  1089. }
  1090. if assert.NotSubset(t, list, subset, msgAndArgs...) {
  1091. return
  1092. }
  1093. t.FailNow()
  1094. }
  1095. // NotSubsetf asserts that the specified list(array, slice...) contains not all
  1096. // elements given in the specified subset(array, slice...).
  1097. //
  1098. // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")
  1099. func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  1100. if h, ok := t.(tHelper); ok {
  1101. h.Helper()
  1102. }
  1103. if assert.NotSubsetf(t, list, subset, msg, args...) {
  1104. return
  1105. }
  1106. t.FailNow()
  1107. }
  1108. // NotZero asserts that i is not the zero value for its type.
  1109. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  1110. if h, ok := t.(tHelper); ok {
  1111. h.Helper()
  1112. }
  1113. if assert.NotZero(t, i, msgAndArgs...) {
  1114. return
  1115. }
  1116. t.FailNow()
  1117. }
  1118. // NotZerof asserts that i is not the zero value for its type.
  1119. func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  1120. if h, ok := t.(tHelper); ok {
  1121. h.Helper()
  1122. }
  1123. if assert.NotZerof(t, i, msg, args...) {
  1124. return
  1125. }
  1126. t.FailNow()
  1127. }
  1128. // Panics asserts that the code inside the specified PanicTestFunc panics.
  1129. //
  1130. // assert.Panics(t, func(){ GoCrazy() })
  1131. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1132. if h, ok := t.(tHelper); ok {
  1133. h.Helper()
  1134. }
  1135. if assert.Panics(t, f, msgAndArgs...) {
  1136. return
  1137. }
  1138. t.FailNow()
  1139. }
  1140. // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
  1141. // the recovered panic value equals the expected panic value.
  1142. //
  1143. // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
  1144. func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  1145. if h, ok := t.(tHelper); ok {
  1146. h.Helper()
  1147. }
  1148. if assert.PanicsWithValue(t, expected, f, msgAndArgs...) {
  1149. return
  1150. }
  1151. t.FailNow()
  1152. }
  1153. // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
  1154. // the recovered panic value equals the expected panic value.
  1155. //
  1156. // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1157. func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1158. if h, ok := t.(tHelper); ok {
  1159. h.Helper()
  1160. }
  1161. if assert.PanicsWithValuef(t, expected, f, msg, args...) {
  1162. return
  1163. }
  1164. t.FailNow()
  1165. }
  1166. // Panicsf asserts that the code inside the specified PanicTestFunc panics.
  1167. //
  1168. // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
  1169. func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {
  1170. if h, ok := t.(tHelper); ok {
  1171. h.Helper()
  1172. }
  1173. if assert.Panicsf(t, f, msg, args...) {
  1174. return
  1175. }
  1176. t.FailNow()
  1177. }
  1178. // Regexp asserts that a specified regexp matches a string.
  1179. //
  1180. // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
  1181. // assert.Regexp(t, "start...$", "it's not starting")
  1182. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  1183. if h, ok := t.(tHelper); ok {
  1184. h.Helper()
  1185. }
  1186. if assert.Regexp(t, rx, str, msgAndArgs...) {
  1187. return
  1188. }
  1189. t.FailNow()
  1190. }
  1191. // Regexpf asserts that a specified regexp matches a string.
  1192. //
  1193. // assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
  1194. // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
  1195. func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {
  1196. if h, ok := t.(tHelper); ok {
  1197. h.Helper()
  1198. }
  1199. if assert.Regexpf(t, rx, str, msg, args...) {
  1200. return
  1201. }
  1202. t.FailNow()
  1203. }
  1204. // Same asserts that two pointers reference the same object.
  1205. //
  1206. // assert.Same(t, ptr1, ptr2)
  1207. //
  1208. // Both arguments must be pointer variables. Pointer variable sameness is
  1209. // determined based on the equality of both type and value.
  1210. func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  1211. if h, ok := t.(tHelper); ok {
  1212. h.Helper()
  1213. }
  1214. if assert.Same(t, expected, actual, msgAndArgs...) {
  1215. return
  1216. }
  1217. t.FailNow()
  1218. }
  1219. // Samef asserts that two pointers reference the same object.
  1220. //
  1221. // assert.Samef(t, ptr1, ptr2, "error message %s", "formatted")
  1222. //
  1223. // Both arguments must be pointer variables. Pointer variable sameness is
  1224. // determined based on the equality of both type and value.
  1225. func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {
  1226. if h, ok := t.(tHelper); ok {
  1227. h.Helper()
  1228. }
  1229. if assert.Samef(t, expected, actual, msg, args...) {
  1230. return
  1231. }
  1232. t.FailNow()
  1233. }
  1234. // Subset asserts that the specified list(array, slice...) contains all
  1235. // elements given in the specified subset(array, slice...).
  1236. //
  1237. // assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
  1238. func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  1239. if h, ok := t.(tHelper); ok {
  1240. h.Helper()
  1241. }
  1242. if assert.Subset(t, list, subset, msgAndArgs...) {
  1243. return
  1244. }
  1245. t.FailNow()
  1246. }
  1247. // Subsetf asserts that the specified list(array, slice...) contains all
  1248. // elements given in the specified subset(array, slice...).
  1249. //
  1250. // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")
  1251. func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {
  1252. if h, ok := t.(tHelper); ok {
  1253. h.Helper()
  1254. }
  1255. if assert.Subsetf(t, list, subset, msg, args...) {
  1256. return
  1257. }
  1258. t.FailNow()
  1259. }
  1260. // True asserts that the specified value is true.
  1261. //
  1262. // assert.True(t, myBool)
  1263. func True(t TestingT, value bool, msgAndArgs ...interface{}) {
  1264. if h, ok := t.(tHelper); ok {
  1265. h.Helper()
  1266. }
  1267. if assert.True(t, value, msgAndArgs...) {
  1268. return
  1269. }
  1270. t.FailNow()
  1271. }
  1272. // Truef asserts that the specified value is true.
  1273. //
  1274. // assert.Truef(t, myBool, "error message %s", "formatted")
  1275. func Truef(t TestingT, value bool, msg string, args ...interface{}) {
  1276. if h, ok := t.(tHelper); ok {
  1277. h.Helper()
  1278. }
  1279. if assert.Truef(t, value, msg, args...) {
  1280. return
  1281. }
  1282. t.FailNow()
  1283. }
  1284. // WithinDuration asserts that the two times are within duration delta of each other.
  1285. //
  1286. // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
  1287. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  1288. if h, ok := t.(tHelper); ok {
  1289. h.Helper()
  1290. }
  1291. if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
  1292. return
  1293. }
  1294. t.FailNow()
  1295. }
  1296. // WithinDurationf asserts that the two times are within duration delta of each other.
  1297. //
  1298. // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
  1299. func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {
  1300. if h, ok := t.(tHelper); ok {
  1301. h.Helper()
  1302. }
  1303. if assert.WithinDurationf(t, expected, actual, delta, msg, args...) {
  1304. return
  1305. }
  1306. t.FailNow()
  1307. }
  1308. // Zero asserts that i is the zero value for its type.
  1309. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  1310. if h, ok := t.(tHelper); ok {
  1311. h.Helper()
  1312. }
  1313. if assert.Zero(t, i, msgAndArgs...) {
  1314. return
  1315. }
  1316. t.FailNow()
  1317. }
  1318. // Zerof asserts that i is the zero value for its type.
  1319. func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) {
  1320. if h, ok := t.(tHelper); ok {
  1321. h.Helper()
  1322. }
  1323. if assert.Zerof(t, i, msg, args...) {
  1324. return
  1325. }
  1326. t.FailNow()
  1327. }
上海开阖软件有限公司 沪ICP备12045867号-1