require.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. "github.com/json-iterator/go/assert"
  8. "time"
  9. )
  10. // Condition uses a Comparison to assert a complex condition.
  11. func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
  12. if !assert.Condition(t, comp, msgAndArgs...) {
  13. t.FailNow()
  14. }
  15. }
  16. // Contains asserts that the specified string, list(array, slice...) or map contains the
  17. // specified substring or element.
  18. //
  19. // assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'")
  20. // assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
  21. // assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
  22. //
  23. // Returns whether the assertion was successful (true) or not (false).
  24. func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  25. if !assert.Contains(t, s, contains, msgAndArgs...) {
  26. t.FailNow()
  27. }
  28. }
  29. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  30. // a slice or a channel with len == 0.
  31. //
  32. // assert.Empty(t, obj)
  33. //
  34. // Returns whether the assertion was successful (true) or not (false).
  35. func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  36. if !assert.Empty(t, object, msgAndArgs...) {
  37. t.FailNow()
  38. }
  39. }
  40. // Equal asserts that two objects are equal.
  41. //
  42. // assert.Equal(t, 123, 123, "123 and 123 should be equal")
  43. //
  44. // Returns whether the assertion was successful (true) or not (false).
  45. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  46. if !assert.Equal(t, expected, actual, msgAndArgs...) {
  47. t.FailNow()
  48. }
  49. }
  50. // EqualError asserts that a function returned an error (i.e. not `nil`)
  51. // and that it is equal to the provided error.
  52. //
  53. // actualObj, err := SomeFunction()
  54. // assert.EqualError(t, err, expectedErrorString, "An error was expected")
  55. //
  56. // Returns whether the assertion was successful (true) or not (false).
  57. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
  58. if !assert.EqualError(t, theError, errString, msgAndArgs...) {
  59. t.FailNow()
  60. }
  61. }
  62. // EqualValues asserts that two objects are equal or convertable to the same types
  63. // and equal.
  64. //
  65. // assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal")
  66. //
  67. // Returns whether the assertion was successful (true) or not (false).
  68. func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  69. if !assert.EqualValues(t, expected, actual, msgAndArgs...) {
  70. t.FailNow()
  71. }
  72. }
  73. // Error asserts that a function returned an error (i.e. not `nil`).
  74. //
  75. // actualObj, err := SomeFunction()
  76. // if assert.Error(t, err, "An error was expected") {
  77. // assert.Equal(t, err, expectedError)
  78. // }
  79. //
  80. // Returns whether the assertion was successful (true) or not (false).
  81. func Error(t TestingT, err error, msgAndArgs ...interface{}) {
  82. if !assert.Error(t, err, msgAndArgs...) {
  83. t.FailNow()
  84. }
  85. }
  86. // Exactly asserts that two objects are equal is value and type.
  87. //
  88. // assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal")
  89. //
  90. // Returns whether the assertion was successful (true) or not (false).
  91. func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  92. if !assert.Exactly(t, expected, actual, msgAndArgs...) {
  93. t.FailNow()
  94. }
  95. }
  96. // Fail reports a failure through
  97. func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  98. if !assert.Fail(t, failureMessage, msgAndArgs...) {
  99. t.FailNow()
  100. }
  101. }
  102. // FailNow fails test
  103. func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  104. if !assert.FailNow(t, failureMessage, msgAndArgs...) {
  105. t.FailNow()
  106. }
  107. }
  108. // False asserts that the specified value is false.
  109. //
  110. // assert.False(t, myBool, "myBool should be false")
  111. //
  112. // Returns whether the assertion was successful (true) or not (false).
  113. func False(t TestingT, value bool, msgAndArgs ...interface{}) {
  114. if !assert.False(t, value, msgAndArgs...) {
  115. t.FailNow()
  116. }
  117. }
  118. // Implements asserts that an object is implemented by the specified interface.
  119. //
  120. // assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
  121. func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  122. if !assert.Implements(t, interfaceObject, object, msgAndArgs...) {
  123. t.FailNow()
  124. }
  125. }
  126. // InDelta asserts that the two numerals are within delta of each other.
  127. //
  128. // assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
  129. //
  130. // Returns whether the assertion was successful (true) or not (false).
  131. func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  132. if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
  133. t.FailNow()
  134. }
  135. }
  136. // InDeltaSlice is the same as InDelta, except it compares two slices.
  137. func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  138. if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
  139. t.FailNow()
  140. }
  141. }
  142. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  143. //
  144. // Returns whether the assertion was successful (true) or not (false).
  145. func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  146. if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
  147. t.FailNow()
  148. }
  149. }
  150. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  151. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  152. if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
  153. t.FailNow()
  154. }
  155. }
  156. // IsType asserts that the specified objects are of the same type.
  157. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
  158. if !assert.IsType(t, expectedType, object, msgAndArgs...) {
  159. t.FailNow()
  160. }
  161. }
  162. // JSONEq asserts that two JSON strings are equivalent.
  163. //
  164. // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  165. //
  166. // Returns whether the assertion was successful (true) or not (false).
  167. func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  168. if !assert.JSONEq(t, expected, actual, msgAndArgs...) {
  169. t.FailNow()
  170. }
  171. }
  172. // Len asserts that the specified object has specific length.
  173. // Len also fails if the object has a type that len() not accept.
  174. //
  175. // assert.Len(t, mySlice, 3, "The size of slice is not 3")
  176. //
  177. // Returns whether the assertion was successful (true) or not (false).
  178. func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
  179. if !assert.Len(t, object, length, msgAndArgs...) {
  180. t.FailNow()
  181. }
  182. }
  183. // Nil asserts that the specified object is nil.
  184. //
  185. // assert.Nil(t, err, "err should be nothing")
  186. //
  187. // Returns whether the assertion was successful (true) or not (false).
  188. func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  189. if !assert.Nil(t, object, msgAndArgs...) {
  190. t.FailNow()
  191. }
  192. }
  193. // NoError asserts that a function returned no error (i.e. `nil`).
  194. //
  195. // actualObj, err := SomeFunction()
  196. // if assert.NoError(t, err) {
  197. // assert.Equal(t, actualObj, expectedObj)
  198. // }
  199. //
  200. // Returns whether the assertion was successful (true) or not (false).
  201. func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
  202. if !assert.NoError(t, err, msgAndArgs...) {
  203. t.FailNow()
  204. }
  205. }
  206. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  207. // specified substring or element.
  208. //
  209. // assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
  210. // assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
  211. // assert.NotContains(t, {"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
  212. //
  213. // Returns whether the assertion was successful (true) or not (false).
  214. func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  215. if !assert.NotContains(t, s, contains, msgAndArgs...) {
  216. t.FailNow()
  217. }
  218. }
  219. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  220. // a slice or a channel with len == 0.
  221. //
  222. // if assert.NotEmpty(t, obj) {
  223. // assert.Equal(t, "two", obj[1])
  224. // }
  225. //
  226. // Returns whether the assertion was successful (true) or not (false).
  227. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  228. if !assert.NotEmpty(t, object, msgAndArgs...) {
  229. t.FailNow()
  230. }
  231. }
  232. // NotEqual asserts that the specified values are NOT equal.
  233. //
  234. // assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
  235. //
  236. // Returns whether the assertion was successful (true) or not (false).
  237. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  238. if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
  239. t.FailNow()
  240. }
  241. }
  242. // NotNil asserts that the specified object is not nil.
  243. //
  244. // assert.NotNil(t, err, "err should be something")
  245. //
  246. // Returns whether the assertion was successful (true) or not (false).
  247. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  248. if !assert.NotNil(t, object, msgAndArgs...) {
  249. t.FailNow()
  250. }
  251. }
  252. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  253. //
  254. // assert.NotPanics(t, func(){
  255. // RemainCalm()
  256. // }, "Calling RemainCalm() should NOT panic")
  257. //
  258. // Returns whether the assertion was successful (true) or not (false).
  259. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  260. if !assert.NotPanics(t, f, msgAndArgs...) {
  261. t.FailNow()
  262. }
  263. }
  264. // NotRegexp asserts that a specified regexp does not match a string.
  265. //
  266. // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
  267. // assert.NotRegexp(t, "^start", "it's not starting")
  268. //
  269. // Returns whether the assertion was successful (true) or not (false).
  270. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  271. if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
  272. t.FailNow()
  273. }
  274. }
  275. // NotZero asserts that i is not the zero value for its type and returns the truth.
  276. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  277. if !assert.NotZero(t, i, msgAndArgs...) {
  278. t.FailNow()
  279. }
  280. }
  281. // Panics asserts that the code inside the specified PanicTestFunc panics.
  282. //
  283. // assert.Panics(t, func(){
  284. // GoCrazy()
  285. // }, "Calling GoCrazy() should panic")
  286. //
  287. // Returns whether the assertion was successful (true) or not (false).
  288. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  289. if !assert.Panics(t, f, msgAndArgs...) {
  290. t.FailNow()
  291. }
  292. }
  293. // Regexp asserts that a specified regexp matches a string.
  294. //
  295. // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
  296. // assert.Regexp(t, "start...$", "it's not starting")
  297. //
  298. // Returns whether the assertion was successful (true) or not (false).
  299. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  300. if !assert.Regexp(t, rx, str, msgAndArgs...) {
  301. t.FailNow()
  302. }
  303. }
  304. // True asserts that the specified value is true.
  305. //
  306. // assert.True(t, myBool, "myBool should be true")
  307. //
  308. // Returns whether the assertion was successful (true) or not (false).
  309. func True(t TestingT, value bool, msgAndArgs ...interface{}) {
  310. if !assert.True(t, value, msgAndArgs...) {
  311. t.FailNow()
  312. }
  313. }
  314. // WithinDuration asserts that the two times are within duration delta of each other.
  315. //
  316. // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
  317. //
  318. // Returns whether the assertion was successful (true) or not (false).
  319. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  320. if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
  321. t.FailNow()
  322. }
  323. }
  324. // Zero asserts that i is the zero value for its type and returns the truth.
  325. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  326. if !assert.Zero(t, i, msgAndArgs...) {
  327. t.FailNow()
  328. }
  329. }