#!/usr/bin/env roundup describe libremakepkg . ./test-common.sh setup_chrootdir it_builds_a_trivial_package() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-hello "$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-hello-1.0-1-any.pkg.tar.?z) ]] } it_disables_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 not testsudo libremakepkg -l "$roundup_test_name" not [[ -f $(echo libretools-netprepare-1.0-1-any.pkg.tar.?z) ]] testsudo libremakepkg -l "$roundup_test_name" -N [[ -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 # 2. Then, we build testpkg2, which depends on testpkg1 # Therefore, testpkg1 will be installed after testpkg2 is built, we # check for that. # 3. Then, we build hello, which depends on neither, so testpkg1 should # be removed. # Also, do funny things with the output of libremakepkg to get a helpful # fail case. mkdir -p "$tmpdir"/{1,2,3} cp libremakepkg.d/PKGBUILD-testpkg1 "$tmpdir/1/PKGBUILD" cp libremakepkg.d/PKGBUILD-testpkg2 "$tmpdir/2/PKGBUILD" cp libremakepkg.d/PKGBUILD-hello "$tmpdir/3/PKGBUILD" libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty cd "$tmpdir/1" testsudo libremakepkg -l "$roundup_test_name" &> "$tmpdir/out" || { r=$?; tail "$tmpdir/out"|cat -v; return $r; } cd "$tmpdir/2" 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' # This next line is actually a separate test, but it fits in well with this test, and chroot tests are slow.. # it_doesnt_cache_local_packages() { not testsudo librechroot -l "$roundup_test_name" run test -e /var/cache/pacman/pkg/libretools-testpkg1-1.0-1-any.pkg.tar.?z cd "$tmpdir/3" 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() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty 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 [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } it_otherwise_fails_as_normal_user() { # I do this to give it a chance of passing cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" local stat=0 libremakepkg >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? [[ $stat != 0 ]] empty $tmpdir/stdout not empty $tmpdir/stderr } it_fails_if_a_hook_fails() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" local stat=0 sed -i 's/^BLACKLIST=.*/&-bogus/' "$XDG_CONFIG_HOME"/libretools/libretools.conf trap 'sed -i s/-bogus// "$XDG_CONFIG_HOME"/libretools/libretools.conf' RETURN libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo libremakepkg -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? [[ $stat != 0 ]] tail -n1 $tmpdir/stderr | grep -qF '==> ERROR: Failure(s) in check_pkgbuild: check_pkgbuild_nonfree' } it_detects_distcc_files() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" echo "CHROOTEXTRAPKG+=(distcc-nozeroconf socat)" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf trap 'sed -i /CHROOTEXTRAPKGs+=/d "$XDG_CONFIG_HOME"/libretools/chroot.conf' RETURN libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo librechroot -l "$roundup_test_name" run pacman -S --noconfirm distcc-nozeroconf socat # first make sure that the engine works testsudo libremakepkg -l "$roundup_test_name" [[ -f $(echo libretools-hello-1.0-1-any.pkg.tar.?z) ]] rm -f -- libretools-hello-1.0-1-any.pkg.tar.?z # now throw a wrench in it testsudo librechroot -l "$roundup_test_name" run touch /bin/distcc-tool # and make sure that the engine broke testsudo libremakepkg -l "$roundup_test_name" || stat=$? [[ $stat != 0 ]] not [[ -f $(echo libretools-hello-1.0-1-any.pkg.tar.?z) ]] } it_doesnt_symlink_outputs() { require network sudo || return 0 echo "WORKDIR='$tmpdir/workdir'" > $XDG_CONFIG_HOME/libretools/libretools.conf mkdir -p $XDG_CONFIG_HOME/pacman { printf 'PKGDEST=%q\n' "$tmpdir/workdir/pkgdest" printf 'SRCPKGDEST=%q\n' "$tmpdir/workdir/srcpkgdest" } >$XDG_CONFIG_HOME/pacman/makepkg.conf trap 'rm -f -- "$XDG_CONFIG_HOME/libretools/libretools.conf" "$XDG_CONFIG_HOME/pacman/makepkg.conf"' RETURN cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo libremakepkg -l "$roundup_test_name" not stat libretools-hello-1.0-1-any.pkg.tar.?z not stat libretools-hello-1.0-1-any.src.tar.?z [[ -f $(echo "$tmpdir/workdir/pkgdest"/libretools-hello-1.0-1-any.pkg.tar.?z) ]] [[ -f $(echo "$tmpdir/workdir/srcpkgdest"/libretools-hello-1.0-1-any.src.tar.?z) ]] } it_succeeds_with_good_signatures() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-signed "$tmpdir/PKGBUILD" cp libremakepkg.d/hello.sh "$tmpdir/hello.sh" cd "$tmpdir" gpg --detach-sign --use-agent --no-armor hello.sh libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo libremakepkg -l "$roundup_test_name" } it_fails_with_bad_signatures() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-signed "$tmpdir/PKGBUILD" cp libremakepkg.d/hello.sh "$tmpdir/hello.sh" cd "$tmpdir" gpg --detach-sign --use-agent --no-armor hello.sh echo 'echo pwned' >> hello.sh makepkg -g >> PKGBUILD libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty not testsudo libremakepkg -l "$roundup_test_name" } it_does_not_run_pkgver() { require network sudo || return 0 cp libremakepkg.d/PKGBUILD-pkgver "$tmpdir/PKGBUILD" pushd "$tmpdir" libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo libremakepkg -l "$roundup_test_name" [[ -f $(echo libretools-pkgver-1-1-any.pkg.tar.?z) ]] not [[ -f $(echo libretools-pkgver-2-1-any.pkg.tar.?z) ]] popd diff -u libremakepkg.d/PKGBUILD-pkgver "$tmpdir/PKGBUILD" }