tests/libtest: Allow appending actions to be run on EXIT
Currently if a test script adds a trap on `EXIT` to run some cleanup, it will stomp on the existing trap to run `save_core()`. Allow for scripts to append actions that will run on exit by introducing an array that will be iterated over by a single exit runner. Closes: #1799 Approved by: cgwalters
This commit is contained in:
parent
b6979e7572
commit
0dd27bbf4b
|
|
@ -34,13 +34,24 @@ else
|
||||||
fi
|
fi
|
||||||
. ${test_srcdir}/libtest-core.sh
|
. ${test_srcdir}/libtest-core.sh
|
||||||
|
|
||||||
|
# Array of expressions to execute when exiting. Each expression should
|
||||||
|
# be a single string (quoting if necessary) that will be eval'd. To add
|
||||||
|
# a command to run on exit, append to the libtest_exit_cmds array like
|
||||||
|
# libtest_exit_cmds+=(expr).
|
||||||
|
libtest_exit_cmds=()
|
||||||
|
run_exit_cmds() {
|
||||||
|
for expr in "${libtest_exit_cmds[@]}"; do
|
||||||
|
eval "${expr}" || true
|
||||||
|
done
|
||||||
|
}
|
||||||
|
trap run_exit_cmds EXIT
|
||||||
|
|
||||||
save_core() {
|
save_core() {
|
||||||
if [ -e core ]; then
|
if [ -e core ]; then
|
||||||
cp core "$test_srcdir/core"
|
cp core "$test_srcdir/core"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
libtest_exit_cmds+=(save_core)
|
||||||
trap save_core EXIT;
|
|
||||||
|
|
||||||
test_tmpdir=$(pwd)
|
test_tmpdir=$(pwd)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ _mount_cleanup () {
|
||||||
|
|
||||||
case "${TEST_SKIP_CLEANUP:-}" in
|
case "${TEST_SKIP_CLEANUP:-}" in
|
||||||
no|"")
|
no|"")
|
||||||
trap _mount_cleanup EXIT
|
libtest_exit_cmds+=(_mount_cleanup)
|
||||||
;;
|
;;
|
||||||
err)
|
err)
|
||||||
trap _mount_cleanup ERR
|
trap _mount_cleanup ERR
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ rofiles-fuse checkout-test2 mnt
|
||||||
cleanup_fuse() {
|
cleanup_fuse() {
|
||||||
fusermount -u ${test_tmpdir}/mnt || true
|
fusermount -u ${test_tmpdir}/mnt || true
|
||||||
}
|
}
|
||||||
trap cleanup_fuse EXIT
|
libtest_exit_cmds+=(cleanup_fuse)
|
||||||
assert_file_has_content mnt/firstfile first
|
assert_file_has_content mnt/firstfile first
|
||||||
echo "ok mount"
|
echo "ok mount"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue