@@ -92,14 +92,18 @@ func Test_decodeState_decodeStruct(t *testing.T) {
9292 if err := Unmarshal (tt .want , & dst ); (err != nil ) != tt .wantErr {
9393 t .Errorf ("decodeState.unmarshal() error = %v, wantErr %v" , err , tt .wantErr )
9494 }
95- var diff string
96- if tt .out != nil {
97- diff = cmp .Diff (dst , tt .out , cmpopts .IgnoreUnexported (tt .in ))
98- } else {
99- diff = cmp .Diff (dst , tt .in , cmpopts .IgnoreUnexported (big.Int {}, tt .in , VDTValue2 {}, MyStructWithIgnore {}))
100- }
101- if diff != "" {
102- t .Errorf ("decodeState.unmarshal() = %s" , diff )
95+
96+ // assert response only if we aren't expecting an error
97+ if ! tt .wantErr {
98+ var diff string
99+ if tt .out != nil {
100+ diff = cmp .Diff (dst , tt .out , cmpopts .IgnoreUnexported (tt .in ))
101+ } else {
102+ diff = cmp .Diff (dst , tt .in , cmpopts .IgnoreUnexported (big.Int {}, tt .in , VDTValue2 {}, MyStructWithIgnore {}))
103+ }
104+ if diff != "" {
105+ t .Errorf ("decodeState.unmarshal() = %s" , diff )
106+ }
103107 }
104108 })
105109 }
@@ -294,20 +298,24 @@ func Test_unmarshal_optionality(t *testing.T) {
294298 t .Errorf ("decodeState.unmarshal() error = %v, wantErr %v" , err , tt .wantErr )
295299 return
296300 }
297- var diff string
298- if tt .out != nil {
299- diff = cmp .Diff (
300- reflect .ValueOf (dst ).Elem ().Interface (),
301- reflect .ValueOf (tt .out ).Interface (),
302- cmpopts .IgnoreUnexported (tt .in ))
303- } else {
304- diff = cmp .Diff (
305- reflect .ValueOf (dst ).Elem ().Interface (),
306- reflect .ValueOf (tt .in ).Interface (),
307- cmpopts .IgnoreUnexported (big.Int {}, VDTValue2 {}, MyStructWithIgnore {}, MyStructWithPrivate {}))
308- }
309- if diff != "" {
310- t .Errorf ("decodeState.unmarshal() = %s" , diff )
301+
302+ // assert response only if we aren't expecting an error
303+ if ! tt .wantErr {
304+ var diff string
305+ if tt .out != nil {
306+ diff = cmp .Diff (
307+ reflect .ValueOf (dst ).Elem ().Interface (),
308+ reflect .ValueOf (tt .out ).Interface (),
309+ cmpopts .IgnoreUnexported (tt .in ))
310+ } else {
311+ diff = cmp .Diff (
312+ reflect .ValueOf (dst ).Elem ().Interface (),
313+ reflect .ValueOf (tt .in ).Interface (),
314+ cmpopts .IgnoreUnexported (big.Int {}, VDTValue2 {}, MyStructWithIgnore {}, MyStructWithPrivate {}))
315+ }
316+ if diff != "" {
317+ t .Errorf ("decodeState.unmarshal() = %s" , diff )
318+ }
311319 }
312320 }
313321 })
@@ -325,7 +333,11 @@ func Test_unmarshal_optionality_nil_case(t *testing.T) {
325333 // ignore out, since we are testing nil case
326334 // out: t.out,
327335 }
328- ptrTest .want = []byte {0x00 }
336+
337+ // for error cases, we don't need to modify the input since we need it to fail
338+ if ! t .wantErr {
339+ ptrTest .want = []byte {0x00 }
340+ }
329341
330342 temp := reflect .New (reflect .TypeOf (t .in ))
331343 // create a new pointer to type of temp
0 commit comments