From 51abbf27ae63209a49666de027e4fa81e7d367db Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 14 Jan 2020 09:25:50 -0800 Subject: [PATCH] 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 https://github.com/CraneStation/wasi-libc/pull/159. --- tests/general/env-absent.c | 7 +++++++ tests/general/env-absent.c.stdout.expected | 1 + tests/general/env.c | 7 +++++++ tests/general/env.c.env | 1 + tests/general/env.c.stdout.expected | 1 + tests/testcase.sh | 9 ++++++++- 6 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/general/env-absent.c create mode 100644 tests/general/env-absent.c.stdout.expected create mode 100644 tests/general/env.c create mode 100644 tests/general/env.c.env create mode 100644 tests/general/env.c.stdout.expected diff --git a/tests/general/env-absent.c b/tests/general/env-absent.c new file mode 100644 index 0000000..b5f6284 --- /dev/null +++ b/tests/general/env-absent.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + printf("HELLO = %s\n", getenv("HELLO")); + return 0; +} diff --git a/tests/general/env-absent.c.stdout.expected b/tests/general/env-absent.c.stdout.expected new file mode 100644 index 0000000..f5614c3 --- /dev/null +++ b/tests/general/env-absent.c.stdout.expected @@ -0,0 +1 @@ +HELLO = (null) diff --git a/tests/general/env.c b/tests/general/env.c new file mode 100644 index 0000000..b5f6284 --- /dev/null +++ b/tests/general/env.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + printf("HELLO = %s\n", getenv("HELLO")); + return 0; +} diff --git a/tests/general/env.c.env b/tests/general/env.c.env new file mode 100644 index 0000000..9be21df --- /dev/null +++ b/tests/general/env.c.env @@ -0,0 +1 @@ +HELLO=hello diff --git a/tests/general/env.c.stdout.expected b/tests/general/env.c.stdout.expected new file mode 100644 index 0000000..b9a2a66 --- /dev/null +++ b/tests/general/env.c.stdout.expected @@ -0,0 +1 @@ +HELLO = hello diff --git a/tests/testcase.sh b/tests/testcase.sh index 61deefb..d2da956 100755 --- a/tests/testcase.sh +++ b/tests/testcase.sh @@ -41,9 +41,16 @@ else stdin="/dev/null" fi +# Determine any environment variables to set. +if [ -e "$input.env" ]; then + env=$(sed -e 's/^/--env /' < "$input.env") +else + env="" +fi + # Run the test, capturing stdout, stderr, and the exit status. exit_status=0 -"$runwasi" "$wasm" \ +"$runwasi" $env "$wasm" \ < "$stdin" \ > "$stdout_observed" \ 2> "$stderr_observed" \