Many tests failed in gojs due to needing to be resolved against the CWD,
which is atypically stored host side. This fixes that and renames the
"exit" scope to "proc" so we can use it for other proc concerns besides
exit.
This reduces known failures on GOOS=js from 23 to 14:
```bash
$ wazero run -mount=/usr/local/go/src/os:/:ro -mount=/tmp:/tmp -mount=/etc:/etc:ro -mount=/usr:/usr:ro -mount=/dev:/dev:ro os.wasm |grep '^--- FAIL'|wc -l
14
```
See #1222
Signed-off-by: Adrian Cole <adrian@tetrate.io>
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package logging
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
|
)
|
|
|
|
// TestLogScopes tests the bitset works as expected
|
|
func TestLogScopes(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
scopes LogScopes
|
|
}{
|
|
{
|
|
name: "one is the smallest flag",
|
|
scopes: 1,
|
|
},
|
|
{
|
|
name: "63 is the largest feature flag", // because uint64
|
|
scopes: 1 << 2,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tc := tt
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f := LogScopes(0)
|
|
|
|
// Defaults to false
|
|
require.False(t, f.IsEnabled(tc.scopes))
|
|
|
|
// Set true makes it true
|
|
f = f | tc.scopes
|
|
require.True(t, f.IsEnabled(tc.scopes))
|
|
|
|
// Set false makes it false again
|
|
f = f ^ tc.scopes
|
|
require.False(t, f.IsEnabled(tc.scopes))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLogScopes_String(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
scopes LogScopes
|
|
expected string
|
|
}{
|
|
{name: "none", scopes: LogScopeNone, expected: ""},
|
|
{name: "any", scopes: LogScopeAll, expected: "all"},
|
|
{name: "clock", scopes: LogScopeClock, expected: "clock"},
|
|
{name: "proc", scopes: LogScopeProc, expected: "proc"},
|
|
{name: "filesystem", scopes: LogScopeFilesystem, expected: "filesystem"},
|
|
{name: "poll", scopes: LogScopePoll, expected: "poll"},
|
|
{name: "random", scopes: LogScopeRandom, expected: "random"},
|
|
{name: "filesystem|random", scopes: LogScopeFilesystem | LogScopeRandom, expected: "filesystem|random"},
|
|
{name: "undefined", scopes: 1 << 14, expected: fmt.Sprintf("<unknown=%d>", 1<<14)},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tc := tt
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.expected, tc.scopes.String())
|
|
})
|
|
}
|
|
}
|