diff --git a/tests/libtest.sh b/tests/libtest.sh index 99d7c967..e70b7b87 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -34,13 +34,24 @@ else fi . ${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() { if [ -e core ]; then cp core "$test_srcdir/core" fi } - -trap save_core EXIT; +libtest_exit_cmds+=(save_core) test_tmpdir=$(pwd) diff --git a/tests/test-repo-finder-mount-integration.sh b/tests/test-repo-finder-mount-integration.sh index 243df591..9ecc4cd6 100755 --- a/tests/test-repo-finder-mount-integration.sh +++ b/tests/test-repo-finder-mount-integration.sh @@ -55,7 +55,7 @@ _mount_cleanup () { case "${TEST_SKIP_CLEANUP:-}" in no|"") - trap _mount_cleanup EXIT + libtest_exit_cmds+=(_mount_cleanup) ;; err) trap _mount_cleanup ERR diff --git a/tests/test-rofiles-fuse.sh b/tests/test-rofiles-fuse.sh index 7b7474d0..1e09711c 100755 --- a/tests/test-rofiles-fuse.sh +++ b/tests/test-rofiles-fuse.sh @@ -41,7 +41,7 @@ rofiles-fuse checkout-test2 mnt cleanup_fuse() { fusermount -u ${test_tmpdir}/mnt || true } -trap cleanup_fuse EXIT +libtest_exit_cmds+=(cleanup_fuse) assert_file_has_content mnt/firstfile first echo "ok mount"