diff --git a/tests/.gitignore b/tests/.gitignore index 8ac0ced..16e760f 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,2 +1,3 @@ *.observed +*.observed.filtered *.wasm diff --git a/tests/general/abort.c b/tests/general/abort.c new file mode 100644 index 0000000..ddac207 --- /dev/null +++ b/tests/general/abort.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + abort(); + return 0; +} diff --git a/tests/general/abort.c.exit_status.expected b/tests/general/abort.c.exit_status.expected new file mode 100644 index 0000000..405e2af --- /dev/null +++ b/tests/general/abort.c.exit_status.expected @@ -0,0 +1 @@ +134 diff --git a/tests/general/abort.c.stderr.expected b/tests/general/abort.c.stderr.expected new file mode 100644 index 0000000..dbcd5f3 --- /dev/null +++ b/tests/general/abort.c.stderr.expected @@ -0,0 +1,6 @@ +Error: failed to run main module `abort.c.---.wasm` + +Caused by: + 0: failed to invoke `_start` + 1: wasm trap: unreachable, source location: @---- + wasm backtrace: diff --git a/tests/general/abort.c.stderr.expected.filter b/tests/general/abort.c.stderr.expected.filter new file mode 100755 index 0000000..b9f9c66 --- /dev/null +++ b/tests/general/abort.c.stderr.expected.filter @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +cat \ + | sed -e 's/main module `abort\.c\.[^`]*\.wasm`/main module `abort.c.---.wasm`/' \ + | sed -e 's/source location: @[[:xdigit:]]*$/source location: @----/' \ + | head -n 6 diff --git a/tests/general/assert-fail.c b/tests/general/assert-fail.c new file mode 100644 index 0000000..07f4557 --- /dev/null +++ b/tests/general/assert-fail.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + assert(false); + return 0; +} diff --git a/tests/general/assert-fail.c.exit_status.expected b/tests/general/assert-fail.c.exit_status.expected new file mode 100644 index 0000000..405e2af --- /dev/null +++ b/tests/general/assert-fail.c.exit_status.expected @@ -0,0 +1 @@ +134 diff --git a/tests/general/assert-fail.c.stderr.expected b/tests/general/assert-fail.c.stderr.expected new file mode 100644 index 0000000..db6da54 --- /dev/null +++ b/tests/general/assert-fail.c.stderr.expected @@ -0,0 +1,7 @@ +Assertion failed: false (assert-fail.c: main: 5) +Error: failed to run main module `assert-fail.c.---.wasm` + +Caused by: + 0: failed to invoke `_start` + 1: wasm trap: unreachable, source location: @---- + wasm backtrace: diff --git a/tests/general/assert-fail.c.stderr.expected.filter b/tests/general/assert-fail.c.stderr.expected.filter new file mode 100755 index 0000000..df075b1 --- /dev/null +++ b/tests/general/assert-fail.c.stderr.expected.filter @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +cat \ + | sed -e 's/main module `assert-fail\.c\.[^`]*\.wasm`/main module `assert-fail.c.---.wasm`/' \ + | sed -e 's/source location: @[[:xdigit:]]*$/source location: @----/' \ + | head -n 7 diff --git a/tests/general/assert-pass.c b/tests/general/assert-pass.c new file mode 100644 index 0000000..e57329f --- /dev/null +++ b/tests/general/assert-pass.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + assert(true); + return 0; +} diff --git a/tests/general/environ.c b/tests/general/environ.c new file mode 100644 index 0000000..14dc955 --- /dev/null +++ b/tests/general/environ.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include +extern char **environ; + +int main(void) { + assert(environ != NULL); + for (char **p = environ; *p; ++p) { + assert(p != NULL); + } + for (char **p = environ; *p; ++p) { + if (strncmp(*p, "HELLO=", 5) == 0) { + printf("HELLO = %s\n", *p + 6); + } + } + return 0; +} diff --git a/tests/general/environ.c.env b/tests/general/environ.c.env new file mode 100644 index 0000000..9be21df --- /dev/null +++ b/tests/general/environ.c.env @@ -0,0 +1 @@ +HELLO=hello diff --git a/tests/general/environ.c.stdout.expected b/tests/general/environ.c.stdout.expected new file mode 100644 index 0000000..b9a2a66 --- /dev/null +++ b/tests/general/environ.c.stdout.expected @@ -0,0 +1 @@ +HELLO = hello diff --git a/tests/testcase.sh b/tests/testcase.sh index d2da956..e072243 100755 --- a/tests/testcase.sh +++ b/tests/testcase.sh @@ -60,11 +60,27 @@ echo $exit_status > "$exit_status_observed" # Determine the reference files to compare with. if [ -e "$input.stdout.expected" ]; then stdout_expected="$input.stdout.expected" + + # Apply output filters. + if [ -e "$input.stdout.expected.filter" ]; then + cat "$stdout_observed" \ + | "$input.stdout.expected.filter" \ + > "${stdout_observed}.filtered" + stdout_observed="${stdout_observed}.filtered" + fi else stdout_expected="/dev/null" fi if [ -e "$input.stderr.expected" ]; then stderr_expected="$input.stderr.expected" + + # Apply output filters. + if [ -e "$input.stderr.expected.filter" ]; then + cat "$stderr_observed" \ + | "./$input.stderr.expected.filter" \ + > "${stderr_observed}.filtered" + stderr_observed="${stderr_observed}.filtered" + fi else stderr_expected="/dev/null" fi