@@ -11,9 +11,25 @@ type Testing interface {
1111 Errorf (format string , args ... any )
1212}
1313
14+ // Fail reports a failure message through
15+ func Fail (t Testing , message string ) bool {
16+ t .Helper ()
17+
18+ t .Errorf (message )
19+
20+ return false
21+ }
22+
23+ // Failf reports a failure formatted message through
24+ func Failf (t Testing , format string , args ... any ) bool {
25+ t .Helper ()
26+
27+ t .Errorf (format , args ... )
28+
29+ return false
30+ }
31+
1432// True asserts that the specified value is true.
15- //
16- // assert.True(t, condition)
1733func True (t Testing , condition bool ) bool {
1834 t .Helper ()
1935
@@ -25,8 +41,6 @@ func True(t Testing, condition bool) bool {
2541}
2642
2743// False asserts that the specified value is false.
28- //
29- // assert.False(t, condition)
3044func False (t Testing , condition bool ) bool {
3145 t .Helper ()
3246
@@ -39,8 +53,6 @@ func False(t Testing, condition bool) bool {
3953
4054// Equal asserts that two objects are equal.
4155//
42- // assert.Equal(t, actual, expected)
43- //
4456// Pointer variable equality is determined based on the equality of the
4557// referenced values (as opposed to the memory addresses).
4658func Equal [T Comparable ](t Testing , actual , expected T ) bool {
@@ -55,8 +67,6 @@ func Equal[T Comparable](t Testing, actual, expected T) bool {
5567
5668// NotEqual asserts that the specified values are NOT equal.
5769//
58- // assert.NotEqual(t, actual, expected)
59- //
6070// Pointer variable equality is determined based on the equality of the
6171// referenced values (as opposed to the memory addresses).
6272func NotEqual [T Comparable ](t Testing , actual , expected T ) bool {
@@ -71,8 +81,6 @@ func NotEqual[T Comparable](t Testing, actual, expected T) bool {
7181
7282// EqualDelta asserts that two numeric values difference is less then delta.
7383//
74- // assert.EqualDelta(t, actual, expected, delta)
75- //
7684// Method panics if delta value is not positive.
7785func EqualDelta [T Numeric ](t Testing , actual , expected , delta T ) bool {
7886 t .Helper ()
@@ -86,8 +94,6 @@ func EqualDelta[T Numeric](t Testing, actual, expected, delta T) bool {
8694
8795// Same asserts that two pointers reference the same object.
8896//
89- // assert.Same(t, actual, expected)
90- //
9197// Both arguments must be pointer variables. Pointer variable equality is
9298// determined based on the equality of both type and value.
9399func Same [T Reference ](t Testing , actual , expected T ) bool {
@@ -104,8 +110,6 @@ func Same[T Reference](t Testing, actual, expected T) bool {
104110
105111// NotSame asserts that two pointers do NOT reference the same object.
106112//
107- // assert.NotSame(t, actual, expected)
108- //
109113// Both arguments must be pointer variables. Pointer variable equality is
110114// determined based on the equality of both type and value.
111115func NotSame [T Reference ](t Testing , actual , expected T ) bool {
@@ -121,8 +125,6 @@ func NotSame[T Reference](t Testing, actual, expected T) bool {
121125}
122126
123127// Length asserts that object have given length.
124- //
125- // assert.Length(t, object, expected)
126128func Length [S Iterable [any ]](t Testing , object S , expected int ) bool {
127129 t .Helper ()
128130
@@ -135,8 +137,6 @@ func Length[S Iterable[any]](t Testing, object S, expected int) bool {
135137
136138// Contains asserts that object contains given element
137139//
138- // assert.Contains(t, object, element)
139- //
140140// Works with strings, arrays, slices, maps values and channels
141141func Contains [S Iterable [E ], E Comparable ](t Testing , object S , element E ) bool {
142142 t .Helper ()
@@ -152,8 +152,6 @@ func Contains[S Iterable[E], E Comparable](t Testing, object S, element E) bool
152152
153153// NotContains asserts that object do NOT contains given element
154154//
155- // assert.NotContains(t, object, element)
156- //
157155// Works with strings, arrays, slices, maps values and channels
158156func NotContains [S Iterable [E ], E Comparable ](t Testing , object S , element E ) bool {
159157 t .Helper ()
@@ -168,8 +166,6 @@ func NotContains[S Iterable[E], E Comparable](t Testing, object S, element E) bo
168166}
169167
170168// Error asserts that error is NOT nil
171- //
172- // assert.Error(t, err)
173169func Error (t Testing , err error ) bool {
174170 t .Helper ()
175171
@@ -181,8 +177,6 @@ func Error(t Testing, err error) bool {
181177}
182178
183179// NoError asserts that error is nil
184- //
185- // assert.NoError(t, err)
186180func NoError (t Testing , err error ) bool {
187181 t .Helper ()
188182
@@ -194,8 +188,6 @@ func NoError(t Testing, err error) bool {
194188}
195189
196190// ErrorIs asserts that error is unwrappable to given target
197- //
198- // assert.ErrorIs(t, err)
199191func ErrorIs (t Testing , err error , target error ) bool {
200192 t .Helper ()
201193
@@ -207,8 +199,6 @@ func ErrorIs(t Testing, err error, target error) bool {
207199}
208200
209201// NotErrorIs asserts that error is NOT unwrappable to given target
210- //
211- // assert.NotErrorIs(t, err)
212202func NotErrorIs (t Testing , err error , target error ) bool {
213203 t .Helper ()
214204
@@ -220,8 +210,6 @@ func NotErrorIs(t Testing, err error, target error) bool {
220210}
221211
222212// EqualJSON asserts that JSON strings are equal
223- //
224- // assert.EqualJSON(t, actual, expected)
225213func EqualJSON (t Testing , actual , expected string ) bool {
226214 t .Helper ()
227215
@@ -238,20 +226,11 @@ func EqualJSON(t Testing, actual, expected string) bool {
238226 return Equal (t , expectedJSON , actualJSON )
239227}
240228
241- // Fail reports a failure message through
242- func Fail (t Testing , message string ) bool {
229+ // JSON asserts that object can be marshall to expected JSON string
230+ func JSON (t Testing , actual any , expected string ) bool {
243231 t .Helper ()
244232
245- t .Errorf (message )
246-
247- return false
248- }
233+ s , err := json .Marshal (actual )
249234
250- // Failf reports a failure formatted message through
251- func Failf (t Testing , format string , args ... any ) bool {
252- t .Helper ()
253-
254- t .Errorf (format , args ... )
255-
256- return false
235+ return NoError (t , err ) && EqualJSON (t , string (s ), expected )
257236}
0 commit comments