test: add helper macro ATX_RUN

This is meant to be a workaround for a limitation of Autotest,
where `set -e` has no effect in AT_CHECK().

Also we don't want to use `trap ... ERR`, since it is not portable.
This commit is contained in:
CismonX 2025-03-05 07:01:34 +08:00
parent 9050d01fe4
commit 95121cb78f
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
3 changed files with 35 additions and 8 deletions

View file

@ -18,8 +18,10 @@ ATX_CHECK_LIB([
chmod +x $tmpdir/false.sh
# Check both read-only and read/write mode.
check-util-lib sandbox -r -d $tmpdir
check-util-lib sandbox -d $tmpdir
ATX_RUN([
check-util-lib sandbox -r -d $tmpdir
check-util-lib sandbox -d $tmpdir
])
])
AT_CLEANUP

View file

@ -14,7 +14,10 @@ ATX_CHECK_LIB([
tmpdir=./$(ath_fn_rand_u64_hex).tmp.d
mkdir $tmpdir
check-util-lib watcher -d $tmpdir
ATX_RUN([
check-util-lib watcher -d $tmpdir
])
])
AT_CLEANUP

View file

@ -46,12 +46,34 @@ m4_define([ATX_FEAT_PREREQ], [
fi
])
dnl
dnl ATX_RUN_ONE(cmd)
dnl
dnl Run a pipeline of shell command(s).
dnl If it exits with a non-zero status, fail the current test.
dnl
m4_define([ATX_RUN_ONE], [
m4_ifnblank([$1], [
if $1; then :
else
echo "exit status: $?"
ATX_FAIL
fi
])
])
dnl
dnl ATX_RUN(cmd_list)
dnl
dnl Like ATX_RUN_ONE, but takes multiple pipelines, separated by newline.
dnl If any exits with a non-zero status, fail the current test.
dnl
m4_define([ATX_RUN], [
m4_map([ATX_RUN_ONE], m4_split([$1], m4_newline([+])))
])
m4_define([ATX_CHECK_SIMPLE], [
AT_CHECK([
atx_line_start=$LINENO
trap 'echo "Error $? at line $(($LINENO-$atx_line_start))"; exit 1' ERR
$1
], , [ignore], [ignore])
AT_CHECK([$1], , [ignore], [ignore])
])
m4_define([ATX_CHECK_LIB], [