wa-lang.org/wazero@v1.0.2/internal/gojs/misc_test.go (about)

     1  package gojs_test
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"wa-lang.org/wazero"
     8  	"wa-lang.org/wazero/internal/testing/require"
     9  )
    10  
    11  func Test_goroutine(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	stdout, stderr, err := compileAndRun(testCtx, "goroutine", wazero.NewModuleConfig())
    15  
    16  	require.EqualError(t, err, `module "" closed with exit_code(0)`)
    17  	require.Zero(t, stderr)
    18  	require.Equal(t, `producer
    19  consumer
    20  `, stdout)
    21  }
    22  
    23  func Test_mem(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	stdout, stderr, err := compileAndRun(testCtx, "mem", wazero.NewModuleConfig())
    27  
    28  	require.EqualError(t, err, `module "" closed with exit_code(0)`)
    29  	require.Zero(t, stderr)
    30  	require.Zero(t, stdout)
    31  }
    32  
    33  func Test_stdio(t *testing.T) {
    34  	t.Parallel()
    35  
    36  	stdout, stderr, err := compileAndRun(testCtx, "stdio", wazero.NewModuleConfig().
    37  		WithStdin(strings.NewReader("stdin\n")))
    38  
    39  	require.EqualError(t, err, `module "" closed with exit_code(0)`)
    40  	require.Equal(t, "println stdin\nStderr.Write", stderr)
    41  	require.Equal(t, "Stdout.Write", stdout)
    42  }
    43  
    44  func Test_gc(t *testing.T) {
    45  	t.Parallel()
    46  
    47  	stdout, stderr, err := compileAndRun(testCtx, "gc", wazero.NewModuleConfig())
    48  
    49  	require.EqualError(t, err, `module "" closed with exit_code(0)`)
    50  	require.Equal(t, "", stderr)
    51  	require.Equal(t, "before gc\nafter gc\n", stdout)
    52  }