Files
wazero/internal/platform/path_test.go
Crypt Keeper 14c409eaf7 cli: changes experimental workdir flag to inherit (#1235)
This changes the experimental flag introduced yesterday to
`-experimental-workdir-inherit=true`, to reduce edge cases needed to
produce the same behavior as go's wasm test runner.

After this, we have the same failure count, though the latter is likely
related to my machine:

```bash
$ wasm=$PWD/os.wasm; (cd $(go env GOROOT)/src/os; wazero run -mount=/:/ --experimental-workdir-inherit=true $wasm)
--- FAIL: TestMkdirAllAtSlash (0.00s)
    path_test.go:111: MkdirAll "/_go_os_test/dir": mkdir /_go_os_test: I/O error, I/O error
--- FAIL: TestOpenFileLimit (0.01s)
    rlimit_test.go:31: open rlimit.go: I/O error
FAIL
```

See https://github.com/golang/go/blob/master/misc/wasm/wasm_exec_node.js#L24

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-14 10:20:44 +08:00

43 lines
922 B
Go

package platform
import (
"runtime"
"strings"
"testing"
"github.com/tetratelabs/wazero/internal/testing/require"
)
func TestToPosixPath(t *testing.T) {
t.Parallel()
tests := []struct {
input string
expected string
}{
{},
{input: ".", expected: "."},
{input: "/", expected: `/`},
{input: `/`, expected: `/`},
{input: "/foo/bar", expected: `/foo/bar`},
{input: `\foo\bar`, expected: `/foo/bar`},
{input: "foo/bar", expected: `foo/bar`},
{input: `foo\bar`, expected: `foo/bar`},
{input: "c:/foo/bar", expected: `c:/foo/bar`},
{input: `c:\foo\bar`, expected: `c:/foo/bar`},
}
for _, tt := range tests {
tc := tt
// We don't expect to translate backslashes unless we are on windows.
if strings.IndexByte(tc.input, '\\') != -1 && runtime.GOOS != "windows" {
continue
}
t.Run(tc.input, func(t *testing.T) {
require.Equal(t, tc.expected, ToPosixPath(tc.input))
})
}
}