diff options
author | Thomas Haller <thaller@redhat.com> | 2023-10-16 21:43:08 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2023-10-21 11:58:20 +0200 |
commit | 8cacebc36732fe190a991d512e60e4fcbfc782eb (patch) | |
tree | d1c8f6ac488564229ec47ce1f740d897ef621f26 /tests/shell/helpers/test-wrapper.sh | |
parent | 22fab8681a50014174cdd02ace90f74b9e9eefe9 (diff) |
tests/shell: honor NFT_TEST_VERBOSE_TEST variable to debug tests via `bash -x`
It can be cumbersome to debug why a test fails. Our tests are just shell
scripts, which for the most part don't print much. That is good, but for
debugging, it can be useful to run the test via `bash -x`. Previously,
we would just patch the source file while debugging.
Add an option "-x" and NFT_TEST_VERBOSE_TEST=y environment variable. If set,
"test-wrapper.sh" will check whether the shebang is "#!/bin/bash" and add
"-x" to the command line.
While at it, let test-wrapper.sh also log a line like
Command: $CMD
With this, we see in the log the command that was run, and how
NFT_TEST_VERBOSE_TEST may have affected it. This is anyway useful,
because many tests don't print anything at all, and we end up with an
empty "testout.log". Empty files are cumbersome, e.g. I like to use
`grep -R ^` to show the content of all files, which does not show empty
files. Ensuring that something is always written is desirable.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tests/shell/helpers/test-wrapper.sh')
-rwxr-xr-x | tests/shell/helpers/test-wrapper.sh | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/shell/helpers/test-wrapper.sh b/tests/shell/helpers/test-wrapper.sh index 13b918f8..872a0c56 100755 --- a/tests/shell/helpers/test-wrapper.sh +++ b/tests/shell/helpers/test-wrapper.sh @@ -93,7 +93,20 @@ if [ "$rc_test" -eq 0 ] ; then fi if [ "$rc_test" -eq 0 ] ; then - "$TEST" &>> "$NFT_TEST_TESTTMPDIR/testout.log" || rc_test=$? + CMD=( "$TEST" ) + if [ "$NFT_TEST_VERBOSE_TEST" = y ] ; then + X="$(sed -n '1 s/^#!\(\/bin\/bash\>.*$\)/\1/p' "$TEST" 2>/dev/null)" + if [ -n "$X" ] ; then + # Note that kernel parses the shebang differently and does not + # word splitting for the arguments. We do split the arguments here + # which would matter if there are spaces. For our tests, there + # are either no arguments or only one argument without space. So + # this is good enough. + CMD=( $X -x "$TEST" ) + fi + fi + printf "Command: $(printf '%q ' "${CMD[@]}")\n" &>> "$NFT_TEST_TESTTMPDIR/testout.log" + "${CMD[@]}" &>> "$NFT_TEST_TESTTMPDIR/testout.log" || rc_test=$? fi $NFT list ruleset > "$NFT_TEST_TESTTMPDIR/ruleset-after" |