Skip to content

Commit 51abbf2

Browse files
committed
Add a test for environment variables.
This adds basic support for environment variables to the test harness, and adds a simple test. This tests the bug found in WebAssembly/wasi-libc#159.
1 parent 677ffc7 commit 51abbf2

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

tests/general/env-absent.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
int main(void) {
5+
printf("HELLO = %s\n", getenv("HELLO"));
6+
return 0;
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HELLO = (null)

tests/general/env.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
int main(void) {
5+
printf("HELLO = %s\n", getenv("HELLO"));
6+
return 0;
7+
}

tests/general/env.c.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HELLO=hello
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HELLO = hello

tests/testcase.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ else
4141
stdin="/dev/null"
4242
fi
4343

44+
# Determine any environment variables to set.
45+
if [ -e "$input.env" ]; then
46+
env=$(sed -e 's/^/--env /' < "$input.env")
47+
else
48+
env=""
49+
fi
50+
4451
# Run the test, capturing stdout, stderr, and the exit status.
4552
exit_status=0
46-
"$runwasi" "$wasm" \
53+
"$runwasi" $env "$wasm" \
4754
< "$stdin" \
4855
> "$stdout_observed" \
4956
2> "$stderr_observed" \

0 commit comments

Comments
 (0)