github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/wasip1/errno_test.go (about) 1 package wasip1 2 3 import ( 4 "testing" 5 6 "github.com/wasilibs/wazerox/experimental/sys" 7 ) 8 9 func TestToErrno(t *testing.T) { 10 tests := []struct { 11 name string 12 input sys.Errno 13 expected Errno 14 }{ 15 { 16 name: "zero is not an error", 17 expected: ErrnoSuccess, 18 }, 19 { 20 name: "sys.EACCES", 21 input: sys.EACCES, 22 expected: ErrnoAcces, 23 }, 24 { 25 name: "sys.EAGAIN", 26 input: sys.EAGAIN, 27 expected: ErrnoAgain, 28 }, 29 { 30 name: "sys.EBADF", 31 input: sys.EBADF, 32 expected: ErrnoBadf, 33 }, 34 { 35 name: "sys.EEXIST", 36 input: sys.EEXIST, 37 expected: ErrnoExist, 38 }, 39 { 40 name: "sys.EFAULT", 41 input: sys.EFAULT, 42 expected: ErrnoFault, 43 }, 44 { 45 name: "sys.EINTR", 46 input: sys.EINTR, 47 expected: ErrnoIntr, 48 }, 49 { 50 name: "sys.EINVAL", 51 input: sys.EINVAL, 52 expected: ErrnoInval, 53 }, 54 { 55 name: "sys.EIO", 56 input: sys.EIO, 57 expected: ErrnoIo, 58 }, 59 { 60 name: "sys.EISDIR", 61 input: sys.EISDIR, 62 expected: ErrnoIsdir, 63 }, 64 { 65 name: "sys.ELOOP", 66 input: sys.ELOOP, 67 expected: ErrnoLoop, 68 }, 69 { 70 name: "sys.ENAMETOOLONG", 71 input: sys.ENAMETOOLONG, 72 expected: ErrnoNametoolong, 73 }, 74 { 75 name: "sys.ENOENT", 76 input: sys.ENOENT, 77 expected: ErrnoNoent, 78 }, 79 { 80 name: "sys.ENOSYS", 81 input: sys.ENOSYS, 82 expected: ErrnoNosys, 83 }, 84 { 85 name: "sys.ENOTDIR", 86 input: sys.ENOTDIR, 87 expected: ErrnoNotdir, 88 }, 89 { 90 name: "sys.ENOTEMPTY", 91 input: sys.ENOTEMPTY, 92 expected: ErrnoNotempty, 93 }, 94 { 95 name: "sys.ENOTSOCK", 96 input: sys.ENOTSOCK, 97 expected: ErrnoNotsock, 98 }, 99 { 100 name: "sys.ENOTSUP", 101 input: sys.ENOTSUP, 102 expected: ErrnoNotsup, 103 }, 104 { 105 name: "sys.EPERM", 106 input: sys.EPERM, 107 expected: ErrnoPerm, 108 }, 109 { 110 name: "sys.EROFS", 111 input: sys.EROFS, 112 expected: ErrnoRofs, 113 }, 114 { 115 name: "sys.EqualErrno unexpected == ErrnoIo", 116 input: sys.Errno(0xfe), 117 expected: ErrnoIo, 118 }, 119 } 120 121 for _, tt := range tests { 122 tc := tt 123 t.Run(tc.name, func(t *testing.T) { 124 if errno := ToErrno(tc.input); errno != tc.expected { 125 t.Fatalf("expected %s but got %s", ErrnoName(tc.expected), ErrnoName(errno)) 126 } 127 }) 128 } 129 }