adds experimental sys.Errno to begin decoupling from the syscall package (#1582)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -13,9 +13,10 @@ import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
// TestingT is an interface wrapper of functions used in TestingT
|
||||
@@ -131,14 +132,14 @@ func Error(t TestingT, err error, formatWithArgs ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// EqualErrno should be used for functions that return syscall.Errno or nil.
|
||||
func EqualErrno(t TestingT, expected syscall.Errno, err error, formatWithArgs ...interface{}) {
|
||||
// EqualErrno should be used for functions that return sys.Errno or nil.
|
||||
func EqualErrno(t TestingT, expected sys.Errno, err error, formatWithArgs ...interface{}) {
|
||||
if err == nil {
|
||||
fail(t, "expected a syscall.Errno, but was nil", "", formatWithArgs...)
|
||||
fail(t, "expected a sys.Errno, but was nil", "", formatWithArgs...)
|
||||
return
|
||||
}
|
||||
if se, ok := err.(syscall.Errno); !ok {
|
||||
fail(t, fmt.Sprintf("expected %v to be a syscall.Errno", err), "", formatWithArgs...)
|
||||
if se, ok := err.(sys.Errno); !ok {
|
||||
fail(t, fmt.Sprintf("expected %v to be a sys.Errno", err), "", formatWithArgs...)
|
||||
} else if se != expected {
|
||||
fail(t, fmt.Sprintf("expected Errno %#[1]v(%[1]s), but was %#[2]v(%[2]s)", expected, err), "", formatWithArgs...)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ package require
|
||||
import (
|
||||
"io"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
func TestEqualErrno(t *testing.T) {
|
||||
@@ -22,36 +23,36 @@ func TestEqualErrno(t *testing.T) {
|
||||
{
|
||||
name: "EqualErrno passes on equal",
|
||||
require: func(t TestingT) {
|
||||
EqualErrno(t, syscall.ENOENT, syscall.ENOENT)
|
||||
EqualErrno(t, sys.ENOENT, sys.ENOENT)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "EqualErrno fails on nil",
|
||||
require: func(t TestingT) {
|
||||
EqualErrno(t, syscall.ENOENT, nil)
|
||||
EqualErrno(t, sys.ENOENT, nil)
|
||||
},
|
||||
expectedLog: "expected a syscall.Errno, but was nil",
|
||||
expectedLog: "expected a sys.Errno, but was nil",
|
||||
},
|
||||
{
|
||||
name: "EqualErrno fails on not Errno",
|
||||
require: func(t TestingT) {
|
||||
EqualErrno(t, syscall.ENOENT, io.EOF)
|
||||
EqualErrno(t, sys.ENOENT, io.EOF)
|
||||
},
|
||||
expectedLog: `expected EOF to be a syscall.Errno`,
|
||||
expectedLog: `expected EOF to be a sys.Errno`,
|
||||
},
|
||||
{
|
||||
name: "EqualErrno fails on not equal",
|
||||
require: func(t TestingT) {
|
||||
EqualErrno(t, syscall.ENOENT, syscall.EIO)
|
||||
EqualErrno(t, sys.ENOENT, sys.EIO)
|
||||
},
|
||||
expectedLog: `expected Errno 0x2(no such file or directory), but was 0x5(input/output error)`,
|
||||
expectedLog: `expected Errno 0xc(no such file or directory), but was 0x8(input/output error)`,
|
||||
},
|
||||
{
|
||||
name: "EqualErrno fails on not equal with format",
|
||||
require: func(t TestingT) {
|
||||
EqualErrno(t, syscall.ENOENT, syscall.EIO, "pay me %d", 5)
|
||||
EqualErrno(t, sys.ENOENT, sys.EIO, "pay me %d", 5)
|
||||
},
|
||||
expectedLog: `expected Errno 0x2(no such file or directory), but was 0x5(input/output error): pay me 5`,
|
||||
expectedLog: `expected Errno 0xc(no such file or directory), but was 0x8(input/output error): pay me 5`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user