summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/librechroot-test.sh24
-rw-r--r--test/libremakepkg-test.sh22
-rw-r--r--test/test-common.sh23
3 files changed, 49 insertions, 20 deletions
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh
index 5ca1b37..442abed 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,7 +40,7 @@ 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 exit 3 | cat; } || r=$?
[[ $r == 3 ]]
)
@@ -49,7 +53,7 @@ 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
@@ -57,7 +61,7 @@ it_otherwise_fails_as_normal_user() {
}
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
diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh
index e684f18..9f3bed3 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,7 +28,7 @@ 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) ]]
}
@@ -50,13 +52,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; }
+ ! testsudo librechroot -l "$roundup_test_name" run libretools-testpkg1 'second time, fail'
}
it_handles_PKGDEST_not_existing() {
@@ -65,14 +67,14 @@ 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) ]]
}
it_displays_help_as_normal_user() {
rm -rf "$XDG_CONFIG_HOME"
- LC_ALL=C libremakepkg -h >$tmpdir/stdout 2>$tmpdir/stderr
+ LC_ALL=C libremakepkg -l "$roundup_test_name" -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
empty $tmpdir/stderr
@@ -83,7 +85,7 @@ it_otherwise_fails_as_normal_user() {
cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD"
cd "$tmpdir"
- libremakepkg >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ libremakepkg -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
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=()