Skip to content

Commit fb90c7b

Browse files
committed
Modify tests for tinygo Type.String() mismatch
Return value of tinygo's Type.String() for function type doesn't match equivalent call using Go's reflect package. More details at tinygo-org/tinygo#4458 This commit modifies tests to handle function type string being different for tinygo and Go.
1 parent 7730daf commit fb90c7b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

encode_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func TestInvalidTypeMarshal(t *testing.T) {
319319
{"map of channel cannot be marshaled", make(map[string]chan bool), "cbor: unsupported type: map[string]chan bool"},
320320
{"struct of channel cannot be marshaled", s1{}, "cbor: unsupported type: cbor.s1"},
321321
{"struct of channel cannot be marshaled", s2{}, "cbor: unsupported type: cbor.s2"},
322-
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func(int) int"},
322+
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func"},
323323
{"complex cannot be marshaled", complex(100, 8), "cbor: unsupported type: complex128"},
324324
}
325325
em, err := EncOptions{Sort: SortCanonical}.EncMode()
@@ -334,7 +334,7 @@ func TestInvalidTypeMarshal(t *testing.T) {
334334
t.Errorf("Marshal(%v) didn't return an error, want error %q", tc.value, tc.wantErrorMsg)
335335
} else if _, ok := err.(*UnsupportedTypeError); !ok {
336336
t.Errorf("Marshal(%v) error type %T, want *UnsupportedTypeError", tc.value, err)
337-
} else if err.Error() != tc.wantErrorMsg {
337+
} else if !strings.HasPrefix(err.Error(), tc.wantErrorMsg) {
338338
t.Errorf("Marshal(%v) error %q, want %q", tc.value, err.Error(), tc.wantErrorMsg)
339339
} else if b != nil {
340340
t.Errorf("Marshal(%v) = 0x%x, want nil", tc.value, b)
@@ -346,7 +346,7 @@ func TestInvalidTypeMarshal(t *testing.T) {
346346
t.Errorf("Marshal(%v) didn't return an error, want error %q", tc.value, tc.wantErrorMsg)
347347
} else if _, ok := err.(*UnsupportedTypeError); !ok {
348348
t.Errorf("Marshal(%v) error type %T, want *UnsupportedTypeError", tc.value, err)
349-
} else if err.Error() != tc.wantErrorMsg {
349+
} else if !strings.HasPrefix(err.Error(), tc.wantErrorMsg) {
350350
t.Errorf("Marshal(%v) error %q, want %q", tc.value, err.Error(), tc.wantErrorMsg)
351351
} else if b != nil {
352352
t.Errorf("Marshal(%v) = 0x%x, want nil", tc.value, b)

stream_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ func TestEncoderError(t *testing.T) {
692692
wantErrorMsg string
693693
}{
694694
{"channel cannot be marshaled", make(chan bool), "cbor: unsupported type: chan bool"},
695-
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func(int) int"},
695+
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func"},
696696
{"complex cannot be marshaled", complex(100, 8), "cbor: unsupported type: complex128"},
697697
}
698698
var w bytes.Buffer
@@ -705,7 +705,7 @@ func TestEncoderError(t *testing.T) {
705705
t.Errorf("Encode(%v) didn't return an error, want error %q", tc.value, tc.wantErrorMsg)
706706
} else if _, ok := err.(*UnsupportedTypeError); !ok {
707707
t.Errorf("Encode(%v) error type %T, want *UnsupportedTypeError", tc.value, err)
708-
} else if err.Error() != tc.wantErrorMsg {
708+
} else if !strings.HasPrefix(err.Error(), tc.wantErrorMsg) {
709709
t.Errorf("Encode(%v) error %q, want %q", tc.value, err.Error(), tc.wantErrorMsg)
710710
}
711711
})

0 commit comments

Comments
 (0)