Skip to content

Commit

Permalink
Modify tests for tinygo Type.String() mismatch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fxamacker committed Sep 8, 2024
1 parent 7730daf commit fb90c7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
})
Expand Down

0 comments on commit fb90c7b

Please sign in to comment.