summaryrefslogtreecommitdiff
path: root/test/test-common.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-common.sh')
-rw-r--r--test/test-common.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/test-common.sh b/test/test-common.sh
index aadd8f2..46e584d 100644
--- a/test/test-common.sh
+++ b/test/test-common.sh
@@ -26,6 +26,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=()