]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/shell: implement NFT_TEST_HAVE_json feature detection as script
authorThomas Haller <thaller@redhat.com>
Mon, 18 Sep 2023 10:28:27 +0000 (12:28 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 18 Sep 2023 11:08:59 +0000 (13:08 +0200)
No more need to special case the "run a script" approach for detecting
the json feature. Use the new mechanism instead.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/features/json.sh [new file with mode: 0755]
tests/shell/run-tests.sh

diff --git a/tests/shell/features/json.sh b/tests/shell/features/json.sh
new file mode 100755 (executable)
index 0000000..d811570
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Detect JSON support. Note that $NFT may not be the binary from our build
+# tree, hence we detect it by running the binary (instead of asking the build
+# configuration).
+$NFT -j list ruleset
index 9c7e280e31c792e5657054059c04e03512fadcbd..528646f57eca9796f87a1f16e2587b72da1e3139 100755 (executable)
@@ -221,8 +221,7 @@ NFT_TEST_BASEDIR="$(dirname "$0")"
 # Export the base directory. It may be used by tests.
 export NFT_TEST_BASEDIR
 
-_HAVE_OPTS=( json )
-_HAVE_OPTS_NFT=()
+_HAVE_OPTS=()
 shopt -s nullglob
 F=( "$NFT_TEST_BASEDIR/features/"*.nft "$NFT_TEST_BASEDIR/features/"*.sh )
 shopt -u nullglob
@@ -230,13 +229,12 @@ for file in "${F[@]}"; do
        feat="${file##*/}"
        feat="${feat%.*}"
        re="^[a-z_0-9]+$"
-       if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" "${_HAVE_OPTS_NFT[@]}" && [[ "$file" != *.sh || -x "$file" ]] ; then
-               _HAVE_OPTS_NFT+=( "$feat" )
+       if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" && [[ "$file" != *.sh || -x "$file" ]] ; then
+               _HAVE_OPTS+=( "$feat" )
        else
                msg_warn "Ignore feature file \"$file\""
        fi
 done
-_HAVE_OPTS+=( "${_HAVE_OPTS_NFT[@]}" )
 _HAVE_OPTS=( $(printf '%s\n' "${_HAVE_OPTS[@]}" | LANG=C sort) )
 
 for KEY in $(compgen -v | grep '^NFT_TEST_HAVE_' | sort) ; do
@@ -486,14 +484,6 @@ fi
 
 NFT_REAL="${NFT_REAL-$NFT}"
 
-if [ -z "${NFT_TEST_HAVE_json+x}" ] ; then
-       NFT_TEST_HAVE_json=y
-       $NFT_TEST_UNSHARE_CMD "$NFT_REAL" -j list ruleset &>/dev/null || NFT_TEST_HAVE_json=n
-else
-       NFT_TEST_HAVE_json="$(bool_n "$NFT_TEST_HAVE_json")"
-fi
-export NFT_TEST_HAVE_json
-
 feature_probe()
 {
        local with_path="$NFT_TEST_BASEDIR/features/$1"
@@ -511,7 +501,7 @@ feature_probe()
        return 1
 }
 
-for feat in "${_HAVE_OPTS_NFT[@]}" ; do
+for feat in "${_HAVE_OPTS[@]}" ; do
        var="NFT_TEST_HAVE_$feat"
        if [ -z "${!var+x}" ] ; then
                val='y'