bookmarkfs/tests/testsuite.at
2025-03-22 11:38:59 +08:00

125 lines
2.8 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 Fail or skip the current test.
dnl
dnl The status codes are defined by Autotest.
dnl
m4_define([ATX_FAIL], [exit 99])
m4_define([ATX_SKIP], [exit 77])
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 -z "m4_map([ATX_FEAT_VAR], [$@])"; then
ATX_SKIP
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([+])))
])
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])