diff options
Diffstat (limited to 'test/test-common.sh')
-rw-r--r-- | test/test-common.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/test-common.sh b/test/test-common.sh index aadd8f2..c525dd8 100644 --- a/test/test-common.sh +++ b/test/test-common.sh @@ -11,6 +11,7 @@ _before() { unset PKGEXT SRCEXT unset GPGKEY PACKAGER tmpdir="$(mktemp -d --tmpdir "test-${roundup_desc//\//-}.XXXXXXXXXXXX")" + chmod 755 "$tmpdir" stat=0 } @@ -26,6 +27,29 @@ _after_sudo() { fi } +_setup_chrootdir() { + if [[ -z "$chrootdir" ]]; then + export chrootdir="$(mktemp -d --tmpdir "test-chrootdir.XXXXXXXXXXXX")" + trap "$(printf '_cleanup_chrootdir %q' "$chrootdir")" EXIT + fi +} + +_cleanup_chrootdir() ( + chrootdir=$1 + shopt -s nullglob + if [[ $SUDO ]]; then + for copydir in "$chrootdir"/*/*/; do + local chroottype=$(stat -f -c %T "$copydir") + if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then + sudo btrfs subvolume delete "$copydir" >/dev/null + fi + done + sudo rm -rf -- "$chrootdir" + else + rm -rf -- "$chrootdir" + fi +) + require() ( set +x local missing=() @@ -46,3 +70,9 @@ empty() ( set +x [[ $(stat -c %s "$1") -eq 0 ]] ) + +# Just using '!' doesn't trip `set -e` +not() ( + set +x + ! eval "$@" +) |