@@ -4,30 +4,37 @@ set -ueo pipefail
44# A simple testcase runner that runs a command, captures all its command-line
55# outputs, and compares them against expected outputs.
66
7+ # Command-line parsing; this script is meant to be run from a # higher-level
8+ # script, so don't do anything fancy.
79runwasi=" $1 "
810clang=" $2 "
911options=" $3 "
1012input=" $4 "
1113
14+ # Compile names for generated files.
1215wasm=" $input .$options .wasm"
1316stdout_observed=" $input .$options .stdout.observed"
1417stderr_observed=" $input .$options .stderr.observed"
1518exit_status_observed=" $input .$options .exit_status.observed"
1619
20+ # Optionally load compiler options from a file.
1721if [ -e " $input .options" ]; then
18- file_options=$( cat " $inpit .options" )
22+ file_options=$( cat " $input .options" )
1923else
2024 file_options=
2125fi
2226
2327echo " Testing $input ..."
28+
29+ # Determine the input file to write to stdin.
2430" $clang " $options $file_options " $input " -o " $wasm "
2531if [ -e " $input .stdin" ]; then
2632 stdin=" $input .stdin"
2733else
2834 stdin=" /dev/null"
2935fi
3036
37+ # Run the test, capturing stdout, stderr, and the exit status.
3138exit_status=0
3239" $runwasi " " $wasm " \
3340 < " $stdin " \
@@ -36,6 +43,7 @@ exit_status=0
3643 || exit_status=$?
3744echo $exit_status > " $exit_status_observed "
3845
46+ # Determine the reference files to compare with.
3947if [ -e " $input .stdout.expected" ]; then
4048 stdout_expected=" $input .stdout.expected"
4149else
5260 exit_status_expected=../exit_status_zero
5361fi
5462
63+ # If there are any differences, diff will return a non-zero exit status, and
64+ # since this script uses "set -e", it will return a non-zero exit status too.
5565diff -u " $stderr_expected " " $stderr_observed "
5666diff -u " $stdout_expected " " $stdout_observed "
5767diff -u " $exit_status_expected " " $exit_status_observed "
0 commit comments