aboutsummaryrefslogtreecommitdiffhomepage
path: root/main_test.go
diff options
context:
space:
mode:
authorTakeshi Yoneda <[email protected]>2021-02-17 23:50:53 +0900
committerRon Evans <[email protected]>2021-02-24 14:22:17 +0100
commit9841ac4acd8f0f288c01d09c68a95baa8e6dd548 (patch)
tree8d1df9fa48d65790d9d52068f3c3feef8ca2fcc0 /main_test.go
parentc2993869067c18a36f724b86b253ef56c37c044a (diff)
downloadtinygo-9841ac4acd8f0f288c01d09c68a95baa8e6dd548.tar.gz
tinygo-9841ac4acd8f0f288c01d09c68a95baa8e6dd548.zip
WASI & darwin: support env variables based on libc
Signed-off-by: Takeshi Yoneda <[email protected]>
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/main_test.go b/main_test.go
index a7eca14f0..31ee8c5dc 100644
--- a/main_test.go
+++ b/main_test.go
@@ -58,6 +58,9 @@ func TestCompiler(t *testing.T) {
if runtime.GOOS != "windows" {
t.Run("Host", func(t *testing.T) {
runPlatTests("", matches, t)
+ if runtime.GOOS == "darwin" {
+ runTest("testdata/libc/env.go", "", t, []string{"ENV1=VALUE1", "ENV2=VALUE2"}...)
+ }
})
}
@@ -104,6 +107,7 @@ func TestCompiler(t *testing.T) {
t.Run("WASI", func(t *testing.T) {
runPlatTests("wasi", matches, t)
+ runTest("testdata/libc/env.go", "wasi", t, []string{"ENV1=VALUE1", "ENV2=VALUE2"}...)
})
}
}
@@ -113,7 +117,6 @@ func runPlatTests(target string, matches []string, t *testing.T) {
for _, path := range matches {
path := path // redefine to avoid race condition
-
t.Run(filepath.Base(path), func(t *testing.T) {
t.Parallel()
runTest(path, target, t)
@@ -133,7 +136,7 @@ func runBuild(src, out string, opts *compileopts.Options) error {
return Build(src, out, opts)
}
-func runTest(path, target string, t *testing.T) {
+func runTest(path, target string, t *testing.T, environmentVars ...string) {
// Get the expected output for this test.
txtpath := path[:len(path)-3] + ".txt"
if path[len(path)-1] == os.PathSeparator {
@@ -182,6 +185,7 @@ func runTest(path, target string, t *testing.T) {
ranTooLong := false
if target == "" {
cmd = exec.Command(binary)
+ cmd.Env = append(cmd.Env, environmentVars...)
} else {
spec, err := compileopts.LoadTarget(target)
if err != nil {
@@ -193,6 +197,14 @@ func runTest(path, target string, t *testing.T) {
args := append(spec.Emulator[1:], binary)
cmd = exec.Command(spec.Emulator[0], args...)
}
+
+ if len(spec.Emulator) != 0 && spec.Emulator[0] == "wasmtime" {
+ for _, v := range environmentVars {
+ cmd.Args = append(cmd.Args, "--env", v)
+ }
+ } else {
+ cmd.Env = append(cmd.Env, environmentVars...)
+ }
}
stdout := &bytes.Buffer{}
cmd.Stdout = stdout