From 00406ddaa210e0e9a6e31e0e6841b51edabc80fb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 1 Oct 2018 20:22:32 -0400 Subject: =?UTF-8?q?(BATS)=20test/cases:=20Automated=20Roundup=E2=86=92BATS?= =?UTF-8?q?=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for file in test/cases/*.bats; do name=$(sed -n 's/^describe //p' -- "$file") sed -ri ' # Remove the roundup shebang /^#!\/usr\/bin\/env roundup$/d # Use $BATS_TEST_NAME instead of $roundup_test_name s,roundup_test_name,BATS_TEST_NAME,g # Use BATS built-in "skip" instead of just succeeding /^\trequire /s/\|\| return 0$/|| skip/ # Remove the chroot message, does not play well with BATS output /Creating a chroot, may take a few minutes/d # Update file locations s,^\. \./test-common\.sh$,load ../lib/common, s,\b(libre(chroot|dbdiff|fetch|makepkg|stage|xgettext)|pkgbuild-check-nonfree|toru)\.d\b,fixtures/\1,g # In BATS, the hook is setup(), not before() s,^before\(\),setup(), s,^\tcommon_before$,\tcommon_setup, # Convert test definitions from # describe FOO # it_does_a_thing() { … } # to # @test "FOO does a thing" { … } /^describe /d /^it_/ { s/_/ /g s,^it (.*)\(\),@test "'"$name"' \1\", } ' \ -- "$file" # Remove leading newline that might have been left behind by the above sed -i '1{/^$/d}' -- "$file" git add "$file" done sed -i \ -e 's,librexgettext\.d,fixtures/librexgettext,g' \ -e 's,/it_,/test_librexgettext_,g' \ -- test/fixtures/librexgettext/* git add test/fixtures/librexgettext/* --- test/cases/aur.bats | 9 +- test/cases/gitget.bats | 11 +- test/cases/is_built.bats | 17 +- test/cases/lib-blacklist.bats | 37 ++--- test/cases/lib-conf.bats | 17 +- test/cases/lib-messages.bats | 19 +-- test/cases/librechroot.bats | 179 ++++++++++----------- test/cases/libredbdiff.bats | 23 ++- test/cases/librefetch.bats | 31 ++-- test/cases/librelib.bats | 17 +- test/cases/libremakepkg.bats | 164 +++++++++---------- test/cases/librerelease.bats | 11 +- test/cases/librestage.bats | 25 ++- test/cases/librexgettext.bats | 39 +++-- test/cases/pkgbuild-check-nonfree.bats | 27 ++-- test/cases/toru-path.bats | 31 ++-- test/fixtures/librexgettext/combine.pot | 8 +- ...test_librexgettext_handles_librefetch_flags.pot | 20 +-- ...ibrexgettext_handles_multiple_skipped_flags.pot | 40 ++--- 19 files changed, 325 insertions(+), 400 deletions(-) diff --git a/test/cases/aur.bats b/test/cases/aur.bats index fbb3266..d77cb40 100644 --- a/test/cases/aur.bats +++ b/test/cases/aur.bats @@ -1,16 +1,13 @@ -#!/usr/bin/env roundup +load ../lib/common -describe aur -. ./test-common.sh - -it_displays_help() { +@test "aur displays help" { LC_ALL=C aur -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_fails_with_0_args() { +@test "aur fails with 0 args" { aur >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] diff --git a/test/cases/gitget.bats b/test/cases/gitget.bats index 1630fdb..034075e 100644 --- a/test/cases/gitget.bats +++ b/test/cases/gitget.bats @@ -1,16 +1,13 @@ -#!/usr/bin/env roundup +load ../lib/common -describe gitget -. ./test-common.sh - -it_displays_help() { +@test "gitget displays help" { LC_ALL=C gitget -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_fails_with_0_args() { +@test "gitget fails with 0 args" { gitget >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -18,7 +15,7 @@ it_fails_with_0_args() { not empty $tmpdir/stderr } -it_forces_url_for_bare() { +@test "gitget forces url for bare" { mkdir "$tmpdir/src" cd "$tmpdir/src" git init . diff --git a/test/cases/is_built.bats b/test/cases/is_built.bats index 66f92bf..44faf90 100644 --- a/test/cases/is_built.bats +++ b/test/cases/is_built.bats @@ -1,16 +1,13 @@ -#!/usr/bin/env roundup +load ../lib/common -describe is_built -. ./test-common.sh - -it_displays_help() { +@test "is_built displays help" { LC_ALL=C is_built -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_fails_with_0_args() { +@test "is_built fails with 0 args" { is_built >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status -gt 1 ]] @@ -18,14 +15,14 @@ it_fails_with_0_args() { not empty $tmpdir/stderr } -it_succeeds_with_1_arg() { +@test "is_built succeeds with 1 arg" { is_built sh >$tmpdir/stdout 2>$tmpdir/stderr empty $tmpdir/stdout empty $tmpdir/stderr } -it_returns_1_for_non_existent_package() { +@test "is_built returns 1 for non existent package" { is_built phony-ne-package 100 >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status == 1 ]] @@ -33,7 +30,7 @@ it_returns_1_for_non_existent_package() { empty $tmpdir/stderr } -it_returns_1_for_future_packages() { +@test "is_built returns 1 for future packages" { # If emacs ever goes rapid release, we might need to change this :P is_built emacs 100 >$tmpdir/stdout 2>$tmpdir/stderr || status=$? @@ -42,7 +39,7 @@ it_returns_1_for_future_packages() { empty $tmpdir/stderr } -it_returns_0_for_past_packages() { +@test "is_built returns 0 for past packages" { # If emacs ever goes rapid release, we might need to change this :P is_built emacs 1 >$tmpdir/stdout 2>$tmpdir/stderr diff --git a/test/cases/lib-blacklist.bats b/test/cases/lib-blacklist.bats index 32d700d..2388b15 100644 --- a/test/cases/lib-blacklist.bats +++ b/test/cases/lib-blacklist.bats @@ -1,9 +1,6 @@ -#!/usr/bin/env roundup +load ../lib/common -describe libreblacklist -. ./test-common.sh - -it_works_with_just_pkgname() { +@test "libreblacklist works with just pkgname" { v="$(libreblacklist normalize <<> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot BLACKLIST='phony://example.com' eot @@ -60,7 +57,7 @@ it_fails_update_with_no_blacklist_or_network() { not empty $tmpdir/stderr } -it_fails_cat_with_no_blacklist_or_network() { +@test "libreblacklist fails cat with no blacklist or network" { cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot BLACKLIST='phony://example.com' eot @@ -72,7 +69,7 @@ it_fails_cat_with_no_blacklist_or_network() { not empty $tmpdir/stderr } -it_fails_update_when_BLACKLIST_is_unset() { +@test "libreblacklist fails update when BLACKLIST is unset" { cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot BLACKLIST= eot @@ -84,7 +81,7 @@ it_fails_update_when_BLACKLIST_is_unset() { not empty $tmpdir/stderr } -it_fails_cat_when_syntax_error_in_conf() { +@test "libreblacklist fails cat when syntax error in conf" { # there is a stray single quote in there cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot BLACKLIST='https://git.parabola.nu/blacklist.git/plain/blacklist.txt @@ -97,22 +94,22 @@ it_fails_cat_when_syntax_error_in_conf() { not empty $tmpdir/stderr } -it_downloads_the_blacklist_as_needed() { - require network || return 0 +@test "libreblacklist downloads the blacklist as needed" { + require network || skip libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr not empty $tmpdir/stdout } -it_downloads_the_blacklist_repeatedly() { - require network || return 0 +@test "libreblacklist downloads the blacklist repeatedly" { + require network || skip libreblacklist update libreblacklist update } -it_displays_help_and_fails_with_no_args() { +@test "libreblacklist displays help and fails with no args" { LC_ALL=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -120,14 +117,14 @@ it_displays_help_and_fails_with_no_args() { [[ "$(sed 1q $tmpdir/stderr)" =~ 'Usage: libreblacklist ' ]] } -it_displays_help_when_given_h() { +@test "libreblacklist displays help when given h" { LC_ALL=C libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist ' ]] empty $tmpdir/stderr } -it_displays_help_when_given_h_cat() { +@test "libreblacklist displays help when given h cat" { LC_ALL=C libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" == 'Usage: libreblacklist cat' ]] diff --git a/test/cases/lib-conf.bats b/test/cases/lib-conf.bats index cf0b805..0925640 100644 --- a/test/cases/lib-conf.bats +++ b/test/cases/lib-conf.bats @@ -1,9 +1,6 @@ -#!/usr/bin/env roundup +load ../lib/common -describe lib/conf.sh -. ./test-common.sh - -it_sets_makepkg_vars_in_custom_file() { +@test "lib/conf.sh sets makepkg vars in custom file" { unset PKGDEST touch "$tmpdir/makepkg.conf" bash -c "$(printf '. $(librelib conf.sh); MAKEPKG_CONF=%q set_var makepkg PKGDEST /pkgdest' "$tmpdir/makepkg.conf")" @@ -11,8 +8,8 @@ it_sets_makepkg_vars_in_custom_file() { [[ $PKGDEST == /pkgdest ]] } -it_figures_out_HOME_when_root() { - require sudo || return 0 +@test "lib/conf.sh figures out HOME when root" { + require sudo || skip # This one is tricky, because it does the job too well, it will find # the actual HOME, instead of the test environment HOME. Therefore, we # will just check that [[ $HOME != /root ]] @@ -22,8 +19,8 @@ it_figures_out_HOME_when_root() { [[ $LIBREHOME != /root ]] } -it_nests_LIBREUSER() { - require sudo || return 0 +@test "lib/conf.sh nests LIBREUSER" { + require sudo || skip [[ $USER != root ]] cd "$tmpdir" echo '. $(librelib conf.sh); echo "$LIBREUSER"' > test.sh @@ -35,7 +32,7 @@ it_nests_LIBREUSER() { [[ $LIBREUSER == "$USER" ]] } -it_respects_custom_HOME() { +@test "lib/conf.sh respects custom HOME" { cd "$tmpdir" echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh diff --git a/test/cases/lib-messages.bats b/test/cases/lib-messages.bats index d0b4497..c992a33 100644 --- a/test/cases/lib-messages.bats +++ b/test/cases/lib-messages.bats @@ -1,19 +1,16 @@ -#!/usr/bin/env roundup +load ../lib/common -describe libremessages -. ./test-common.sh - -it_can_be_included_twice() ( +@test "libremessages can be included twice" ( . libremessages . libremessages ) -it_can_be_included_with_set_euE() ( +@test "libremessages can be included with set euE" ( set -euE . libremessages ) -it_works_with_no_color_and_set_euE() { +@test "libremessages works with no color and set euE" { ( unset TERM set -euE @@ -25,19 +22,19 @@ it_works_with_no_color_and_set_euE() { not empty $tmpdir/stderr } -it_can_be_called_without_including() { +@test "libremessages can be called without including" { libremessages msg Foo >$tmpdir/stdout 2>$tmpdir/stderr empty $tmpdir/stdout not empty $tmpdir/stderr } -it_fails_with_msg_and_no_args() { +@test "libremessages fails with msg and no args" { libremessages msg || status=$? [[ $status != 0 ]] } -it_allows_subheadings_to_flag() { +@test "libremessages allows subheadings to flag" { # Note that old versions of `flag` panicked if given an odd # number of headings, so give an odd number here. libremessages flag \ @@ -54,7 +51,7 @@ it_allows_subheadings_to_flag() { diff -u $tmpdir/exp $tmpdir/out } -it_is_quiet_on_stdout_on_errs() { +@test "libremessages is quiet on stdout on errs" { LC_ALL=C bash -euE -c '. libremessages; setup_traps; false' >"$tmpdir/stdout" 2>"$tmpdir/stderr" || status=$? [[ $status != 0 ]] diff --git a/test/cases/librechroot.bats b/test/cases/librechroot.bats index e476f6f..7e8504d 100644 --- a/test/cases/librechroot.bats +++ b/test/cases/librechroot.bats @@ -1,96 +1,85 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librechroot -. ./test-common.sh - -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 -l "$roundup_test_name" run test -r /repo/repo.db +@test "librechroot creates repo for new chroots" { + require network sudo || skip + testsudo librechroot -l "$BATS_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 -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 +@test "librechroot cleans the local repo correctly" { + require network sudo || skip + testsudo librechroot -l "$BATS_TEST_NAME" make + testsudo librechroot -l "$BATS_TEST_NAME" clean-repo + testsudo librechroot -l "$BATS_TEST_NAME" run test -r /repo/repo.db # TODO: inspect /repo/* more } -it_respects_exit_status_if_out_isnt_a_tty() ( - require network sudo || return 0 +@test "librechroot respects exit status if out isnt a tty" ( + require network sudo || skip set -o pipefail - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - { testsudo librechroot -l "$roundup_test_name" run bash -c 'exit 3' | cat; } || status=$? + { testsudo librechroot -l "$BATS_TEST_NAME" run bash -c 'exit 3' | cat; } || status=$? [[ $status == 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 +@test "librechroot creates ca certificates" { + require network sudo || skip + testsudo librechroot -l "$BATS_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 +@test "librechroot disables networking when requested" { + require network sudo || skip - testsudo librechroot -l "$roundup_test_name" run curl https://repo.parabola.nu/ >/dev/null - not testsudo librechroot -l "$roundup_test_name" -N run curl https://repo.parabola.nu/ >/dev/null + testsudo librechroot -l "$BATS_TEST_NAME" run curl https://repo.parabola.nu/ >/dev/null + not testsudo librechroot -l "$BATS_TEST_NAME" -N run curl https://repo.parabola.nu/ >/dev/null } -it_handles_CHROOTEXTRAPKG_correctly() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot handles CHROOTEXTRAPKG correctly" { + require network sudo || skip - not testsudo librechroot -l "$roundup_test_name" run lsof + not testsudo librechroot -l "$BATS_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 + testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + testsudo librechroot -l "$BATS_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 + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof } -it_obeys_depends_in_PKGBUILD() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot obeys depends in PKGBUILD" { + require network sudo || skip # Make sure it's not in the base install - not testsudo librechroot -l "$roundup_test_name" run lsof + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof # Make sure it removes it without the PKGBUILD - testsudo librechroot -l "$roundup_test_name" install-name lsof - testsudo librechroot -l "$roundup_test_name" run lsof - testsudo librechroot -l "$roundup_test_name" clean-pkgs - not testsudo librechroot -l "$roundup_test_name" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof + testsudo librechroot -l "$BATS_TEST_NAME" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof # Make sure it leaves it with the PKGBUILD - testsudo librechroot -l "$roundup_test_name" install-name lsof - testsudo librechroot -l "$roundup_test_name" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat librechroot.d/PKGBUILD-arches)" + testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat fixtures/librechroot/PKGBUILD-arches)" # uid=99 is 'nobody', but we say '99' because sometimes 'nobody' is uid=65534. # https://bugs.archlinux.org/task/56828 - testsudo librechroot -l "$roundup_test_name" run chown -R 99:99 /startdir - testsudo librechroot -l "$roundup_test_name" clean-pkgs - testsudo librechroot -l "$roundup_test_name" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" run chown -R 99:99 /startdir + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + testsudo librechroot -l "$BATS_TEST_NAME" run lsof } -it_can_install_libretools_with_chcleanup() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot can install libretools with chcleanup" { + require network sudo || skip - not testsudo librechroot -l "$roundup_test_name" run test -f /usr/bin/chcleanup - testsudo librechroot -l "$roundup_test_name" run mkdir /startdir - testsudo librechroot -l "$roundup_test_name" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat librechroot.d/PKGBUILD-libretools)" + not testsudo librechroot -l "$BATS_TEST_NAME" run test -f /usr/bin/chcleanup + testsudo librechroot -l "$BATS_TEST_NAME" run mkdir /startdir + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat fixtures/librechroot/PKGBUILD-libretools)" # uid=99 is 'nobody', but we say '99' because sometimes 'nobody' is uid=65534. # https://bugs.archlinux.org/task/56828 - testsudo librechroot -l "$roundup_test_name" run chown -R 99:99 /startdir - testsudo librechroot -l "$roundup_test_name" clean-pkgs - testsudo librechroot -l "$roundup_test_name" run test -f /usr/bin/chcleanup + testsudo librechroot -l "$BATS_TEST_NAME" run chown -R 99:99 /startdir + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + testsudo librechroot -l "$BATS_TEST_NAME" run test -f /usr/bin/chcleanup } -it_displays_help_as_normal_user() { +@test "librechroot displays help as normal user" { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr @@ -98,36 +87,35 @@ it_displays_help_as_normal_user() { empty $tmpdir/stderr } -it_otherwise_fails_as_normal_user() { - librechroot -l "$roundup_test_name" run true >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "librechroot otherwise fails as normal user" { + librechroot -l "$BATS_TEST_NAME" run true >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] empty $tmpdir/stdout not empty $tmpdir/stderr } -it_displays_help_and_fails_with_0_args() { - LC_ALL=C librechroot -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "librechroot displays help and fails with 0 args" { + LC_ALL=C librechroot -l "$BATS_TEST_NAME" >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] empty $tmpdir/stdout [[ "$(sed -n 2p $tmpdir/stderr)" =~ Usage:.* ]] } -it_obeys_the_n_flag() { - require network sudo || return 0 +@test "librechroot obeys the n flag" { + require network sudo || skip - not test -f "$chrootdir/$roundup_test_name/$roundup_test_name/$roundup_test_name.stamp" + not test -f "$chrootdir/$BATS_TEST_NAME/$BATS_TEST_NAME/$BATS_TEST_NAME.stamp" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -n "$roundup_test_name" -l "$roundup_test_name" run touch /"$roundup_test_name.stamp" + testsudo librechroot -n "$BATS_TEST_NAME" -l "$BATS_TEST_NAME" run touch /"$BATS_TEST_NAME.stamp" - test -f "$chrootdir/$roundup_test_name/$roundup_test_name/$roundup_test_name.stamp" + test -f "$chrootdir/$BATS_TEST_NAME/$BATS_TEST_NAME/$BATS_TEST_NAME.stamp" } # requires sudo so we know it's not failing because it needs root -it_fails_for_unknown_commands() { - require sudo || return 0 +@test "librechroot fails for unknown commands" { + require sudo || skip testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -136,8 +124,8 @@ it_fails_for_unknown_commands() { } # requires sudo so we know it's not failing because it needs root -it_fails_for_unknown_flags() { - require sudo || return 0 +@test "librechroot fails for unknown flags" { + require sudo || skip testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -145,8 +133,8 @@ it_fails_for_unknown_flags() { not empty $tmpdir/stderr } -it_fails_when_syncing_a_copy_with_itself() { - require sudo || return 0 +@test "librechroot fails when syncing a copy with itself" { + require sudo || skip testsudo timeout 5 librechroot -l root sync || status=$? case $status in 0|124|137) # success|timeout+TERM|timeout+KILL @@ -156,36 +144,33 @@ it_fails_when_syncing_a_copy_with_itself() { esac } -it_deletes_copies() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" make - test -d "$chrootdir/default/$roundup_test_name" - testsudo librechroot -l "$roundup_test_name" delete - not test -e "$chrootdir/default/$roundup_test_name" +@test "librechroot deletes copies" { + require network sudo || skip + testsudo librechroot -l "$BATS_TEST_NAME" make + test -d "$chrootdir/default/$BATS_TEST_NAME" + testsudo librechroot -l "$BATS_TEST_NAME" delete + not test -e "$chrootdir/default/$BATS_TEST_NAME" } -it_deletes_subvolumes_recursively() { - require network sudo btrfs || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" make - testsudo librechroot -l "$roundup_test_name" install-name btrfs-progs - test -d "$chrootdir/default/$roundup_test_name" - not test -e "$chrootdir/default/$roundup_test_name/var/subvolume" - testsudo librechroot -l "$roundup_test_name" run btrfs subvolume create /var/subvolume - test -d "$chrootdir/default/$roundup_test_name/var/subvolume" - testsudo librechroot -l "$roundup_test_name" delete - not test -e "$chrootdir/default/$roundup_test_name" +@test "librechroot deletes subvolumes recursively" { + require network sudo btrfs || skip + testsudo librechroot -l "$BATS_TEST_NAME" make + testsudo librechroot -l "$BATS_TEST_NAME" install-name btrfs-progs + test -d "$chrootdir/default/$BATS_TEST_NAME" + not test -e "$chrootdir/default/$BATS_TEST_NAME/var/subvolume" + testsudo librechroot -l "$BATS_TEST_NAME" run btrfs subvolume create /var/subvolume + test -d "$chrootdir/default/$BATS_TEST_NAME/var/subvolume" + testsudo librechroot -l "$BATS_TEST_NAME" delete + not test -e "$chrootdir/default/$BATS_TEST_NAME" } -it_cleans_up_TMPDIR() { - require network sudo || return 0 +@test "librechroot cleans up TMPDIR" { + require network sudo || skip local dir="$tmpdir/tmp" mkdir -- "$dir" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - TMPDIR=$dir testsudo librechroot -l "$roundup_test_name" -A x86_64 make + TMPDIR=$dir testsudo librechroot -l "$BATS_TEST_NAME" -A x86_64 make # Make sure $dir is now empty rmdir -- "$dir" diff --git a/test/cases/libredbdiff.bats b/test/cases/libredbdiff.bats index 6cebbf6..ed19b6d 100644 --- a/test/cases/libredbdiff.bats +++ b/test/cases/libredbdiff.bats @@ -1,10 +1,7 @@ -#!/usr/bin/env roundup +load ../lib/common -describe libredbdiff -. ./test-common.sh - -before() { - common_before +setup() { + common_setup install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libredbdiff.conf" <<-'eot' statedir="$PWD" @@ -14,15 +11,15 @@ before() { eot } -it_displays_help() { +@test "libredbdiff displays help" { LC_ALL=C libredbdiff -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_handles_packages_with_multiple_provides_explicit() { - cd libredbdiff.d/statedir +@test "libredbdiff handles packages with multiple provides explicit" { + cd fixtures/libredbdiff/statedir libredbdiff -n libre >$tmpdir/stdout 2>$tmpdir/stderr @@ -30,8 +27,8 @@ it_handles_packages_with_multiple_provides_explicit() { diff -w ../expected-explicit.txt $tmpdir/stdout } -it_handles_packages_with_multiple_provides_implicit() { - cd libredbdiff.d/statedir +@test "libredbdiff handles packages with multiple provides implicit" { + cd fixtures/libredbdiff/statedir libredbdiff -n >$tmpdir/stdout 2>$tmpdir/stderr @@ -39,8 +36,8 @@ it_handles_packages_with_multiple_provides_implicit() { diff -w ../expected-implicit.txt $tmpdir/stdout } -it_fails_on_bad_repo_args() { - cd libredbdiff.d/statedir +@test "libredbdiff fails on bad repo args" { + cd fixtures/libredbdiff/statedir libredbdiff -n bogus >$tmpdir/stdout 2>$tmpdir/stderr || status=$? diff --git a/test/cases/librefetch.bats b/test/cases/librefetch.bats index 9edc227..47cd9bd 100644 --- a/test/cases/librefetch.bats +++ b/test/cases/librefetch.bats @@ -1,10 +1,7 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librefetch -. ./test-common.sh - -before() { - common_before +setup() { + common_setup cat >> "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u' @@ -23,16 +20,16 @@ before() { eot } -it_displays_help() { +@test "librefetch displays help" { LC_ALL=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_fails_with_bad_flags() { +@test "librefetch fails with bad flags" { local srcball=testpkg-1.0.tar.gz - cp librefetch.d/* "$tmpdir/" + cp fixtures/librefetch/* "$tmpdir/" cd "$tmpdir" mv PKGBUILD{-mksource,} @@ -47,9 +44,9 @@ it_fails_with_bad_flags() { # This test used to be called "it_cleans_src_libre_first", but let's # be honest: it checks pretty much everything related to normal # operation. -it_runs_with_mksource() { +@test "librefetch runs with mksource" { local srcball=testpkg-1.0.tar.gz - cp librefetch.d/* "$tmpdir/" + cp fixtures/librefetch/* "$tmpdir/" cd "$tmpdir" mv PKGBUILD{-mksource,} @@ -80,9 +77,9 @@ it_runs_with_mksource() { gpg --quiet --verify "$tmpdir/workdir/srcdest/$srcball"{.sig,} 2>/dev/null } -it_runs_with_srcbuild() { +@test "librefetch runs with srcbuild" { local srcball=testpkg-1.0.tar.gz - cp librefetch.d/* "$tmpdir/" + cp fixtures/librefetch/* "$tmpdir/" cd "$tmpdir" mv PKGBUILD{-srcbuild,} mv SRCBUILD{-srcbuild,} @@ -110,9 +107,9 @@ it_runs_with_srcbuild() { gpg --quiet --verify "$tmpdir/workdir/srcdest/$srcball"{.sig,} 2>/dev/null } -it_recurses() { +@test "librefetch recurses" { local srcball=testpkg-1.0.tar.gz - cp librefetch.d/* "$tmpdir/" + cp fixtures/librefetch/* "$tmpdir/" cd "$tmpdir" mv PKGBUILD{-recurse,} @@ -122,9 +119,9 @@ it_recurses() { gpg --quiet --verify "$tmpdir/workdir/srcdest/$srcball"{.sig,} 2>/dev/null } -it_doesnt_recurse_extra() { +@test "librefetch doesnt recurse extra" { local srcball=testpkg-1.0.tar.gz - cp librefetch.d/* "$tmpdir/" + cp fixtures/librefetch/* "$tmpdir/" cd "$tmpdir" mv PKGBUILD{-recurse,} diff --git a/test/cases/librelib.bats b/test/cases/librelib.bats index ebaf7b2..1bd80ae 100644 --- a/test/cases/librelib.bats +++ b/test/cases/librelib.bats @@ -1,9 +1,6 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librelib -. ./test-common.sh - -it_displays_help_and_fails_with_0_args() { +@test "librelib displays help and fails with 0 args" { librelib >$tmpdir/stdout 2>$tmpdir/stderr || status=$? empty $tmpdir/stdout @@ -11,7 +8,7 @@ it_displays_help_and_fails_with_0_args() { [[ $status != 0 ]] } -it_fails_with_2_args() { +@test "librelib fails with 2 args" { librelib a b >$tmpdir/stdout 2>$tmpdir/stderr || status=$? empty $tmpdir/stdout @@ -19,7 +16,7 @@ it_fails_with_2_args() { [[ $status != 0 ]] } -it_displays_usage_text() { +@test "librelib displays usage text" { librelib -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] @@ -29,7 +26,7 @@ it_displays_usage_text() { # Nothing in $(libdir) should be executable anymore (except that # $(libexecdir)=$(libdir), and executable things go in there. But I # digress, libremessages should not be executable anymore). -it_finds_messages() { +@test "librelib finds messages" { v1=$(librelib messages) v2=$(librelib libremessages) v3=$(librelib messages.sh) @@ -42,7 +39,7 @@ it_finds_messages() { } # conf.sh is non-executable -it_finds_conf() { +@test "librelib finds conf" { v1=$(librelib conf) v2=$(librelib libreconf) v3=$(librelib conf.sh) @@ -54,7 +51,7 @@ it_finds_conf() { [[ "$v1" == "$v4" ]] } -it_fails_to_find_phony() { +@test "librelib fails to find phony" { librelib phony >$tmpdir/stdout 2>$tmpdir/stderr || status=$? empty $tmpdir/stdout 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" } diff --git a/test/cases/librerelease.bats b/test/cases/librerelease.bats index 5ffbb14..26049bc 100644 --- a/test/cases/librerelease.bats +++ b/test/cases/librerelease.bats @@ -1,9 +1,6 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librerelease -. ./test-common.sh - -it_displays_usage_text() { +@test "librerelease displays usage text" { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C librerelease -h >"$tmpdir/stdout" 2>"$tmpdir/stderr" @@ -11,7 +8,7 @@ it_displays_usage_text() { empty "$tmpdir/stderr" } -it_lists_all_files() { +@test "librerelease lists all files" { WORKDIR="$tmpdir/workdir" mkdir -p "$WORKDIR/staging/repo1" "$WORKDIR/staging/repo2/sub" touch \ @@ -34,7 +31,7 @@ it_lists_all_files() { diff "$tmpdir/list-correct" "$tmpdir/list" } -it_fails_if_gpgkey_not_set() { +@test "librerelease fails if gpgkey not set" { unset GPGKEY WORKDIR="$tmpdir/workdir" diff --git a/test/cases/librestage.bats b/test/cases/librestage.bats index 2fe3415..1bc5c25 100644 --- a/test/cases/librestage.bats +++ b/test/cases/librestage.bats @@ -1,9 +1,6 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librestage -. ./test-common.sh - -it_displays_usage_text() { +@test "librestage displays usage text" { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C librestage -h >$tmpdir/stdout 2>$tmpdir/stderr @@ -11,7 +8,7 @@ it_displays_usage_text() { empty "$tmpdir/stderr" } -it_fails_with_0_args() { +@test "librestage fails with 0 args" { librestage >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -19,7 +16,7 @@ it_fails_with_0_args() { not empty "$tmpdir/stderr" } -it_fails_with_invalid_args() { +@test "librestage fails with invalid args" { librestage -q >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -27,17 +24,16 @@ it_fails_with_invalid_args() { not empty "$tmpdir/stderr" } -it_guesses_the_repo() { +@test "librestage guesses the repo" { nochroot=false; require network sudo || nochroot=true mkdir -p -- "$tmpdir/reponame/libretools-hello" - cp librestage.d/PKGBUILD-hello "$tmpdir/reponame/libretools-hello/PKGBUILD" + cp fixtures/librestage/PKGBUILD-hello "$tmpdir/reponame/libretools-hello/PKGBUILD" cd "$tmpdir/reponame/libretools-hello" if $nochroot; then makepkg else - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo libremakepkg -l "$roundup_test_name" + testsudo libremakepkg -l "$BATS_TEST_NAME" fi librestage @@ -46,7 +42,7 @@ it_guesses_the_repo() { $nochroot || globfile $tmpdir/workdir/staging/sources/parabola/libretools-hello-1.0-1-any.src.tar.?z } -it_stages_packages_without_PKGDEST() { +@test "librestage stages packages without PKGDEST" { nochroot=false; require network sudo || nochroot=true cat >> "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot @@ -54,14 +50,13 @@ it_stages_packages_without_PKGDEST() { SRCPKGDEST='' eot - cp librestage.d/PKGBUILD-hello "$tmpdir/PKGBUILD" + cp fixtures/librestage/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" if $nochroot; then makepkg else - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo libremakepkg -l "$roundup_test_name" + testsudo libremakepkg -l "$BATS_TEST_NAME" fi librestage repo1 diff --git a/test/cases/librexgettext.bats b/test/cases/librexgettext.bats index d4c8028..5bf9c93 100644 --- a/test/cases/librexgettext.bats +++ b/test/cases/librexgettext.bats @@ -1,16 +1,13 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librexgettext -. ./test-common.sh - -it_displays_help() { +@test "librexgettext displays help" { LC_ALL=C librexgettext -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_fails_with_0_args() { +@test "librexgettext fails with 0 args" { librexgettext >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -19,31 +16,31 @@ it_fails_with_0_args() { } passcase() { - librexgettext librexgettext.d/$roundup_test_name.sh > $tmpdir/actual.pot 2>$tmpdir/stderr + librexgettext fixtures/librexgettext/$BATS_TEST_NAME.sh > $tmpdir/actual.pot 2>$tmpdir/stderr empty $tmpdir/stderr - diff -u librexgettext.d/$roundup_test_name.pot $tmpdir/actual.pot + diff -u fixtures/librexgettext/$BATS_TEST_NAME.pot $tmpdir/actual.pot } -it_handles_multiple_skipped_flags() { passcase; } -it_handles_zero_flags() { passcase; } -it_handles_librefetch_flags() { passcase; } +@test "librexgettext handles multiple skipped flags" { passcase; } +@test "librexgettext handles zero flags" { passcase; } +@test "librexgettext handles librefetch flags" { passcase; } -it_fails_on_missing_final_flag_description() { - librexgettext librexgettext.d/$roundup_test_name.sh > /dev/null 2>$tmpdir/stderr || status=$? +@test "librexgettext fails on missing final flag description" { + librexgettext fixtures/librexgettext/$BATS_TEST_NAME.sh > /dev/null 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] - [[ "$(sed 1q $tmpdir/stderr)" = "librexgettext.d/$roundup_test_name.sh:4:"* ]] + [[ "$(sed 1q $tmpdir/stderr)" = "fixtures/librexgettext/$BATS_TEST_NAME.sh:4:"* ]] } -it_fails_on_subshell_flag_descriptions() { - librexgettext librexgettext.d/$roundup_test_name.sh > /dev/null 2>$tmpdir/stderr || status=$? +@test "librexgettext fails on subshell flag descriptions" { + librexgettext fixtures/librexgettext/$BATS_TEST_NAME.sh > /dev/null 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] - [[ "$(sed 1q $tmpdir/stderr)" = "librexgettext.d/$roundup_test_name.sh:4-6:"* ]] + [[ "$(sed 1q $tmpdir/stderr)" = "fixtures/librexgettext/$BATS_TEST_NAME.sh:4-6:"* ]] } -it_doesnt_keep_failing() { +@test "librexgettext doesnt keep failing" { librexgettext some_file_that_doesnt_exist >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -51,8 +48,8 @@ it_doesnt_keep_failing() { [[ "$(wc -l <$tmpdir/stderr)" == 1 ]] } -it_handles_multiple_files() { - librexgettext librexgettext.d/combine1.sh librexgettext.d/combine2.sh > $tmpdir/actual.pot 2>$tmpdir/stderr +@test "librexgettext handles multiple files" { + librexgettext fixtures/librexgettext/combine1.sh fixtures/librexgettext/combine2.sh > $tmpdir/actual.pot 2>$tmpdir/stderr empty $tmpdir/stderr - diff -u librexgettext.d/combine.pot $tmpdir/actual.pot + diff -u fixtures/librexgettext/combine.pot $tmpdir/actual.pot } diff --git a/test/cases/pkgbuild-check-nonfree.bats b/test/cases/pkgbuild-check-nonfree.bats index 0582e29..36f6619 100644 --- a/test/cases/pkgbuild-check-nonfree.bats +++ b/test/cases/pkgbuild-check-nonfree.bats @@ -1,10 +1,7 @@ -#!/usr/bin/env roundup +load ../lib/common -describe pkgbuild-check-nonfree -. ./test-common.sh - -before() { - common_before +setup() { + common_setup # Disable networking for blacklist.txt, and install a cached version instead cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot @@ -16,7 +13,7 @@ before() { eot } -it_displays_usage_text() { +@test "pkgbuild-check-nonfree displays usage text" { # This test seems silly, but it makes sure that it is executable, # syntactically correct, and loading libraries works. LC_ALL=C pkgbuild-check-nonfree -h >$tmpdir/stdout 2>$tmpdir/stderr @@ -27,24 +24,24 @@ it_displays_usage_text() { [[ $status == 0 ]] } -it_succeeds_for_free_depends() { - pkgbuild-check-nonfree pkgbuild-check-nonfree.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "pkgbuild-check-nonfree succeeds for free depends" { + pkgbuild-check-nonfree fixtures/pkgbuild-check-nonfree/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || status=$? empty $tmpdir/stdout not empty $tmpdir/stderr [[ $status == 0 ]] } -it_succeeds_for_nonfree_depend_with_replacement() { - pkgbuild-check-nonfree pkgbuild-check-nonfree.d/PKGBUILD.nonfree-replacement >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "pkgbuild-check-nonfree succeeds for nonfree depend with replacement" { + pkgbuild-check-nonfree fixtures/pkgbuild-check-nonfree/PKGBUILD.nonfree-replacement >$tmpdir/stdout 2>$tmpdir/stderr || status=$? empty $tmpdir/stdout not empty $tmpdir/stderr [[ $status == 0 ]] } -it_fails_for_nonfree_depend() { - pkgbuild-check-nonfree pkgbuild-check-nonfree.d/PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "pkgbuild-check-nonfree fails for nonfree depend" { + pkgbuild-check-nonfree fixtures/pkgbuild-check-nonfree/PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] empty $tmpdir/stdout not empty $tmpdir/stderr @@ -57,10 +54,10 @@ it_fails_for_nonfree_depend() { not empty $tmpdir/stderr } -it_fails_when_there_is_no_blacklist() { +@test "pkgbuild-check-nonfree fails when there is no blacklist" { rm $XDG_CACHE_HOME/libretools/blacklist.txt - pkgbuild-check-nonfree pkgbuild-check-nonfree.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || status=$? + pkgbuild-check-nonfree fixtures/pkgbuild-check-nonfree/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || status=$? empty $tmpdir/stdout not empty $tmpdir/stderr diff --git a/test/cases/toru-path.bats b/test/cases/toru-path.bats index 5576ad7..d891d3d 100644 --- a/test/cases/toru-path.bats +++ b/test/cases/toru-path.bats @@ -1,22 +1,19 @@ -#!/usr/bin/env roundup +load ../lib/common -describe toru-path -. ./test-common.sh - -it_displays_help() { +@test "toru-path displays help" { LC_ALL=C toru-path -h >$tmpdir/stdout 2>$tmpdir/stderr [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] empty $tmpdir/stderr } -it_runs() { +@test "toru-path runs" { cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot TORUPATH=${tmpdir@Q} REPOS=(libre) eot cat >> "$HOME/.abs.conf" <<-eot - ABSROOT=${PWD@Q}/toru.d + ABSROOT=${PWD@Q}/fixtures/toru eot toru-path @@ -27,26 +24,26 @@ it_runs() { done > "$tmpdir/paths-actual.txt" printf '«%q» -> «%q»\n' \ - BAR "$PWD/toru.d/libre/split-base" \ - BAZ "$PWD/toru.d/libre/split-base" \ - FOO "$PWD/toru.d/libre/split-base" \ - bar "$PWD/toru.d/libre/split" \ - baz "$PWD/toru.d/libre/split" \ - foo "$PWD/toru.d/libre/split" \ - simple "$PWD/toru.d/libre/simple" \ - split-base "$PWD/toru.d/libre/split-base" \ + BAR "$PWD/fixtures/toru/libre/split-base" \ + BAZ "$PWD/fixtures/toru/libre/split-base" \ + FOO "$PWD/fixtures/toru/libre/split-base" \ + bar "$PWD/fixtures/toru/libre/split" \ + baz "$PWD/fixtures/toru/libre/split" \ + foo "$PWD/fixtures/toru/libre/split" \ + simple "$PWD/fixtures/toru/libre/simple" \ + split-base "$PWD/fixtures/toru/libre/split-base" \ > "$tmpdir/paths-expected.txt" diff "$tmpdir/paths-expected.txt" "$tmpdir/paths-actual.txt" } -it_sets_torupath() { +@test "toru-path sets torupath" { cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot TORUPATH=${tmpdir@Q} REPOS=(libre) eot cat >> "$HOME/.abs.conf" <<-eot - ABSROOT=${PWD@Q}/toru.d + ABSROOT=${PWD@Q}/fixtures/toru eot mkdir -p "$tmpdir/x" diff --git a/test/fixtures/librexgettext/combine.pot b/test/fixtures/librexgettext/combine.pot index 80d066f..967a98b 100644 --- a/test/fixtures/librexgettext/combine.pot +++ b/test/fixtures/librexgettext/combine.pot @@ -1,15 +1,15 @@ -#: librexgettext.d/combine1.sh:4 +#: fixtures/librexgettext/combine1.sh:4 msgid "Flag a" msgstr "" -#: librexgettext.d/combine1.sh:5 +#: fixtures/librexgettext/combine1.sh:5 msgid "Flag b" msgstr "" -#: librexgettext.d/combine2.sh:4 +#: fixtures/librexgettext/combine2.sh:4 msgid "Flag 1" msgstr "" -#: librexgettext.d/combine2.sh:5 +#: fixtures/librexgettext/combine2.sh:5 msgid "Flag 2" msgstr "" diff --git a/test/fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.pot b/test/fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.pot index 0d76a49..9548695 100644 --- a/test/fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.pot +++ b/test/fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.pot @@ -1,40 +1,40 @@ -#: librexgettext.d/it_handles_librefetch_flags.sh:4 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:4 msgid "Settings:" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:5 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:5 msgid "Force create mode (don't download)" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:6 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:6 msgid "Force download mode (don't create)" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:7 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:7 msgid "FILE" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:7 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:7 msgid "Use an alternate build script (instead of 'PKGBUILD'). If an " "SRCBUILD exists in the same directory, it is used instead" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:10 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:10 msgid "Alternate modes:" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:11 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:11 msgid "Generate integrity checks for source files" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:12 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:12 msgid "Print the effective build script (SRCBUILD)" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:13 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:13 msgid "Generate and print the location of the effective makepkg script" msgstr "" -#: librexgettext.d/it_handles_librefetch_flags.sh:15 +#: fixtures/librexgettext/test_librexgettext_handles_librefetch_flags.sh:15 msgid "Show this message" msgstr "" diff --git a/test/fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.pot b/test/fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.pot index cae2a17..714ebac 100644 --- a/test/fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.pot +++ b/test/fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.pot @@ -1,58 +1,58 @@ -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:4 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:4 msgid "Flag 1" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:4 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:6 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:7 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:8 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:9 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:10 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:11 -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:13 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:4 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:6 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:7 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:8 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:9 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:10 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:11 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:13 msgid "OPTARG" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:5 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:5 msgid "Flag 2" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:6 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:6 msgid "Flag 3" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:7 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:7 msgid "Flag 4" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:8 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:8 msgid "Flag 5" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:9 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:9 msgid "Flag 6" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:10 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:10 msgid "Flag 7" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:11 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:11 msgid "Flag 8" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:13 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:13 msgid "FLAG 1" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:14 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:14 msgid "FLAG 2" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:16 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:16 msgid "FLAG A" msgstr "" -#: librexgettext.d/it_handles_multiple_skipped_flags.sh:17 +#: fixtures/librexgettext/test_librexgettext_handles_multiple_skipped_flags.sh:17 msgid "FLAG B" msgstr "" -- cgit v1.2.2