summaryrefslogtreecommitdiffstats
path: root/tests/shell/run-tests.sh
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2019-01-04 15:57:00 +0100
committerFlorian Westphal <fw@strlen.de>2019-01-04 16:00:31 +0100
commit4d26b6dd3c4c8354a88c4a1aef8ea33229f0a4cc (patch)
tree1e82c9b480038033c65cd7d17b08f24e149bcd82 /tests/shell/run-tests.sh
parenteb49882deb3e9ec5eccd6e6106b454e3a6394408 (diff)
tests: shell: change all test scripts to return 0
The shell-based tests currently encode a return value in the file name, i.e. foo_1 expects that the script should return '1' for the test case to pass. This is very error prone, and one test case is even broken (i.e., it returns 1, but because of a different, earlier error). do_something || exit 1 or 'set -e' are both pretty common patterns, in both cases tests should fail. In those test-cases that deliberately test for an error, nft something_should_fail || exit 0 nft something_should_fail && exit 1 or a similar constructs should be used. This initial commit modififies all '_1' scripts to return 0 on success, usually via 'nft wrong || exit 0'. All tests pass, except the one broken test case that hasn't worked before either, but where 'set -e' use made it pass (the failing command is supposed to work, and the command that is supposed to fail is never run). Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tests/shell/run-tests.sh')
-rwxr-xr-xtests/shell/run-tests.sh15
1 files changed, 6 insertions, 9 deletions
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index fdca5fb3..6b693cc1 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -4,7 +4,6 @@
TESTDIR="./$(dirname $0)/"
RETURNCODE_SEPARATOR="_"
SRC_NFT="$(dirname $0)/../../src/nft"
-POSITIVE_RET=0
DIFF=$(which diff)
msg_error() {
@@ -102,29 +101,27 @@ for testfile in $(find_tests)
do
kernel_cleanup
- rc_spec=$(awk -F${RETURNCODE_SEPARATOR} '{print $NF}' <<< $testfile)
-
msg_info "[EXECUTING] $testfile"
test_output=$(NFT=$NFT ${testfile} 2>&1)
rc_got=$?
echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
- if [ "$rc_got" == "$rc_spec" ] ; then
+ if [ "$rc_got" -eq 0 ] ; then
# check nft dump only for positive tests
- rc_spec="${POSITIVE_RET}"
dumppath="$(dirname ${testfile})/dumps"
dumpfile="${dumppath}/$(basename ${testfile}).nft"
- if [ "$rc_got" == "${POSITIVE_RET}" ] && [ -f ${dumpfile} ]; then
+ rc_spec=0
+ if [ "$rc_got" -eq 0 ] && [ -f ${dumpfile} ]; then
test_output=$(${DIFF} ${dumpfile} <($NFT list ruleset) 2>&1)
rc_spec=$?
fi
- if [ "$rc_spec" == "${POSITIVE_RET}" ]; then
+ if [ "$rc_spec" -eq 0 ]; then
msg_info "[OK] $testfile"
[ "$VERBOSE" == "y" ] && [ ! -z "$test_output" ] && echo "$test_output"
((ok++))
- if [ "$DUMPGEN" == "y" ] && [ "$rc_got" == "${POSITIVE_RET}" ] && [ ! -f "${dumpfile}" ]; then
+ if [ "$DUMPGEN" == "y" ] && [ "$rc_got" == 0 ] && [ ! -f "${dumpfile}" ]; then
mkdir -p "${dumppath}"
nft list ruleset > "${dumpfile}"
fi
@@ -140,7 +137,7 @@ do
else
((failed++))
if [ "$VERBOSE" == "y" ] ; then
- msg_warn "[FAILED] $testfile: expected $rc_spec but got $rc_got"
+ msg_warn "[FAILED] $testfile: got $rc_got"
[ ! -z "$test_output" ] && echo "$test_output"
else
msg_warn "[FAILED] $testfile"