mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
test-lib.sh: add "atexit" functionality
New function at_exit_function registers given function to be called at script termination. Functions so registered are called in the reverse order of their registration; no arguments are passed. Function is called only once; re-adding with function name already registered will remove previous registration. New function rm_exit_function can be used to remove registration. Modules (and possibly test-lib.sh functions) in future commits will register such functions.
This commit is contained in:
parent
523d2b50fc
commit
eb157f8841
1 changed files with 11 additions and 0 deletions
|
@ -219,10 +219,21 @@ test_fixed=0
|
|||
test_broken=0
|
||||
test_success=0
|
||||
|
||||
declare -a _exit_functions=()
|
||||
|
||||
at_exit_function () {
|
||||
_exit_functions=($1 ${_exit_functions[@]/$1})
|
||||
}
|
||||
|
||||
rm_exit_function () {
|
||||
_exit_functions=(${_exit_functions[@]/$1})
|
||||
}
|
||||
|
||||
_exit_common () {
|
||||
code=$?
|
||||
trap - EXIT
|
||||
set +ex
|
||||
for _fn in ${_exit_functions[@]}; do $_fn; done
|
||||
rm -rf "$TEST_TMPDIR"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue