wa-lang.org/wazero@v1.0.2/imports/wasi_snapshot_preview1/proc_test.go (about) 1 package wasi_snapshot_preview1 2 3 import ( 4 "testing" 5 6 "wa-lang.org/wazero" 7 "wa-lang.org/wazero/internal/testing/require" 8 "wa-lang.org/wazero/sys" 9 ) 10 11 func Test_procExit(t *testing.T) { 12 mod, r, log := requireProxyModule(t, wazero.NewModuleConfig()) 13 defer r.Close(testCtx) 14 15 tests := []struct { 16 name string 17 exitCode uint32 18 expectedLog string 19 }{ 20 { 21 name: "success (exitcode 0)", 22 exitCode: 0, 23 expectedLog: ` 24 --> proxy.proc_exit(rval=0) 25 ==> wasi_snapshot_preview1.proc_exit(rval=0) 26 `, 27 }, 28 { 29 name: "arbitrary non-zero exitcode", 30 exitCode: 42, 31 expectedLog: ` 32 --> proxy.proc_exit(rval=42) 33 ==> wasi_snapshot_preview1.proc_exit(rval=42) 34 `, 35 }, 36 } 37 38 for _, tt := range tests { 39 tc := tt 40 41 t.Run(tc.name, func(t *testing.T) { 42 defer log.Reset() 43 44 // Since procExit panics, any opcodes afterwards cannot be reached. 45 _, err := mod.ExportedFunction(functionProcExit).Call(testCtx, uint64(tc.exitCode)) 46 require.Error(t, err) 47 sysErr, ok := err.(*sys.ExitError) 48 require.True(t, ok, err) 49 require.Equal(t, tc.exitCode, sysErr.ExitCode()) 50 require.Equal(t, tc.expectedLog, "\n"+log.String()) 51 }) 52 } 53 } 54 55 // Test_procRaise only tests it is stubbed for GrainLang per #271 56 func Test_procRaise(t *testing.T) { 57 log := requireErrnoNosys(t, functionProcRaise, 0) 58 require.Equal(t, ` 59 --> proxy.proc_raise(sig=0) 60 --> wasi_snapshot_preview1.proc_raise(sig=0) 61 <-- ENOSYS 62 <-- (52) 63 `, log) 64 }