summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-09-29 18:41:26 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-09-30 15:37:15 -0400
commit88d808002dcbcff20847f6c744345058723e08d2 (patch)
tree0b0b7e195d1bd792bb1ed3e77ae850ffe55d7c38
parent36c7b060591d5980ceaaa2c58197f0d390ecc8f5 (diff)
test: Have $chrootdir be owned by testenv instead of test-common.sh
-rwxr-xr-xtest/test-common.sh19
-rwxr-xr-xtest/testenv14
2 files changed, 14 insertions, 19 deletions
diff --git a/test/test-common.sh b/test/test-common.sh
index 45adb8b..bd66fc7 100755
--- a/test/test-common.sh
+++ b/test/test-common.sh
@@ -43,10 +43,7 @@ after() {
}
setup_chrootdir() {
- if [[ -z "$chrootdir" ]]; then
- export chrootdir="$(mktemp -d --tmpdir "test-chrootdir.XXXXXXXXXXXX")"
- trap "$(printf '_cleanup_chrootdir %q' "$chrootdir")" EXIT
- fi
+ export chrootdir="${chrootdir:-$TMPDIR/chroots}"
_common_before() {
mkdir -p "$XDG_CONFIG_HOME"/libretools
@@ -58,20 +55,6 @@ setup_chrootdir() {
}
}
-_cleanup_chrootdir() (
- chrootdir=$1
- shopt -s nullglob
- if [[ $SUDO ]]; then
- if [[ "$(stat -f -c %T "$chrootdir")" == btrfs ]]; then
- sudo find "$chrootdir" -depth -inum 256 -exec \
- btrfs subvolume delete {} \; &>/dev/null
- fi
- sudo rm -rf -- "$chrootdir"
- else
- rm -rf -- "$chrootdir"
- fi
-)
-
require() (
set +x
local missing=()
diff --git a/test/testenv b/test/testenv
index 4fc2860..a61fd24 100755
--- a/test/testenv
+++ b/test/testenv
@@ -24,7 +24,19 @@
# Set up the working directory, and add the hook to clean it up
export TMPDIR="$(mktemp --tmpdir -d libretools-test.XXXXXXXXXX)"
- trap "rm -rf '$TMPDIR'" EXIT
+ cleanup() {
+ set +e
+ # coordinate this with ./lib/common.bash
+ if [[ $SUDO ]] && [[ -d "$TMPDIR/chroots" ]]; then
+ if [[ "$(stat -f -c %T "$TMPDIR/chroots")" == btrfs ]]; then
+ sudo find "$TMPDIR/chroots" -depth -inum 256 -exec \
+ btrfs subvolume delete {} \; &>/dev/null
+ fi
+ sudo rm -rf -- "$TMPDIR/chroots"
+ fi
+ rm -rf -- "$TMPDIR"
+ }
+ trap cleanup EXIT
# Set up the install to work with
destdir=$TMPDIR/destdir