@@ -58,6 +58,9 @@ func TestCompiler(t *testing.T) {
58
58
if runtime .GOOS != "windows" {
59
59
t .Run ("Host" , func (t * testing.T ) {
60
60
runPlatTests ("" , matches , t )
61
+ if runtime .GOOS == "darwin" {
62
+ runTest ("testdata/libc/env.go" , "" , t , []string {"ENV1=VALUE1" , "ENV2=VALUE2" }... )
63
+ }
61
64
})
62
65
}
63
66
@@ -104,6 +107,7 @@ func TestCompiler(t *testing.T) {
104
107
105
108
t .Run ("WASI" , func (t * testing.T ) {
106
109
runPlatTests ("wasi" , matches , t )
110
+ runTest ("testdata/libc/env.go" , "wasi" , t , []string {"ENV1=VALUE1" , "ENV2=VALUE2" }... )
107
111
})
108
112
}
109
113
}
@@ -113,7 +117,6 @@ func runPlatTests(target string, matches []string, t *testing.T) {
113
117
114
118
for _ , path := range matches {
115
119
path := path // redefine to avoid race condition
116
-
117
120
t .Run (filepath .Base (path ), func (t * testing.T ) {
118
121
t .Parallel ()
119
122
runTest (path , target , t )
@@ -133,7 +136,7 @@ func runBuild(src, out string, opts *compileopts.Options) error {
133
136
return Build (src , out , opts )
134
137
}
135
138
136
- func runTest (path , target string , t * testing.T ) {
139
+ func runTest (path , target string , t * testing.T , environmentVars ... string ) {
137
140
// Get the expected output for this test.
138
141
txtpath := path [:len (path )- 3 ] + ".txt"
139
142
if path [len (path )- 1 ] == os .PathSeparator {
@@ -182,6 +185,7 @@ func runTest(path, target string, t *testing.T) {
182
185
ranTooLong := false
183
186
if target == "" {
184
187
cmd = exec .Command (binary )
188
+ cmd .Env = append (cmd .Env , environmentVars ... )
185
189
} else {
186
190
spec , err := compileopts .LoadTarget (target )
187
191
if err != nil {
@@ -193,6 +197,14 @@ func runTest(path, target string, t *testing.T) {
193
197
args := append (spec .Emulator [1 :], binary )
194
198
cmd = exec .Command (spec .Emulator [0 ], args ... )
195
199
}
200
+
201
+ if len (spec .Emulator ) != 0 && spec .Emulator [0 ] == "wasmtime" {
202
+ for _ , v := range environmentVars {
203
+ cmd .Args = append (cmd .Args , "--env" , v )
204
+ }
205
+ } else {
206
+ cmd .Env = append (cmd .Env , environmentVars ... )
207
+ }
196
208
}
197
209
stdout := & bytes.Buffer {}
198
210
cmd .Stdout = stdout
0 commit comments