diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-24 23:14:15 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-01-26 10:47:56 +0100 |
commit | abe38e7e390cc17e6eae0ebe94d2006c548e095c (patch) | |
tree | 9c3e18b2ee6ad734440528dd54c66cb134579e85 /tests/custom | |
parent | 34a04a2d0c33bb50d8fa88e4ac808dabcb11c69c (diff) |
run_tests.sh: add ability to define environment variables for testcases
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom')
-rwxr-xr-x | tests/custom/run_tests.sh | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/custom/run_tests.sh b/tests/custom/run_tests.sh index c384973..d09859c 100755 --- a/tests/custom/run_tests.sh +++ b/tests/custom/run_tests.sh @@ -21,6 +21,12 @@ extract_sections() { outfile=$(printf "%s/%03d.args" "$dir" $count) printf "" > "$outfile" ;; + "-- Vars --") + tag="vars" + count=$((count + 1)) + outfile=$(printf "%s/%03d.vars" "$dir" $count) + printf "" > "$outfile" + ;; "-- Testcase --") tag="test" count=$((count + 1)) @@ -62,10 +68,23 @@ run_testcase() { local err=$5 local code=$6 local args=$7 + local vars=$8 local fail=0 ( cd "$topdir" + + IFS=$'\n' + + local var + for var in $vars; do + case "$var" in + *=*) export "$var" ;; + esac + done + + IFS=$' \t\n' + $ucode_bin $args -e '{ "REQUIRE_SEARCH_PATH": [ "'"$ucode_lib"'/*.so" ] }' -i - <"$in" >"$dir/res.out" 2>"$dir/res.err" ) @@ -122,21 +141,23 @@ run_test() { if [ $testcase_first = 1 ]; then # Flush previous test if [ -n "$ein" ]; then - run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" || failed=$((failed + 1)) + run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1)) eout="" eerr="" ecode="" eargs="" + evars="" fi ein=$res else - run_testcase $count "/tmp/test.$$" "$res" "$eout" "$eerr" "$ecode" "$eargs" || failed=$((failed + 1)) + run_testcase $count "/tmp/test.$$" "$res" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1)) eout="" eerr="" ecode="" eargs="" + evars="" fi ;; @@ -144,12 +165,13 @@ run_test() { *.stderr) eerr=$res ;; *.exitcode) ecode=$res ;; *.args) eargs=$(cat "$res") ;; + *.vars) evars=$(cat "$res") ;; esac done # Flush last test if [ $testcase_first = 1 ] && [ -n "$eout$eerr$ecode" ]; then - run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" || failed=$((failed + 1)) + run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1)) fi rm -r "/tmp/test.$$" |