From 9d90d48c9d01fa45d1a363fc01d0a1c2ffc9e790 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 10 Apr 2017 22:31:02 -0400 Subject: test/: Tidy before()/after() definitions. --- test/test-common.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'test/test-common.sh') diff --git a/test/test-common.sh b/test/test-common.sh index c1d050a..f81738a 100644 --- a/test/test-common.sh +++ b/test/test-common.sh @@ -5,7 +5,15 @@ if [[ $HOME == "$(eval echo ~$USER)" ]]; then exit 1 fi -_before() { +common_before() { + : +} + +common_after() { + : +} + +before() { unset PKGDEST SRCDEST SRCPKGDEST LOGDEST unset BUILDDIR unset PKGEXT SRCEXT @@ -13,25 +21,32 @@ _before() { tmpdir="$(mktemp -d --tmpdir "test-${roundup_desc//\//-}.XXXXXXXXXXXX")" chmod 755 "$tmpdir" stat=0 + common_before } -_after() { - rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" -} - -_after_sudo() { - if [[ $SUDO ]]; then +after() { + common_after + if [[ -f "$tmpdir/.used-sudo" ]]; then sudo rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" else rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" fi } -_setup_chrootdir() { +setup_chrootdir() { if [[ -z "$chrootdir" ]]; then export chrootdir="$(mktemp -d --tmpdir "test-chrootdir.XXXXXXXXXXXX")" trap "$(printf '_cleanup_chrootdir %q' "$chrootdir")" EXIT fi + common_before() { + mkdir -p "$XDG_CONFIG_HOME"/libretools + + echo "BLACKLIST=https://git.parabola.nu/blacklist.git/plain/blacklist.txt" >"$XDG_CONFIG_HOME"/libretools/libretools.conf + + echo "CHROOTDIR='${chrootdir}'" > "$XDG_CONFIG_HOME"/libretools/chroot.conf + echo "CHROOT='default'" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf + echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf + } } _cleanup_chrootdir() ( @@ -67,7 +82,10 @@ require() ( libremessages warning "Next test requires %s; Skipping (passing)..." "$(echo "${missing[*]}"|sed 's/ /, /g')" &>/dev/tty return 1 fi - return 0; + if libremessages in_array "sudo" "$@"; then + touch "$tmpdir/.used-sudo" + fi + return 0 ) empty() ( -- cgit v1.2.3-54-g00ecf