diff options
Diffstat (limited to 'test/cases/libremakepkg.bats')
-rw-r--r-- | test/cases/libremakepkg.bats | 164 |
1 files changed, 74 insertions, 90 deletions
diff --git a/test/cases/libremakepkg.bats b/test/cases/libremakepkg.bats index 36176d3..8ac46cf 100644 --- a/test/cases/libremakepkg.bats +++ b/test/cases/libremakepkg.bats @@ -1,65 +1,58 @@ -#!/usr/bin/env roundup +load ../lib/common -describe libremakepkg -. ./test-common.sh - -before() { - common_before +setup() { + common_setup cat >> "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot unset PKGDEST SRCPKGDEST eot } -it_builds_a_trivial_package() { - require network sudo || return 0 - cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" +@test "libremakepkg builds a trivial package" { + require network sudo || skip + cp fixtures/libremakepkg/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo libremakepkg -l "$roundup_test_name" + testsudo libremakepkg -l "$BATS_TEST_NAME" globfile 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" +@test "libremakepkg disables networking during prepare" { + require network sudo || skip + cp fixtures/libremakepkg/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 testsudo libremakepkg -l "$BATS_TEST_NAME" not globfile libretools-netprepare-1.0-1-any.pkg.tar.?z - testsudo libremakepkg -l "$roundup_test_name" -N + testsudo libremakepkg -l "$BATS_TEST_NAME" -N globfile 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" +@test "libremakepkg disables networking during build" { + require network sudo || skip + cp fixtures/libremakepkg/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 testsudo libremakepkg -l "$BATS_TEST_NAME" not globfile libretools-netbuild-1.0-1-any.pkg.tar.?z - testsudo libremakepkg -l "$roundup_test_name" -N + testsudo libremakepkg -l "$BATS_TEST_NAME" -N globfile 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" +@test "libremakepkg disables networking during package" { + require network sudo || skip + cp fixtures/libremakepkg/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 testsudo libremakepkg -l "$BATS_TEST_NAME" not globfile libretools-netpackage-1.0-1-any.pkg.tar.?z - testsudo libremakepkg -l "$roundup_test_name" -N + testsudo libremakepkg -l "$BATS_TEST_NAME" -N globfile libretools-netpackage-1.0-1-any.pkg.tar.?z } -it_cleans_the_chroot_before_building() { - require network sudo || return 0 +@test "libremakepkg cleans the chroot before building" { + require network sudo || skip # 1. First, we build testpkg1 # 2. Then, we build testpkg2, which depends on testpkg1 # Therefore, testpkg1 will be installed after testpkg2 is built, we @@ -71,40 +64,38 @@ it_cleans_the_chroot_before_building() { # 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" + cp fixtures/libremakepkg/PKGBUILD-testpkg1 "$tmpdir/1/PKGBUILD" + cp fixtures/libremakepkg/PKGBUILD-testpkg2 "$tmpdir/2/PKGBUILD" + cp fixtures/libremakepkg/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" || { status=$?; tail "$tmpdir/out"|cat -v; return $status; } + testsudo libremakepkg -l "$BATS_TEST_NAME" &> "$tmpdir/out" || { status=$?; tail "$tmpdir/out"|cat -v; return $status; } cd "$tmpdir/2" - testsudo libremakepkg -l "$roundup_test_name" &> "$tmpdir/out" || { status=$?; tail "$tmpdir/out"|cat -v; return $status; } - testsudo librechroot -l "$roundup_test_name" run libretools-testpkg1 'first time, pass' + testsudo libremakepkg -l "$BATS_TEST_NAME" &> "$tmpdir/out" || { status=$?; tail "$tmpdir/out"|cat -v; return $status; } + testsudo librechroot -l "$BATS_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 + not testsudo librechroot -l "$BATS_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" || { status=$?; tail "$tmpdir/out"|cat -v; return $status; } - not testsudo librechroot -l "$roundup_test_name" run libretools-testpkg1 'second time, fail' + testsudo libremakepkg -l "$BATS_TEST_NAME" &> "$tmpdir/out" || { status=$?; tail "$tmpdir/out"|cat -v; return $status; } + not testsudo librechroot -l "$BATS_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" +@test "libremakepkg handles PKGDEST not existing" { + require network sudo || skip + cp fixtures/libremakepkg/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" + testsudo env PKGDEST="$tmpdir/dest/pkgdest" libremakepkg -l "$BATS_TEST_NAME" globfile dest/pkgdest/libretools-hello-1.0-1-any.pkg.tar.?z } -it_displays_help_as_normal_user() { +@test "libremakepkg displays help as normal user" { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C libremakepkg -h >$tmpdir/stdout 2>$tmpdir/stderr @@ -112,9 +103,9 @@ it_displays_help_as_normal_user() { empty $tmpdir/stderr } -it_otherwise_fails_as_normal_user() { +@test "libremakepkg otherwise fails as normal user" { # I do this to give it a chance of passing - cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" + cp fixtures/libremakepkg/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" libremakepkg >$tmpdir/stdout 2>$tmpdir/stderr || status=$? @@ -124,73 +115,69 @@ it_otherwise_fails_as_normal_user() { not empty $tmpdir/stderr } -it_fails_if_a_hook_fails() { - require network sudo || return 0 - cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" +@test "libremakepkg fails if a hook fails" { + require network sudo || skip + cp fixtures/libremakepkg/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot BLACKLIST='phony://example.com' eot - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo libremakepkg -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || status=$? + testsudo libremakepkg -l "$BATS_TEST_NAME" >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 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" +@test "libremakepkg detects distcc files" { + require network sudo || skip + cp fixtures/libremakepkg/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" cat >> "$XDG_CONFIG_HOME/libretools/chroot.conf" <<-eot CHROOTEXTRAPKG+=(distcc-nozeroconf socat) eot - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" install-name distcc-nozeroconf socat + testsudo librechroot -l "$BATS_TEST_NAME" install-name distcc-nozeroconf socat # first make sure that the engine works - testsudo libremakepkg -l "$roundup_test_name" + testsudo libremakepkg -l "$BATS_TEST_NAME" globfile 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 + testsudo librechroot -l "$BATS_TEST_NAME" run touch /bin/distcc-tool # and make sure that the engine broke - testsudo libremakepkg -l "$roundup_test_name" || status=$? + testsudo libremakepkg -l "$BATS_TEST_NAME" || status=$? [[ $status != 0 ]] not globfile libretools-hello-1.0-1-any.pkg.tar.?z } -it_allows_distcc_on_long_chrootpaths() { +@test "libremakepkg allows distcc on long chrootpaths" { # The maximum AF_UNIX socket path is 108 bytes; so let's have # a chroot name that's guaranteed to be >110 characters. - local chrootname=$roundup_test_name.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + local chrootname=$BATS_TEST_NAME.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - require network sudo || return 0 - cp libremakepkg.d/PKGBUILD-distcc "$tmpdir/PKGBUILD" + require network sudo || skip + cp fixtures/libremakepkg/PKGBUILD-distcc "$tmpdir/PKGBUILD" cd "$tmpdir" cat >> "$XDG_CONFIG_HOME/libretools/chroot.conf" <<-eot CHROOTEXTRAPKG+=(distcc-nozeroconf socat) eot - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo librechroot -l "$chrootname" install-name distcc-nozeroconf socat testsudo libremakepkg -l "$chrootname" globfile libretools-distcc-1.0-1-any.pkg.tar.?z } -it_doesnt_symlink_outputs() { - require network sudo || return 0 +@test "libremakepkg doesnt symlink outputs" { + require network sudo || skip sed -i /^unset/d "$XDG_CONFIG_HOME/pacman/makepkg.conf" - cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" + cp fixtures/libremakepkg/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo libremakepkg -l "$roundup_test_name" + testsudo libremakepkg -l "$BATS_TEST_NAME" not stat libretools-hello-1.0-1-any.pkg.tar.?z not stat libretools-hello-1.0-1-any.src.tar.?z @@ -198,43 +185,40 @@ it_doesnt_symlink_outputs() { globfile "$tmpdir/workdir/srcpkgdest"/libretools-hello-1.0-1-any.src.tar.?z } -it_succeeds_with_good_signatures() { - require network sudo || return 0 +@test "libremakepkg succeeds with good signatures" { + require network sudo || skip - cp libremakepkg.d/PKGBUILD-signed "$tmpdir/PKGBUILD" - cp libremakepkg.d/hello.sh "$tmpdir/hello.sh" + cp fixtures/libremakepkg/PKGBUILD-signed "$tmpdir/PKGBUILD" + cp fixtures/libremakepkg/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" + testsudo libremakepkg -l "$BATS_TEST_NAME" } -it_fails_with_bad_signatures() { - require network sudo || return 0 +@test "libremakepkg fails with bad signatures" { + require network sudo || skip - cp libremakepkg.d/PKGBUILD-signed "$tmpdir/PKGBUILD" - cp libremakepkg.d/hello.sh "$tmpdir/hello.sh" + cp fixtures/libremakepkg/PKGBUILD-signed "$tmpdir/PKGBUILD" + cp fixtures/libremakepkg/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" + not testsudo libremakepkg -l "$BATS_TEST_NAME" } -it_does_not_run_pkgver() { - require network sudo || return 0 +@test "libremakepkg does not run pkgver" { + require network sudo || skip - cp libremakepkg.d/PKGBUILD-pkgver "$tmpdir/PKGBUILD" + cp fixtures/libremakepkg/PKGBUILD-pkgver "$tmpdir/PKGBUILD" pushd "$tmpdir" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo libremakepkg -l "$roundup_test_name" + testsudo libremakepkg -l "$BATS_TEST_NAME" globfile libretools-pkgver-1-1-any.pkg.tar.?z not globfile libretools-pkgver-2-1-any.pkg.tar.?z popd - diff -u libremakepkg.d/PKGBUILD-pkgver "$tmpdir/PKGBUILD" + diff -u fixtures/libremakepkg/PKGBUILD-pkgver "$tmpdir/PKGBUILD" } |