]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tools: simplify error handling in "check-tree.sh" by adding msg_err()/msg_warn()
authorThomas Haller <thaller@redhat.com>
Tue, 14 Nov 2023 16:08:29 +0000 (17:08 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 15 Nov 2023 12:12:06 +0000 (13:12 +0100)
msg_err() also sets EXIT_CODE=, so we don't have to duplicate this.

Also add msg_warn() to print non-fatal warnings. Will be used in the
future. As "check-tree.sh" tests the consistency of the source tree, a
warning only makes sense to point something out that really should be
fixed, but is not yet.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tools/check-tree.sh

index e3ddf8bdea5824f341535fc575e91ce066b9435e..b16d37c4651b6784ab06d1f6c7cf0a20bae02a27 100755 (executable)
@@ -25,6 +25,15 @@ cd "$(dirname "$0")/.."
 
 EXIT_CODE=0
 
+msg_err() {
+       printf "ERR:  %s\n" "$*"
+       EXIT_CODE=1
+}
+
+msg_warn() {
+       printf "WARN: %s\n" "$*"
+}
+
 ##############################################################################
 
 check_shell_dumps() {
@@ -37,8 +46,7 @@ check_shell_dumps() {
        local nodump_name
 
        if [ ! -d "$dir/dumps/" ] ; then
-               echo "\"$TEST\" has no \"$dir/dumps/\" directory"
-               EXIT_CODE=1
+               msg_err "\"$TEST\" has no \"$dir/dumps/\" directory"
                return 0
        fi
 
@@ -49,34 +57,31 @@ check_shell_dumps() {
        [ -f "$nodump_name" ] && has_nodump=1
 
        if [ "$has_nft" != 1 -a "$has_nodump" != 1 ] ; then
-               echo "\"$TEST\" has no \"$dir/dumps/$base.{nft,nodump}\" file"
-               EXIT_CODE=1
+               msg_err "\"$TEST\" has no \"$dir/dumps/$base.{nft,nodump}\" file"
        elif [ "$has_nft" == 1 -a "$has_nodump" == 1 ] ; then
-               echo "\"$TEST\" has both \"$dir/dumps/$base.{nft,nodump}\" files"
-               EXIT_CODE=1
+               msg_err "\"$TEST\" has both \"$dir/dumps/$base.{nft,nodump}\" files"
        elif [ "$has_nodump" == 1 -a -s "$nodump_name" ] ; then
-               echo "\"$TEST\" has a non-empty \"$dir/dumps/$base.nodump\" file"
-               EXIT_CODE=1
+               msg_err "\"$TEST\" has a non-empty \"$dir/dumps/$base.nodump\" file"
        fi
 }
 
 SHELL_TESTS=( $(find "tests/shell/testcases/" -type f -executable | sort) )
 
 if [ "${#SHELL_TESTS[@]}" -eq 0 ] ; then
-       echo "No executable tests under \"tests/shell/testcases/\" found"
-       EXIT_CODE=1
+       msg_err "No executable tests under \"tests/shell/testcases/\" found"
 fi
 for t in "${SHELL_TESTS[@]}" ; do
        check_shell_dumps "$t"
-       head -n 1 "$t" |grep -q  '^#!/bin/sh' && echo "$t uses sh instead of bash" && EXIT_CODE=1
+       if head -n 1 "$t" |grep -q  '^#!/bin/sh' ; then
+               msg_err "$t uses #!/bin/sh instead of /bin/bash"
+       fi
 done
 
 ##############################################################################
 
 SHELL_TESTS2=( $(./tests/shell/run-tests.sh --list-tests) )
 if [ "${SHELL_TESTS[*]}" != "${SHELL_TESTS2[*]}" ] ; then
-       echo "\`./tests/shell/run-tests.sh --list-tests\` does not list the expected tests"
-       EXIT_CODE=1
+       msg_err "\`./tests/shell/run-tests.sh --list-tests\` does not list the expected tests"
 fi
 
 ##############################################################################
@@ -85,8 +90,7 @@ F=( $(find tests/shell/testcases/ -type f | grep '^tests/shell/testcases/[^/]\+/
 IGNORED_FILES=( tests/shell/testcases/bogons/nft-f/* )
 for f in "${F[@]}" ; do
        if ! array_contains "$f" "${SHELL_TESTS[@]}" "${IGNORED_FILES[@]}" ; then
-               echo "Unexpected file \"$f\""
-               EXIT_CODE=1
+               msg_err "Unexpected file \"$f\""
        fi
 done
 
@@ -97,8 +101,7 @@ FILES=( $(find "tests/shell/testcases/" -type f | sed -n 's#\(tests/shell/testca
 for f in "${FILES[@]}" ; do
        f2="$(echo "$f" | sed -n 's#\(tests/shell/testcases\(/.*\)\?/\)dumps/\(.*\)\.\(nft\|nodump\)$#\1\3#p')"
        if ! array_contains "$f2" "${SHELL_TESTS[@]}" ; then
-               echo "\"$f\" has no test \"$f2\""
-               EXIT_CODE=1
+               msg_err "\"$f\" has no test \"$f2\""
        fi
 done