From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Cc: tomi.ollila@iki.fi
Subject: [PATCH 1/2] test-lib.sh: add "atexit" functionality
Date: Tue, 23 May 2017 21:54:24 +0300 [thread overview]
Message-ID: <20170523185425.31470-2-tomi.ollila@iki.fi> (raw)
In-Reply-To: <20170523185425.31470-1-tomi.ollila@iki.fi>
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.
---
test/test-lib.sh | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 988b00a..37f8ddf 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -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"
}
--
2.9.3
next prev parent reply other threads:[~2017-05-23 19:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-23 18:54 Tomi Ollila
2017-05-23 18:54 ` Tomi Ollila [this message]
2017-05-23 18:54 ` [PATCH 2/2] exit lingering gpg agents at the end of relevant tests Tomi Ollila
2017-05-23 21:19 ` Daniel Kahn Gillmor
2017-05-24 17:17 ` David Bremner
2017-05-25 12:05 ` David Bremner
2017-05-26 10:40 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170523185425.31470-2-tomi.ollila@iki.fi \
--to=tomi.ollila@iki.fi \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).