X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=test%2Ftestlib.sh.in;h=ec8f400f5365d47dd31e8bc1a60369cb1931e4b8;hp=224ab4f9f6847ef1e184041c8fb8e13799b8c857;hb=7e09765003114ba37fed2851d9126924d0f813f1;hpb=d72a450975bed625e058eb857410f0d78caee2d1 diff --git a/test/testlib.sh.in b/test/testlib.sh.in index 224ab4f9..ec8f400f 100644 --- a/test/testlib.sh.in +++ b/test/testlib.sh.in @@ -26,6 +26,8 @@ SPTPS_KEYPAIR=$(realdir "../src/sptps_keypair@EXEEXT@") # Exit status list # shellcheck disable=SC2034 +EXIT_FAILURE=1 +# shellcheck disable=SC2034 EXIT_SKIP_TEST=77 # The list of the environment variables that tinc injects into the scripts it calls. @@ -98,6 +100,19 @@ must_fail() { fi } +# Executes whatever is passed to it, checking that the resulting exit code is equal to the first argument. +expect_code() { + expected=$1 + shift + + code=0 + "$@" || code=$? + + if [ $code != "$expected" ]; then + bail "wrong exit code $code, expected $expected" + fi +} + # Runs its arguments with timeout(1) or gtimeout(1) if either are installed. # Usage: try_limit_time 10 command --with --args if type timeout >/dev/null; then