summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/aur-test.sh2
-rw-r--r--test/is_built-test.sh2
-rw-r--r--test/lib-blacklist-test.sh10
-rw-r--r--test/lib-messages-test.sh4
-rw-r--r--test/librechroot-test.sh60
-rw-r--r--test/librefetch-test.sh5
-rw-r--r--test/librefetch.d/PKGBUILD5
-rw-r--r--test/librefetch.d/list.txt5
-rw-r--r--test/librelib-test.sh4
-rw-r--r--test/libremakepkg-test.sh54
-rw-r--r--test/libremakepkg.d/PKGBUILD-netbuild17
-rw-r--r--test/libremakepkg.d/PKGBUILD-netpackage12
-rw-r--r--test/libremakepkg.d/PKGBUILD-netprepare17
-rw-r--r--test/librerelease-test.sh12
-rw-r--r--test/librestage-test.sh4
-rw-r--r--test/pkgbuild-check-nonfree-test.sh10
-rw-r--r--test/test-common.sh30
17 files changed, 203 insertions, 50 deletions
diff --git a/test/aur-test.sh b/test/aur-test.sh
index 8bcb5ef..5de590b 100644
--- a/test/aur-test.sh
+++ b/test/aur-test.sh
@@ -24,7 +24,7 @@ it_fails_with_0_args() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
# TODO: Actually test
diff --git a/test/is_built-test.sh b/test/is_built-test.sh
index af754dc..f7f6c65 100644
--- a/test/is_built-test.sh
+++ b/test/is_built-test.sh
@@ -24,7 +24,7 @@ it_fails_with_0_args() {
[[ $stat -gt 1 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_succeeds_with_1_arg() {
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh
index 640ed77..9dfd5da 100644
--- a/test/lib-blacklist-test.sh
+++ b/test/lib-blacklist-test.sh
@@ -53,7 +53,7 @@ it_fails_update_with_no_blacklist_or_network() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_fails_cat_with_no_blacklist_or_network() {
@@ -64,7 +64,7 @@ it_fails_cat_with_no_blacklist_or_network() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_fails_update_when_BLACKLIST_is_unset() {
@@ -75,7 +75,7 @@ it_fails_update_when_BLACKLIST_is_unset() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_fails_cat_when_syntax_error_in_conf() {
@@ -87,7 +87,7 @@ it_fails_cat_when_syntax_error_in_conf() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_downloads_the_blacklist_as_needed() {
@@ -97,7 +97,7 @@ it_downloads_the_blacklist_as_needed() {
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr
- ! empty $tmpdir/stdout
+ not empty $tmpdir/stdout
}
it_downloads_the_blacklist_repeatedly() {
diff --git a/test/lib-messages-test.sh b/test/lib-messages-test.sh
index fffff36..3fcac63 100644
--- a/test/lib-messages-test.sh
+++ b/test/lib-messages-test.sh
@@ -31,14 +31,14 @@ it_works_with_no_color_and_set_euE() (
) >$tmpdir/stdout 2>$tmpdir/stderr
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
)
it_can_be_called_without_including() {
libremessages msg Foo >$tmpdir/stdout 2>$tmpdir/stderr
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_fails_with_msg_and_no_args() {
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh
index 5ca1b37..43f3143 100644
--- a/test/librechroot-test.sh
+++ b/test/librechroot-test.sh
@@ -4,30 +4,34 @@ describe librechroot
. ./test-common.sh
+_setup_chrootdir
+
before() {
_before librechroot
+
mkdir -p "$XDG_CONFIG_HOME"/libretools
- echo "CHROOTDIR='$tmpdir/chrootdir'" > "$XDG_CONFIG_HOME"/libretools/chroot.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
}
-after() {
+after() (
_after_sudo
-}
+)
it_creates_repo_for_new_chroots() {
require network sudo || return 0
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
- testsudo librechroot run test -r /repo/repo.db
+ testsudo librechroot -l "$roundup_test_name" run test -r /repo/repo.db
}
it_cleans_the_local_repo_correctly() {
require network sudo || return 0
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
- testsudo librechroot make
- testsudo librechroot clean-repo
- testsudo librechroot run test -r /repo/repo.db
+ testsudo librechroot -l "$roundup_test_name" make
+ testsudo librechroot -l "$roundup_test_name" clean-repo
+ testsudo librechroot -l "$roundup_test_name" run test -r /repo/repo.db
# TODO: inspect /repo/* more
}
@@ -36,10 +40,38 @@ it_respects_exit_status_if_out_isnt_a_tty() (
set -o pipefail
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
r=0
- { testsudo librechroot run exit 3 | cat; } || r=$?
+ { testsudo librechroot -l "$roundup_test_name" run bash -c 'exit 3' | cat; } || r=$?
[[ $r == 3 ]]
)
+it_creates_ca_certificates() {
+ require network sudo || return 0
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+ testsudo librechroot -l "$roundup_test_name" run test -r /etc/ssl/certs/ca-certificates.crt
+}
+
+it_disables_networking_when_requested() {
+ require network sudo || return 0
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+
+ testsudo librechroot -l "$roundup_test_name" run curl https://repo.parabolagnulinux.org/ >/dev/null
+ not testsudo librechroot -l "$roundup_test_name" -N run curl https://repo.parabolagnulinux.org/ >/dev/null
+}
+
+it_handles_CHROOTEXTRAPKG_correctly() {
+ requuire network sudo || return 0
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+
+ not testsudo librechroot -l "$roundup_test_name" run lsof
+ echo "CHROOTEXTRAPKG=(lsof)" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf
+ testsudo librechroot -l "$roundup_test_name" install-name lsof
+ testsudo librechroot -l "$roundup_test_name" clean-pkgs
+ testsudo librechroot -l "$roundup_test_name" run lsof
+ echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf
+ testsudo librechroot -l "$roundup_test_name" clean-pkgs
+ not testsudo librechroot -l "$roundup_test_name" run lsof
+}
+
it_displays_help_as_normal_user() {
rm -rf "$XDG_CONFIG_HOME"
LC_ALL=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr
@@ -49,19 +81,19 @@ it_displays_help_as_normal_user() {
}
it_otherwise_fails_as_normal_user() {
- librechroot run true >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ librechroot -l "$roundup_test_name" run true >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_displays_help_and_fails_with_0_args() {
- LC_ALL=C librechroot >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ LC_ALL=C librechroot -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
- [[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]]
+ [[ "$(sed -n 2p $tmpdir/stderr)" =~ Usage:.* ]]
}
# requires sudo so we know it's not failing because it needs root
@@ -71,7 +103,7 @@ it_fails_for_unknown_commands() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
# requires sudo so we know it's not failing because it needs root
@@ -81,5 +113,5 @@ it_fails_for_unknown_flags() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh
index 13ce80f..9db836b 100644
--- a/test/librefetch-test.sh
+++ b/test/librefetch-test.sh
@@ -9,13 +9,13 @@ before() {
mkdir -p "$HOME"
printf '%s\n' \
- "DLAGENTS+=(\"libre::$(which librefetch) -p \\\"\\\$BUILDFILE\\\" %u %o\")" \
+ "DLAGENTS=({https,libre}'::$(which librefetch) -p \"\$BUILDFILE\" -- %u %o')" \
'BUILDDIR=""' \
> "$HOME/.makepkg.conf"
mkdir -p "$XDG_CONFIG_HOME/libretools"
printf '%s\n' \
- 'MIRROR="phony://example.com/dir/"' \
+ 'MIRRORS=("phony://example.com/dir/")' \
'DOWNLOADER=/usr/bin/false' \
> "$XDG_CONFIG_HOME/libretools/librefetch.conf"
}
@@ -31,6 +31,7 @@ it_displays_help() {
empty $tmpdir/stderr
}
+# This test also does a rough test of file order in the PKGBUILD
it_cleans_src_libre_first() {
cp librefetch.d/* "$tmpdir/"
cd "$tmpdir"
diff --git a/test/librefetch.d/PKGBUILD b/test/librefetch.d/PKGBUILD
index 723d82e..db80db3 100644
--- a/test/librefetch.d/PKGBUILD
+++ b/test/librefetch.d/PKGBUILD
@@ -7,7 +7,10 @@ source=("libre://$pkgname-$pkgver.tar.gz")
mksource() {
mkdir "$srcdir/bar"
- touch "$srcdir/bar/file"
+ local file
+ for file in '~foo' '~a' a A; do
+ touch "$srcdir/bar/$file"
+ done
}
package() {
diff --git a/test/librefetch.d/list.txt b/test/librefetch.d/list.txt
index b04d5d1..9bd32f4 100644
--- a/test/librefetch.d/list.txt
+++ b/test/librefetch.d/list.txt
@@ -1,2 +1,5 @@
bar/
-bar/file
+bar/A
+bar/a
+bar/~a
+bar/~foo
diff --git a/test/librelib-test.sh b/test/librelib-test.sh
index 23c38dc..a74ce0a 100644
--- a/test/librelib-test.sh
+++ b/test/librelib-test.sh
@@ -26,7 +26,7 @@ it_fails_with_2_args() {
librelib a b >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
[[ $ret != 0 ]]
}
@@ -68,6 +68,6 @@ it_fails_to_find_phony() {
librelib phony >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
[[ $ret != 0 ]]
}
diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh
index e684f18..4d8a7c5 100644
--- a/test/libremakepkg-test.sh
+++ b/test/libremakepkg-test.sh
@@ -4,6 +4,8 @@ describe libremakepkg
. ./test-common.sh
+_setup_chrootdir
+
before() {
_before libremakepkg
@@ -11,7 +13,7 @@ before() {
echo "BLACKLIST=https://repo.parabolagnulinux.org/docs/blacklist.txt" >"$XDG_CONFIG_HOME"/libretools/libretools.conf
- echo "CHROOTDIR='$tmpdir/chrootdir'" > "$XDG_CONFIG_HOME"/libretools/chroot.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
}
@@ -26,11 +28,45 @@ it_builds_a_trivial_package() {
cd "$tmpdir"
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
- testsudo libremakepkg
+ testsudo libremakepkg -l "$roundup_test_name"
[[ -f $(echo libretools-hello-1.0-1-any.pkg.tar.?z) ]]
}
+it_enables_networking_during_prepare() {
+ require network sudo || return 0
+ cp libremakepkg.d/PKGBUILD-netprepare "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+ testsudo libremakepkg -l "$roundup_test_name"
+ [[ -f $(echo libretools-netprepare-1.0-1-any.pkg.tar.?z) ]]
+}
+
+it_disables_networking_during_build() {
+ require network sudo || return 0
+ cp libremakepkg.d/PKGBUILD-netbuild "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+ not testsudo libremakepkg -l "$roundup_test_name"
+ not [[ -f $(echo libretools-netbuild-1.0-1-any.pkg.tar.?z) ]]
+ testsudo libremakepkg -l "$roundup_test_name" -N
+ [[ -f $(echo libretools-netbuild-1.0-1-any.pkg.tar.?z) ]]
+}
+
+it_disables_networking_during_package() {
+ require network sudo || return 0
+ cp libremakepkg.d/PKGBUILD-netpackage "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+ not testsudo libremakepkg -l "$roundup_test_name"
+ not [[ -f $(echo libretools-netpackage-1.0-1-any.pkg.tar.?z) ]]
+ testsudo libremakepkg -l "$roundup_test_name" -N
+ [[ -f $(echo libretools-netpackage-1.0-1-any.pkg.tar.?z) ]]
+}
+
it_cleans_the_chroot_before_building() {
require network sudo || return 0
# 1. First, we build testpkg1
@@ -50,13 +86,13 @@ it_cleans_the_chroot_before_building() {
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
cd "$tmpdir/1"
- testsudo libremakepkg &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; }
+ testsudo libremakepkg -l "$roundup_test_name" &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; }
cd "$tmpdir/2"
- testsudo libremakepkg &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; }
- testsudo librechroot run libretools-testpkg1 'first time, pass'
+ testsudo libremakepkg -l "$roundup_test_name" &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; }
+ testsudo librechroot -l "$roundup_test_name" run libretools-testpkg1 'first time, pass'
cd "$tmpdir/3"
- testsudo libremakepkg &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; }
- ! testsudo librechroot run libretools-testpkg1 'second time, fail'
+ testsudo libremakepkg -l "$roundup_test_name" &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; }
+ not testsudo librechroot -l "$roundup_test_name" run libretools-testpkg1 'second time, fail'
}
it_handles_PKGDEST_not_existing() {
@@ -65,7 +101,7 @@ it_handles_PKGDEST_not_existing() {
cd "$tmpdir"
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
- testsudo env PKGDEST="$tmpdir/dest/pkgdest" libremakepkg
+ testsudo env PKGDEST="$tmpdir/dest/pkgdest" libremakepkg -l "$roundup_test_name"
[[ -f $(echo dest/pkgdest/libretools-hello-1.0-1-any.pkg.tar.?z) ]]
}
@@ -87,5 +123,5 @@ it_otherwise_fails_as_normal_user() {
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
diff --git a/test/libremakepkg.d/PKGBUILD-netbuild b/test/libremakepkg.d/PKGBUILD-netbuild
new file mode 100644
index 0000000..7be896b
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-netbuild
@@ -0,0 +1,17 @@
+pkgname='libretools-netbuild'
+pkgver=1.0
+license=('GPL')
+url='https://parabolagnulinux.org'
+
+pkgrel=1
+arch=(any)
+
+build() {
+ cd "$srcdir"
+ curl https://repo.parabolagnulinux.org/ > index.html
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm644 index.html "$pkgdir"/usr/share/$pkgname/index.html
+}
diff --git a/test/libremakepkg.d/PKGBUILD-netpackage b/test/libremakepkg.d/PKGBUILD-netpackage
new file mode 100644
index 0000000..cbefe8f
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-netpackage
@@ -0,0 +1,12 @@
+pkgname='libretools-netpackage'
+pkgver=1.0
+license=('GPL')
+url='https://parabolagnulinux.org'
+
+pkgrel=1
+arch=(any)
+
+package() {
+ install -d "$pkgdir"/usr/share/$pkgname
+ curl https://repo.parabolagnulinux.org/ > "$pkgdir"/usr/share/$pkgname/index.html
+}
diff --git a/test/libremakepkg.d/PKGBUILD-netprepare b/test/libremakepkg.d/PKGBUILD-netprepare
new file mode 100644
index 0000000..90f3e82
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-netprepare
@@ -0,0 +1,17 @@
+pkgname='libretools-netprepare'
+pkgver=1.0
+license=('GPL')
+url='https://parabolagnulinux.org'
+
+pkgrel=1
+arch=(any)
+
+prepare() {
+ cd "$srcdir"
+ curl https://repo.parabolagnulinux.org/ > index.html
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm644 index.html "$pkgdir"/usr/share/$pkgname/index.html
+}
diff --git a/test/librerelease-test.sh b/test/librerelease-test.sh
index c395bc6..a44b150 100644
--- a/test/librerelease-test.sh
+++ b/test/librerelease-test.sh
@@ -34,20 +34,22 @@ it_displays_usage_text() {
it_lists_all_files() {
WORKDIR="$tmpdir/workdir"
- mkdir -p "$WORKDIR/staging/repo1" "$WORKDIR/staging/repo2"
+ mkdir -p "$WORKDIR/staging/repo1" "$WORKDIR/staging/repo2/sub"
touch \
"$WORKDIR/staging/repo1/file1" \
"$WORKDIR/staging/repo1/file2" \
- "$WORKDIR/staging/repo2/file with spaces"
+ "$WORKDIR/staging/repo2/file with spaces" \
+ "$WORKDIR/staging/repo2/sub/subfolder"
unset WORKDIR
LC_ALL=C librerelease -l &>"$tmpdir/list"
cat > "$tmpdir/list-correct" <<EOF
-> repo1
-file1
-file2
+ file1
+ file2
-> repo2
-file with spaces
+ file with spaces
+ sub/subfolder
EOF
diff "$tmpdir/list-correct" "$tmpdir/list"
diff --git a/test/librestage-test.sh b/test/librestage-test.sh
index 6728143..460eb58 100644
--- a/test/librestage-test.sh
+++ b/test/librestage-test.sh
@@ -34,7 +34,7 @@ it_fails_with_0_args() {
[[ $stat != 0 ]]
empty "$tmpdir/stdout"
- ! empty "$tmpdir/stderr"
+ not empty "$tmpdir/stderr"
}
it_fails_with_invalid_args() {
@@ -42,7 +42,7 @@ it_fails_with_invalid_args() {
[[ $stat != 0 ]]
empty "$tmpdir/stdout"
- ! empty "$tmpdir/stderr"
+ not empty "$tmpdir/stderr"
}
# This was an actual bug I hit with md/emacs-mdmua a long time ago; solution was
diff --git a/test/pkgbuild-check-nonfree-test.sh b/test/pkgbuild-check-nonfree-test.sh
index 6463d64..2af2669 100644
--- a/test/pkgbuild-check-nonfree-test.sh
+++ b/test/pkgbuild-check-nonfree-test.sh
@@ -39,7 +39,7 @@ it_succeeds_for_free_depends() {
$pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
[[ $stat == 0 ]]
}
@@ -47,7 +47,7 @@ it_succeeds_for_nonfree_depend_with_replacement() {
$pcn $pcn.d/PKGBUILD.nonfree-replacement >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
[[ $stat == 0 ]]
}
@@ -55,14 +55,14 @@ it_fails_for_nonfree_depend() {
$pcn $pcn.d/PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
local pcn_stat=$stat
$psn $pcn_stat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
}
it_fails_when_there_is_no_blacklist() {
@@ -73,6 +73,6 @@ it_fails_when_there_is_no_blacklist() {
$pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
empty $tmpdir/stdout
- ! empty $tmpdir/stderr
+ not empty $tmpdir/stderr
[[ $stat != 0 ]] && [[ $stat != 15 ]]
}
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 "$@"
+)