bookmarkfs/tests/testsuite.at
CismonX bced141b98
test: misc fix and refactor
- Do not exit with status 99.  It is considered a "hard failure"
  in Autotest, and cleanup script won't be executed.
- Fix ATX_FEAT_PREREQ().
- Remove unneeded helper macros.
- Add more log output.
2025-03-24 19:30:32 +08:00

118 lines
2.7 KiB
Text

dnl
dnl Copyright (C) 2025 CismonX <admin@cismon.net>
dnl
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty,
dnl provided the copyright notice and this notice are preserved.
dnl This file is offered as-is, without any warranty.
dnl
AT_INIT
dnl
dnl ATX_REPEAT(n, string)
dnl
dnl Repeat string n times.
dnl
m4_define([ATX_REPEAT], [m4_for([unused_], [1], [$1], , [$2])])
dnl
dnl ATX_FEAT_VAR(feature)
dnl
dnl Expands to the shell variable indicating whether the given feature
dnl is defined by EX_FEAT() and enabled during `configure`.
dnl
dnl A non-empty value indicates that the feature is enabled.
dnl
m4_define([ATX_FEAT_VAR], [[${feat_]m4_translit($1, [-], [_])[}]])
dnl
dnl ATX_FEAT_IF(feature, [action-if-enabled], [action-if-disabled])
dnl
dnl Conditionally run script depending on whether a feature is enabled.
dnl
m4_define([ATX_FEAT_IF], [
if test -n "ATX_FEAT_VAR($1)"; then :
$2
else :
$3
fi
])
dnl
dnl ATX_FEAT_PREREQ(features...)
dnl
dnl If any of the given features is not enabled, skip the current test.
dnl
m4_define([ATX_FEAT_PREREQ], [
if test "m4_map([ATX_FEAT_VAR], [$@])" != ATX_REPEAT([$#], [y]); then
exit 77
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], [$1 || exit $?])
])
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([+])))
])
dnl
dnl ATX_CHECK_SIMPLE(script)
dnl
m4_define([ATX_CHECK_SIMPLE], [
AT_CHECK([$1], , [ignore], [ignore])
])
dnl
dnl ATX_CHECK_LIB(script)
dnl
m4_define([ATX_CHECK_LIB], [
ATX_CHECK_SIMPLE([
ATX_FEAT_PREREQ([bookmarkfs-util])
$1
])
])
dnl -- Helper functions --
AT_TEST_HELPER_FN([rand_u64_hex], , , [
echo $(od -vAn -N8 -tx8 /dev/urandom | tr -d ' ')
])
AT_TEST_HELPER_FN([rand_base64], , , [
# The `base64` utility is not specified by POSIX,
# but present in GNU Coreutils, BusyBox and the FreeBSD base system.
echo $(head -c$1 /dev/urandom | base64 -w0)
])
AT_TEST_HELPER_FN([prng_seed], , , [
seed_1=$(ath_fn_rand_u64_hex)
seed_2=$(ath_fn_rand_u64_hex)
seed_3=$(ath_fn_rand_u64_hex)
seed_4=$(ath_fn_rand_u64_hex)
echo $seed_1$seed_2$seed_3$seed_4
])
dnl -- Test groups --
AT_BANNER([The Utility Library])
m4_include([lib_hash.at])
m4_include([lib_prng.at])
m4_include([lib_watcher.at])
m4_include([lib_sandbox.at])
m4_include([lib_hashmap.at])