From 9d90d48c9d01fa45d1a363fc01d0a1c2ffc9e790 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 10 Apr 2017 22:31:02 -0400 Subject: test/: Tidy before()/after() definitions. --- test/aur-test.sh | 9 --------- test/is_built-test.sh | 9 --------- test/lib-blacklist-test.sh | 9 --------- test/lib-conf-test.sh | 9 --------- test/lib-messages-test.sh | 9 --------- test/librechroot-test.sh | 17 +---------------- test/librefetch-test.sh | 9 +-------- test/librelib-test.sh | 9 --------- test/libremakepkg-test.sh | 19 +------------------ test/librerelease-test.sh | 9 +-------- test/librestage-test.sh | 9 +-------- test/pkgbuild-check-nonfree-test.sh | 9 +-------- test/test-common.sh | 36 +++++++++++++++++++++++++++--------- 13 files changed, 33 insertions(+), 129 deletions(-) diff --git a/test/aur-test.sh b/test/aur-test.sh index 5de590b..47f6d87 100644 --- a/test/aur-test.sh +++ b/test/aur-test.sh @@ -1,17 +1,8 @@ #!/usr/bin/env roundup describe aur - . ./test-common.sh -before() { - _before -} - -after() { - _after -} - it_displays_help() { LC_ALL=C aur -h >$tmpdir/stdout 2>$tmpdir/stderr diff --git a/test/is_built-test.sh b/test/is_built-test.sh index f7f6c65..147bdaa 100644 --- a/test/is_built-test.sh +++ b/test/is_built-test.sh @@ -1,17 +1,8 @@ #!/usr/bin/env roundup describe is_built - . ./test-common.sh -before() { - _before -} - -after() { - _after -} - it_displays_help() { LC_ALL=C is_built -h >$tmpdir/stdout 2>$tmpdir/stderr diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh index 7b06f84..49c756e 100644 --- a/test/lib-blacklist-test.sh +++ b/test/lib-blacklist-test.sh @@ -1,19 +1,10 @@ #!/usr/bin/env roundup describe libreblacklist - . ./test-common.sh _blacklist_url=https://projects.parabola.nu/blacklist.git/plain/blacklist.txt -before() { - _before -} - -after() { - _after -} - it_works_with_just_pkgname() { v="$(libreblacklist normalize << "$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_sudo -) +setup_chrootdir it_creates_repo_for_new_chroots() { require network sudo || return 0 diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh index f10ee7f..6871be1 100644 --- a/test/librefetch-test.sh +++ b/test/librefetch-test.sh @@ -1,15 +1,12 @@ #!/usr/bin/env roundup describe librefetch - . ./test-common.sh KEYSERVER=hkp://pool.sks-keyservers.net GPG="gpg --quiet --batch --no-tty --no-permission-warning --keyserver ${KEYSERVER}" -before() { - _before - +common_before() { mkdir -p "$XDG_CONFIG_HOME"/{pacman,libretools} "$tmpdir/srcdest" cat < "$XDG_CONFIG_HOME/pacman/makepkg.conf" @@ -44,10 +41,6 @@ EOF | $GPG --gen-key 2>/dev/null } -after() { - _after -} - it_displays_help() { LC_ALL=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr diff --git a/test/librelib-test.sh b/test/librelib-test.sh index 24c4478..72cbfd2 100644 --- a/test/librelib-test.sh +++ b/test/librelib-test.sh @@ -1,17 +1,8 @@ #!/usr/bin/env roundup describe librelib - . ./test-common.sh -before() { - _before -} - -after() { - _after -} - it_displays_help_and_fails_with_0_args() { ret=0 librelib >$tmpdir/stdout 2>$tmpdir/stderr || ret=$? diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh index 2e918ad..ef4ab6a 100644 --- a/test/libremakepkg-test.sh +++ b/test/libremakepkg-test.sh @@ -1,26 +1,9 @@ #!/usr/bin/env roundup describe libremakepkg - . ./test-common.sh -_setup_chrootdir - -before() { - _before libremakepkg - - mkdir -p "$XDG_CONFIG_HOME"/libretools - - echo "BLACKLIST=https://git.parabola.nu/blacklist.git/plain/blacklist.txt" >"$XDG_CONFIG_HOME"/libretools/libretools.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_sudo -} +setup_chrootdir it_builds_a_trivial_package() { require network sudo || return 0 diff --git a/test/librerelease-test.sh b/test/librerelease-test.sh index a44b150..572e100 100644 --- a/test/librerelease-test.sh +++ b/test/librerelease-test.sh @@ -1,12 +1,9 @@ #!/usr/bin/env roundup describe librestage - . ./test-common.sh -before() { - _before - +common_before() { mkdir -p $XDG_CONFIG_HOME/libretools { echo "WORKDIR='$tmpdir/workdir'" @@ -20,10 +17,6 @@ before() { mkdir -p "$tmpdir/workdir/pkgdest" } -after() { - _after -} - it_displays_usage_text() { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C librerelease -h >"$tmpdir/stdout" 2>"$tmpdir/stderr" diff --git a/test/librestage-test.sh b/test/librestage-test.sh index affad6a..9ecbf38 100644 --- a/test/librestage-test.sh +++ b/test/librestage-test.sh @@ -1,12 +1,9 @@ #!/usr/bin/env roundup describe librestage - . ./test-common.sh -before() { - _before - +common_before() { mkdir -p $XDG_CONFIG_HOME/libretools echo "WORKDIR='$tmpdir/workdir'" > $XDG_CONFIG_HOME/libretools/libretools.conf echo "ARCHES=('x86_64' 'i686' 'misp64el')" >> $XDG_CONFIG_HOME/libretools/libretools.conf @@ -20,10 +17,6 @@ before() { mkdir -p "$tmpdir/workdir/pkgdest" } -after() { - _after -} - it_displays_usage_text() { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C librestage -h >$tmpdir/stdout 2>$tmpdir/stderr diff --git a/test/pkgbuild-check-nonfree-test.sh b/test/pkgbuild-check-nonfree-test.sh index 2af2669..e6679ed 100644 --- a/test/pkgbuild-check-nonfree-test.sh +++ b/test/pkgbuild-check-nonfree-test.sh @@ -5,12 +5,9 @@ pcn=pkgbuild-check-nonfree psn=pkgbuild-summarize-nonfree describe $pcn - . ./test-common.sh -before() { - _before - +common_before() { mkdir -p $XDG_CONFIG_HOME/libretools echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf @@ -20,10 +17,6 @@ before() { echo 'skype' >>$blacklist } -after() { - _after -} - it_displays_usage_text() { # This test seems silly, but it makes sure that it is executable, # syntactically correct, and loading libraries works. diff --git a/test/test-common.sh b/test/test-common.sh index c1d050a..f81738a 100644 --- a/test/test-common.sh +++ b/test/test-common.sh @@ -5,7 +5,15 @@ if [[ $HOME == "$(eval echo ~$USER)" ]]; then exit 1 fi -_before() { +common_before() { + : +} + +common_after() { + : +} + +before() { unset PKGDEST SRCDEST SRCPKGDEST LOGDEST unset BUILDDIR unset PKGEXT SRCEXT @@ -13,25 +21,32 @@ _before() { tmpdir="$(mktemp -d --tmpdir "test-${roundup_desc//\//-}.XXXXXXXXXXXX")" chmod 755 "$tmpdir" stat=0 + common_before } -_after() { - rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" -} - -_after_sudo() { - if [[ $SUDO ]]; then +after() { + common_after + if [[ -f "$tmpdir/.used-sudo" ]]; then sudo rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" else rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" fi } -_setup_chrootdir() { +setup_chrootdir() { if [[ -z "$chrootdir" ]]; then export chrootdir="$(mktemp -d --tmpdir "test-chrootdir.XXXXXXXXXXXX")" trap "$(printf '_cleanup_chrootdir %q' "$chrootdir")" EXIT fi + common_before() { + mkdir -p "$XDG_CONFIG_HOME"/libretools + + echo "BLACKLIST=https://git.parabola.nu/blacklist.git/plain/blacklist.txt" >"$XDG_CONFIG_HOME"/libretools/libretools.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 + } } _cleanup_chrootdir() ( @@ -67,7 +82,10 @@ require() ( libremessages warning "Next test requires %s; Skipping (passing)..." "$(echo "${missing[*]}"|sed 's/ /, /g')" &>/dev/tty return 1 fi - return 0; + if libremessages in_array "sudo" "$@"; then + touch "$tmpdir/.used-sudo" + fi + return 0 ) empty() ( -- cgit v1.2.2