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 https://github.com/tinygo-org/tinygo/issues/4458

This commit modifies tests to handle function type string being
different for tinygo and Go.
This commit is contained in:
Faye Amacker 2024-09-07 20:42:17 -05:00
parent 7730daf1b0
commit fb90c7bd35
2 changed files with 5 additions and 5 deletions

View File

@ -319,7 +319,7 @@ func TestInvalidTypeMarshal(t *testing.T) {
{"map of channel cannot be marshaled", make(map[string]chan bool), "cbor: unsupported type: map[string]chan bool"},
{"struct of channel cannot be marshaled", s1{}, "cbor: unsupported type: cbor.s1"},
{"struct of channel cannot be marshaled", s2{}, "cbor: unsupported type: cbor.s2"},
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func(int) int"},
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func"},
{"complex cannot be marshaled", complex(100, 8), "cbor: unsupported type: complex128"},
}
em, err := EncOptions{Sort: SortCanonical}.EncMode()
@ -334,7 +334,7 @@ func TestInvalidTypeMarshal(t *testing.T) {
t.Errorf("Marshal(%v) didn't return an error, want error %q", tc.value, tc.wantErrorMsg)
} else if _, ok := err.(*UnsupportedTypeError); !ok {
t.Errorf("Marshal(%v) error type %T, want *UnsupportedTypeError", tc.value, err)
} else if err.Error() != tc.wantErrorMsg {
} else if !strings.HasPrefix(err.Error(), tc.wantErrorMsg) {
t.Errorf("Marshal(%v) error %q, want %q", tc.value, err.Error(), tc.wantErrorMsg)
} else if b != nil {
t.Errorf("Marshal(%v) = 0x%x, want nil", tc.value, b)
@ -346,7 +346,7 @@ func TestInvalidTypeMarshal(t *testing.T) {
t.Errorf("Marshal(%v) didn't return an error, want error %q", tc.value, tc.wantErrorMsg)
} else if _, ok := err.(*UnsupportedTypeError); !ok {
t.Errorf("Marshal(%v) error type %T, want *UnsupportedTypeError", tc.value, err)
} else if err.Error() != tc.wantErrorMsg {
} else if !strings.HasPrefix(err.Error(), tc.wantErrorMsg) {
t.Errorf("Marshal(%v) error %q, want %q", tc.value, err.Error(), tc.wantErrorMsg)
} else if b != nil {
t.Errorf("Marshal(%v) = 0x%x, want nil", tc.value, b)

View File

@ -692,7 +692,7 @@ func TestEncoderError(t *testing.T) {
wantErrorMsg string
}{
{"channel cannot be marshaled", make(chan bool), "cbor: unsupported type: chan bool"},
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func(int) int"},
{"function cannot be marshaled", func(i int) int { return i * i }, "cbor: unsupported type: func"},
{"complex cannot be marshaled", complex(100, 8), "cbor: unsupported type: complex128"},
}
var w bytes.Buffer
@ -705,7 +705,7 @@ func TestEncoderError(t *testing.T) {
t.Errorf("Encode(%v) didn't return an error, want error %q", tc.value, tc.wantErrorMsg)
} else if _, ok := err.(*UnsupportedTypeError); !ok {
t.Errorf("Encode(%v) error type %T, want *UnsupportedTypeError", tc.value, err)
} else if err.Error() != tc.wantErrorMsg {
} else if !strings.HasPrefix(err.Error(), tc.wantErrorMsg) {
t.Errorf("Encode(%v) error %q, want %q", tc.value, err.Error(), tc.wantErrorMsg)
}
})