summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore1
-rw-r--r--test/aur-test.sh30
-rw-r--r--test/is_built-test.sh60
-rw-r--r--test/lib-blacklist-test.sh134
-rw-r--r--test/lib-conf-test.sh43
-rw-r--r--test/lib-messages-test.sh64
-rw-r--r--test/librechroot-test.sh129
-rw-r--r--test/librefetch-test.sh99
-rw-r--r--test/librefetch.d/PKGBUILD18
-rw-r--r--test/librefetch.d/PKGBUILD-recurse18
-rw-r--r--test/librefetch.d/list.txt5
-rw-r--r--test/librelib-test.sh75
-rw-r--r--test/libremakepkg-test.sh134
-rw-r--r--test/libremakepkg.d/PKGBUILD-hello19
-rw-r--r--test/libremakepkg.d/PKGBUILD-netbuild17
-rw-r--r--test/libremakepkg.d/PKGBUILD-netpackage12
-rw-r--r--test/libremakepkg.d/PKGBUILD-netprepare17
-rw-r--r--test/libremakepkg.d/PKGBUILD-testpkg119
-rw-r--r--test/libremakepkg.d/PKGBUILD-testpkg219
-rw-r--r--test/librerelease-test.sh56
-rw-r--r--test/librestage-test.sh72
-rw-r--r--test/librestage.d/PKGBUILD-hello19
-rw-r--r--test/pkgbuild-check-nonfree-test.sh78
-rw-r--r--test/pkgbuild-check-nonfree.d/PKGBUILD.free18
-rw-r--r--test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree18
-rw-r--r--test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree-replacement18
-rw-r--r--test/test-common.sh78
-rwxr-xr-xtest/testenv69
28 files changed, 1339 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..2226ac6
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+.roundup.*
diff --git a/test/aur-test.sh b/test/aur-test.sh
new file mode 100644
index 0000000..5de590b
--- /dev/null
+++ b/test/aur-test.sh
@@ -0,0 +1,30 @@
+#!/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
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+it_fails_with_0_args() {
+ aur >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+# TODO: Actually test
diff --git a/test/is_built-test.sh b/test/is_built-test.sh
new file mode 100644
index 0000000..f7f6c65
--- /dev/null
+++ b/test/is_built-test.sh
@@ -0,0 +1,60 @@
+#!/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
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+it_fails_with_0_args() {
+ is_built >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat -gt 1 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_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() {
+ is_built phony-ne-package 100 >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat == 1 ]]
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
+}
+
+it_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 || stat=$?
+
+ [[ $stat == 1 ]]
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
+}
+
+it_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
+
+ empty $tmpdir/stdout
+ empty $tmpdir/stderr
+}
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh
new file mode 100644
index 0000000..7b06f84
--- /dev/null
+++ b/test/lib-blacklist-test.sh
@@ -0,0 +1,134 @@
+#!/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 <<<skype)"; [[ $v == 'skype::' ]]
+ v="$(libreblacklist get-pkg <<<skype)"; [[ $v == skype ]]
+ v="$(libreblacklist get-rep <<<skype)"; [[ -z $v ]]
+ v="$(libreblacklist get-reason <<<skype)"; [[ -z $v ]]
+}
+
+it_works_with_everything_set() {
+ line='linux:linux-libre:nonfree blobs and firmwares'
+ v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
+ v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'linux' ]]
+ v="$(libreblacklist get-rep <<<"$line")"; [[ $v == 'linux-libre' ]]
+ v="$(libreblacklist get-reason <<<"$line")"; [[ $v == 'nonfree blobs and firmwares' ]]
+}
+
+it_normalizes_correctly() {
+ v="$(libreblacklist normalize <<<pkg)"; [[ $v == 'pkg::' ]]
+ v="$(libreblacklist normalize <<<pkg:)"; [[ $v == 'pkg::' ]]
+ v="$(libreblacklist normalize <<<pkg::)"; [[ $v == 'pkg::' ]]
+ v="$(libreblacklist normalize <<<pkg:rep)"; [[ $v == 'pkg:rep:' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:)"; [[ $v == 'pkg:rep:' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:reason)"; [[ $v == 'pkg:rep:reason' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:reason:)"; [[ $v == 'pkg:rep:reason:' ]]
+}
+
+it_works_with_colons_in_reason() {
+ line='package:replacement:my:reason'
+ v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
+ v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'package' ]]
+ v="$(libreblacklist get-rep <<<"$line")"; [[ $v == 'replacement' ]]
+ v="$(libreblacklist get-reason <<<"$line")"; [[ $v == 'my:reason' ]]
+}
+
+it_fails_update_with_no_blacklist_or_network() {
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_fails_cat_with_no_blacklist_or_network() {
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_fails_update_when_BLACKLIST_is_unset() {
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ echo "BLACKLIST=" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_fails_cat_when_syntax_error_in_conf() {
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ # there is a stray single quote in there
+ printf "BLACKLIST='%q\n" "${_blacklist_url}" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_downloads_the_blacklist_as_needed() {
+ require network || return 0
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ printf 'BLACKLIST=%q\n' "${_blacklist_url}" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr
+
+ not empty $tmpdir/stdout
+}
+
+it_downloads_the_blacklist_repeatedly() {
+ require network || return 0
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ printf 'BLACKLIST=%q\n' "${_blacklist_url}" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ libreblacklist update
+ libreblacklist update
+}
+
+it_displays_help_and_fails_with_no_args() {
+ LC_ALL=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ [[ "$(sed 1q $tmpdir/stderr)" =~ 'Usage: libreblacklist ' ]]
+}
+
+it_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() {
+ LC_ALL=C libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" == 'Usage: libreblacklist cat' ]]
+ empty $tmpdir/stderr
+}
diff --git a/test/lib-conf-test.sh b/test/lib-conf-test.sh
new file mode 100644
index 0000000..efad907
--- /dev/null
+++ b/test/lib-conf-test.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env roundup
+
+describe lib/conf.sh
+
+. ./test-common.sh
+
+before() {
+ _before test-conf.sh
+}
+
+after() {
+ _after
+}
+
+it_sets_makepkg_vars_in_custom_file() {
+ unset PKGDEST
+ touch "$tmpdir/makepkg.conf"
+ . $(librelib conf.sh)
+ MAKEPKG_CONF="$tmpdir/makepkg.conf" set_var makepkg PKGDEST /pkgdest
+ . "$tmpdir/makepkg.conf"
+ [[ $PKGDEST == /pkgdest ]]
+}
+
+it_figures_out_HOME_when_root() {
+ require sudo || return 0
+ # 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 ]]
+ cd "$tmpdir"
+ echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh
+ LIBREHOME=$(testsudo bash ./test.sh)
+ [[ $LIBREHOME != /root ]]
+}
+
+it_respects_custom_HOME() {
+ cd "$tmpdir"
+ echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh
+
+ export HOME=/foo
+ LIBREHOME=$(bash ./test.sh)
+
+ [[ $LIBREHOME == /foo ]]
+}
diff --git a/test/lib-messages-test.sh b/test/lib-messages-test.sh
new file mode 100644
index 0000000..d895d99
--- /dev/null
+++ b/test/lib-messages-test.sh
@@ -0,0 +1,64 @@
+#!/usr/bin/env roundup
+
+describe libremessages
+
+. ./test-common.sh
+
+before() {
+ _before
+}
+
+after() {
+ _after
+}
+
+it_can_be_included_twice() (
+ . libremessages
+ . libremessages
+)
+
+it_can_be_included_with_set_euE() (
+ set -euE
+ . libremessages
+)
+
+it_works_with_no_color_and_set_euE() (
+ (
+ unset TERM
+ set -euE
+ . libremessages
+ msg Foo
+ ) >$tmpdir/stdout 2>$tmpdir/stderr
+
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+)
+
+it_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() {
+ ret=0
+ libremessages msg || ret=$?
+ [[ $ret != 0 ]]
+}
+
+it_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 \
+ -a adesc \
+ -b bdesc \
+ Head1: \
+ -c cdesc > $tmpdir/out
+ printf '%s\n' \
+ ' -a adesc' \
+ ' -b bdesc' \
+ ' Head1:' \
+ ' -c cdesc' > $tmpdir/exp
+ diff -u $tmpdir/exp $tmpdir/out
+}
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh
new file mode 100644
index 0000000..667246c
--- /dev/null
+++ b/test/librechroot-test.sh
@@ -0,0 +1,129 @@
+#!/usr/bin/env roundup
+
+describe librechroot
+
+. ./test-common.sh
+
+_setup_chrootdir
+
+before() {
+ _before librechroot
+
+ mkdir -p "$XDG_CONFIG_HOME"/libretools
+
+ 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
+)
+
+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
+}
+
+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
+ # TODO: inspect /repo/* more
+}
+
+it_respects_exit_status_if_out_isnt_a_tty() (
+ require network sudo || return 0
+ set -o pipefail
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+ r=0
+ { testsudo librechroot -l "$roundup_test_name" run bash -c 'exit 3' | cat; } || r=$?
+
+ [[ $r == 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
+}
+
+it_disables_networking_when_requested() {
+ require network sudo || return 0
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+
+ 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
+}
+
+it_handles_CHROOTEXTRAPKG_correctly() {
+ requuire network sudo || return 0
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+
+ not testsudo librechroot -l "$roundup_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
+ 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
+}
+
+it_displays_help_as_normal_user() {
+ rm -rf "$XDG_CONFIG_HOME"
+ LC_ALL=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+it_otherwise_fails_as_normal_user() {
+ librechroot -l "$roundup_test_name" run true >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 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 || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ [[ "$(sed -n 2p $tmpdir/stderr)" =~ Usage:.* ]]
+}
+
+# requires sudo so we know it's not failing because it needs root
+it_fails_for_unknown_commands() {
+ require sudo || return 0
+ testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+# requires sudo so we know it's not failing because it needs root
+it_fails_for_unknown_flags() {
+ require sudo || return 0
+ testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_fails_when_syncing_a_copy_with_itself() {
+ require sudo || return 0
+ testsudo timeout 5 librechroot -l root sync || stat=$?
+ case $stat in
+ 0|124|137) # success|timeout+TERM|timeout+KILL
+ false;;
+ *)
+ true;;
+ esac
+}
diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh
new file mode 100644
index 0000000..f10ee7f
--- /dev/null
+++ b/test/librefetch-test.sh
@@ -0,0 +1,99 @@
+#!/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
+
+ mkdir -p "$XDG_CONFIG_HOME"/{pacman,libretools} "$tmpdir/srcdest"
+
+ cat <<EOF > "$XDG_CONFIG_HOME/pacman/makepkg.conf"
+DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
+ 'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'rsync::/usr/bin/rsync --no-motd -z %u %o'
+ 'scp::/usr/bin/scp -C %u %o')
+BUILDDIR=""
+SRCDEST=$tmpdir/srcdest
+. ${_librelib_conf_sh_pkgconfdir}/librefetch-makepkg.conf
+EOF
+ sed -i 's,/usr/bin/librefetch,$(which librefetch),' \
+ "${_librelib_conf_sh_pkgconfdir}/librefetch-makepkg.conf"
+
+ export MAKEPKG_CONF="$XDG_CONFIG_HOME/pacman/makepkg.conf"
+
+ printf '%s\n' \
+ 'MIRRORS=("phony://example.com/dir/")' \
+ 'DOWNLOADER=/usr/bin/false' \
+ > "$XDG_CONFIG_HOME/libretools/librefetch.conf"
+
+ printf '%s\n' \
+ 'Key-Type: RSA' \
+ 'Key-Length: 1024' \
+ 'Key-Usage: sign' \
+ 'Name-Real: Temporary LibreTools testsuite key' \
+ 'Name-Email: libretools-test@localhost' \
+ 'Expire-Date: 0' \
+ '%no-protection' \
+ '%commit' \
+ | $GPG --gen-key 2>/dev/null
+}
+
+after() {
+ _after
+}
+
+it_displays_help() {
+ LC_ALL=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+# 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() {
+ local srcball=testpkg-1.0.tar.gz
+ cp librefetch.d/* "$tmpdir/"
+ cd "$tmpdir"
+
+ # Create garbage, to verifiy that it cleans src-libre first
+ mkdir -p src-libre/foo
+ touch src-libre/foo/file
+
+ # Run librefetch
+ makepkg -g
+
+ # Verify that no temporary files were left around
+ not test -e librefetch.*
+
+ # Verify:
+ # - The srcball was created...
+ # - ... and is in the correct directory
+ # - The srcball does not contain the garbage created earlier
+ # - The files in the srcball are in the correct order (if the
+ # order isn't ensured, then this would only sometimes fail,
+ # unfortunately).
+ bsdtar tf "$tmpdir/srcdest/$srcball" > list-pkg.txt
+ diff -u list.txt list-pkg.txt
+ # Verify that the signature was created and matches
+ gpg --quiet --verify "$tmpdir/srcdest/$srcball"{.sig,} 2>/dev/null
+}
+
+it_recurses() {
+ local srcball=testpkg-1.0.tar.gz
+ cp librefetch.d/* "$tmpdir/"
+ cd "$tmpdir"
+ mv PKGBUILD{-recurse,}
+
+ makepkg -g
+ bsdtar tf "$tmpdir/srcdest/$srcball" > list-pkg.txt
+ diff -u list.txt list-pkg.txt
+ gpg --quiet --verify "$tmpdir/srcdest/$srcball"{.sig,} 2>/dev/null
+}
diff --git a/test/librefetch.d/PKGBUILD b/test/librefetch.d/PKGBUILD
new file mode 100644
index 0000000..6547e25
--- /dev/null
+++ b/test/librefetch.d/PKGBUILD
@@ -0,0 +1,18 @@
+pkgname=testpkg
+pkgver=1.0
+pkgrel=1
+pkgdesc=foo
+arch=(any)
+source=("libre://$pkgname-$pkgver.tar.gz"{,.sig})
+
+mksource() {
+ mkdir "$srcdir/bar"
+ local file
+ for file in '~foo' '~a' a A; do
+ touch "$srcdir/bar/$file"
+ done
+}
+
+package() {
+ :;
+}
diff --git a/test/librefetch.d/PKGBUILD-recurse b/test/librefetch.d/PKGBUILD-recurse
new file mode 100644
index 0000000..fad5976
--- /dev/null
+++ b/test/librefetch.d/PKGBUILD-recurse
@@ -0,0 +1,18 @@
+pkgname=testpkg
+pkgver=1.0
+pkgrel=1
+pkgdesc=foo
+arch=(any)
+source=("libre://$pkgname-$pkgver.tar.gz.sig")
+
+mksource() {
+ mkdir "$srcdir/bar"
+ local file
+ for file in '~foo' '~a' a A; do
+ touch "$srcdir/bar/$file"
+ done
+}
+
+package() {
+ :;
+}
diff --git a/test/librefetch.d/list.txt b/test/librefetch.d/list.txt
new file mode 100644
index 0000000..9bd32f4
--- /dev/null
+++ b/test/librefetch.d/list.txt
@@ -0,0 +1,5 @@
+bar/
+bar/A
+bar/a
+bar/~a
+bar/~foo
diff --git a/test/librelib-test.sh b/test/librelib-test.sh
new file mode 100644
index 0000000..24c4478
--- /dev/null
+++ b/test/librelib-test.sh
@@ -0,0 +1,75 @@
+#!/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=$?
+
+ empty $tmpdir/stdout
+ [[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]]
+ [[ $ret != 0 ]]
+}
+
+it_fails_with_2_args() {
+ ret=0
+ librelib a b >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
+
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+ [[ $ret != 0 ]]
+}
+
+it_displays_usage_text() {
+ librelib -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+# 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() {
+ v1=$(librelib messages)
+ v2=$(librelib libremessages)
+ v3=$(librelib messages.sh)
+ v4=$(librelib libremessages.sh)
+
+ [[ -r "$v1" && ! -x "$v1" ]]
+ [[ "$v1" == "$v2" ]]
+ [[ "$v1" == "$v3" ]]
+ [[ "$v1" == "$v4" ]]
+}
+
+# conf.sh is non-executable
+it_finds_conf() {
+ v1=$(librelib conf)
+ v2=$(librelib libreconf)
+ v3=$(librelib conf.sh)
+ v4=$(librelib libreconf.sh)
+
+ [[ -r "$v1" && ! -x "$v1" ]]
+ [[ "$v1" == "$v2" ]]
+ [[ "$v1" == "$v3" ]]
+ [[ "$v1" == "$v4" ]]
+}
+
+it_fails_to_find_phony() {
+ ret=0
+ librelib phony >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
+
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+ [[ $ret != 0 ]]
+}
diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh
new file mode 100644
index 0000000..ddccab0
--- /dev/null
+++ b/test/libremakepkg-test.sh
@@ -0,0 +1,134 @@
+#!/usr/bin/env roundup
+
+describe libremakepkg
+
+. ./test-common.sh
+
+_setup_chrootdir
+
+before() {
+ _before libremakepkg
+
+ mkdir -p "$XDG_CONFIG_HOME"/libretools
+
+ echo "BLACKLIST=https://repo.parabola.nu/docs/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
+}
+
+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_enables_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
+ testsudo libremakepkg -l "$roundup_test_name"
+ [[ -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"
+
+ libremakepkg >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
diff --git a/test/libremakepkg.d/PKGBUILD-hello b/test/libremakepkg.d/PKGBUILD-hello
new file mode 100644
index 0000000..5f320fe
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-hello
@@ -0,0 +1,19 @@
+pkgname='libretools-hello'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+depends=(sh)
+
+build() {
+ cd "$srcdir"
+ echo '#!/bin/sh' > hello.sh
+ echo 'echo Hello, world!' >> hello.sh
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm755 hello.sh "$pkgdir"/usr/bin/libretools-hello
+}
diff --git a/test/libremakepkg.d/PKGBUILD-netbuild b/test/libremakepkg.d/PKGBUILD-netbuild
new file mode 100644
index 0000000..4db1274
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-netbuild
@@ -0,0 +1,17 @@
+pkgname='libretools-netbuild'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+
+build() {
+ cd "$srcdir"
+ curl https://repo.parabola.nu/ > index.html
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm644 index.html "$pkgdir"/usr/share/$pkgname/index.html
+}
diff --git a/test/libremakepkg.d/PKGBUILD-netpackage b/test/libremakepkg.d/PKGBUILD-netpackage
new file mode 100644
index 0000000..6cadcf8
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-netpackage
@@ -0,0 +1,12 @@
+pkgname='libretools-netpackage'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+
+package() {
+ install -d "$pkgdir"/usr/share/$pkgname
+ curl https://repo.parabola.nu/ > "$pkgdir"/usr/share/$pkgname/index.html
+}
diff --git a/test/libremakepkg.d/PKGBUILD-netprepare b/test/libremakepkg.d/PKGBUILD-netprepare
new file mode 100644
index 0000000..efb7a43
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-netprepare
@@ -0,0 +1,17 @@
+pkgname='libretools-netprepare'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+
+prepare() {
+ cd "$srcdir"
+ curl https://repo.parabola.nu/ > index.html
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm644 index.html "$pkgdir"/usr/share/$pkgname/index.html
+}
diff --git a/test/libremakepkg.d/PKGBUILD-testpkg1 b/test/libremakepkg.d/PKGBUILD-testpkg1
new file mode 100644
index 0000000..8da1f14
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-testpkg1
@@ -0,0 +1,19 @@
+pkgname='libretools-testpkg1'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+depends=(sh)
+
+build() {
+ cd "$srcdir"
+ echo '#!/bin/sh' > testpkg1.sh
+ echo 'echo testpkg1' >> testpkg1.sh
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm755 testpkg1.sh "$pkgdir"/usr/bin/libretools-testpkg1
+}
diff --git a/test/libremakepkg.d/PKGBUILD-testpkg2 b/test/libremakepkg.d/PKGBUILD-testpkg2
new file mode 100644
index 0000000..65d558e
--- /dev/null
+++ b/test/libremakepkg.d/PKGBUILD-testpkg2
@@ -0,0 +1,19 @@
+pkgname='libretools-testpkg2'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+depends=(sh libretools-testpkg1)
+
+build() {
+ cd "$srcdir"
+ echo '#!/bin/sh' > testpkg2.sh
+ echo 'libretools-testpkg1' >> testpkg2.sh
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm755 testpkg2.sh "$pkgdir"/usr/bin/libretools-testpkg2
+}
diff --git a/test/librerelease-test.sh b/test/librerelease-test.sh
new file mode 100644
index 0000000..a44b150
--- /dev/null
+++ b/test/librerelease-test.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env roundup
+
+describe librestage
+
+. ./test-common.sh
+
+before() {
+ _before
+
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ {
+ echo "WORKDIR='$tmpdir/workdir'"
+ echo 'REPODEST=repo@repo:/srv/http/repo/staging-$LIBREUSER'
+ } >$XDG_CONFIG_HOME/libretools/libretools.conf
+ {
+ echo 'PKGEXT=.pkg.tar.gz'
+ echo "PKGDEST='$tmpdir/workdir/pkgdest'"
+ echo "GPGKEY=YOURKEY"
+ } > $HOME/.makepkg.conf
+ 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"
+
+ [[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]]
+ empty "$tmpdir/stderr"
+}
+
+it_lists_all_files() {
+ WORKDIR="$tmpdir/workdir"
+ mkdir -p "$WORKDIR/staging/repo1" "$WORKDIR/staging/repo2/sub"
+ touch \
+ "$WORKDIR/staging/repo1/file1" \
+ "$WORKDIR/staging/repo1/file2" \
+ "$WORKDIR/staging/repo2/file with spaces" \
+ "$WORKDIR/staging/repo2/sub/subfolder"
+ unset WORKDIR
+ LC_ALL=C librerelease -l &>"$tmpdir/list"
+
+ cat > "$tmpdir/list-correct" <<EOF
+ -> repo1
+ file1
+ file2
+ -> repo2
+ file with spaces
+ sub/subfolder
+EOF
+
+ diff "$tmpdir/list-correct" "$tmpdir/list"
+}
diff --git a/test/librestage-test.sh b/test/librestage-test.sh
new file mode 100644
index 0000000..affad6a
--- /dev/null
+++ b/test/librestage-test.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env roundup
+
+describe librestage
+
+. ./test-common.sh
+
+before() {
+ _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
+
+ mkdir -p $XDG_CONFIG_HOME/xbs
+ echo "BUILDSYSTEM=abslibre" > $XDG_CONFIG_HOME/xbs/xbs.conf
+
+ echo 'PKGEXT=.pkg.tar.gz' > $HOME/.makepkg.conf
+ echo "PKGDEST='$tmpdir/workdir/pkgdest'" >> $HOME/.makepkg.conf
+ echo "PACKAGER='Test Suite <test@localhost>'" >> $HOME/.makepkg.conf
+ 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
+
+ [[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]]
+ empty "$tmpdir/stderr"
+}
+
+it_fails_with_0_args() {
+ librestage >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty "$tmpdir/stdout"
+ not empty "$tmpdir/stderr"
+}
+
+it_fails_with_invalid_args() {
+ librestage -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ empty "$tmpdir/stdout"
+ not empty "$tmpdir/stderr"
+}
+
+it_guesses_the_repo() {
+ mkdir -p -- "$tmpdir/reponame/libretools-hello"
+ cp librestage.d/PKGBUILD-hello "$tmpdir/reponame/libretools-hello/PKGBUILD"
+ cd "$tmpdir/reponame/libretools-hello"
+
+ makepkg
+ librestage
+
+ [[ -f $tmpdir/workdir/staging/reponame/libretools-hello-1.0-1-any.pkg.tar.gz ]]
+}
+
+it_stages_packages_without_PKGDEST() {
+ echo "PKGDEST=''" >> $HOME/.makepkg.conf
+
+ cp librestage.d/PKGBUILD-hello "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+
+ makepkg
+ librestage repo1
+
+ [[ -f $tmpdir/workdir/staging/repo1/libretools-hello-1.0-1-any.pkg.tar.gz ]]
+}
diff --git a/test/librestage.d/PKGBUILD-hello b/test/librestage.d/PKGBUILD-hello
new file mode 100644
index 0000000..5f320fe
--- /dev/null
+++ b/test/librestage.d/PKGBUILD-hello
@@ -0,0 +1,19 @@
+pkgname='libretools-hello'
+pkgver=1.0
+license=('GPL')
+url='https://parabola.nu'
+
+pkgrel=1
+arch=(any)
+depends=(sh)
+
+build() {
+ cd "$srcdir"
+ echo '#!/bin/sh' > hello.sh
+ echo 'echo Hello, world!' >> hello.sh
+}
+
+package() {
+ cd "$srcdir"
+ install -Dm755 hello.sh "$pkgdir"/usr/bin/libretools-hello
+}
diff --git a/test/pkgbuild-check-nonfree-test.sh b/test/pkgbuild-check-nonfree-test.sh
new file mode 100644
index 0000000..2af2669
--- /dev/null
+++ b/test/pkgbuild-check-nonfree-test.sh
@@ -0,0 +1,78 @@
+#!/usr/bin/env roundup
+
+# avoid carpel tunnel
+pcn=pkgbuild-check-nonfree
+psn=pkgbuild-summarize-nonfree
+
+describe $pcn
+
+. ./test-common.sh
+
+before() {
+ _before
+
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
+
+ local blacklist=$XDG_CACHE_HOME/libretools/blacklist.txt
+ mkdir -p "${blacklist%/*}"
+ echo 'linux:linux-libre:nonfree blobs and firmwares' >$blacklist
+ 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.
+ LC_ALL=C $pcn -h >$tmpdir/stdout 2>$tmpdir/stderr
+ stat=$?
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+ [[ $stat == 0 ]]
+}
+
+it_succeeds_for_free_depends() {
+ $pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+ [[ $stat == 0 ]]
+}
+
+it_succeeds_for_nonfree_depend_with_replacement() {
+ $pcn $pcn.d/PKGBUILD.nonfree-replacement >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+ [[ $stat == 0 ]]
+}
+
+it_fails_for_nonfree_depend() {
+ $pcn $pcn.d/PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+
+ local pcn_stat=$stat
+
+ $psn $pcn_stat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ [[ $stat != 0 ]]
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+}
+
+it_fails_when_there_is_no_blacklist() {
+ mkdir -p $XDG_CONFIG_HOME/libretools
+ echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
+ rm $XDG_CACHE_HOME/libretools/blacklist.txt
+
+ $pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ empty $tmpdir/stdout
+ not empty $tmpdir/stderr
+ [[ $stat != 0 ]] && [[ $stat != 15 ]]
+}
diff --git a/test/pkgbuild-check-nonfree.d/PKGBUILD.free b/test/pkgbuild-check-nonfree.d/PKGBUILD.free
new file mode 100644
index 0000000..4b8f0dd
--- /dev/null
+++ b/test/pkgbuild-check-nonfree.d/PKGBUILD.free
@@ -0,0 +1,18 @@
+pkgname=wmii
+pkgver=3.9.2
+pkgrel=3
+pkgdesc="A small, dynamic window manager for X11"
+arch=('i686' 'x86_64')
+license=('MIT')
+url="http://wmii.suckless.org/"
+depends=('libxft' 'libxrandr' 'libxinerama' 'dash')
+source=()
+md5sums=()
+
+build() {
+ :
+}
+
+package() {
+ :
+}
diff --git a/test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree b/test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree
new file mode 100644
index 0000000..3a7afa4
--- /dev/null
+++ b/test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree
@@ -0,0 +1,18 @@
+pkgname=wmii
+pkgver=3.9.2
+pkgrel=3
+pkgdesc="A small, dynamic window manager for X11"
+arch=('i686' 'x86_64')
+license=('MIT')
+url="http://wmii.suckless.org/"
+depends=('skype') # random non-free package with no other information
+source=()
+md5sums=()
+
+build() {
+ :
+}
+
+package() {
+ :
+}
diff --git a/test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree-replacement b/test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree-replacement
new file mode 100644
index 0000000..7855bdc
--- /dev/null
+++ b/test/pkgbuild-check-nonfree.d/PKGBUILD.nonfree-replacement
@@ -0,0 +1,18 @@
+pkgname=wmii
+pkgver=3.9.2
+pkgrel=3
+pkgdesc="A small, dynamic window manager for X11"
+arch=('i686' 'x86_64')
+license=('MIT')
+url="http://wmii.suckless.org/"
+depends=('linux') # random non-free package with a replacement
+source=()
+md5sums=()
+
+build() {
+ :
+}
+
+package() {
+ :
+}
diff --git a/test/test-common.sh b/test/test-common.sh
new file mode 100644
index 0000000..2a8fc37
--- /dev/null
+++ b/test/test-common.sh
@@ -0,0 +1,78 @@
+#!/hint/bash
+
+if [[ $HOME == "$(eval echo ~$USER)" ]]; then
+ libremessages error "\$HOME is the default for %s; use testenv: %s" "$USER" "$HOME"
+ exit 1
+fi
+
+_before() {
+ unset PKGDEST SRCDEST SRCPKGDEST LOGDEST
+ unset BUILDDIR
+ unset PKGEXT SRCEXT
+ unset GPGKEY PACKAGER
+ tmpdir="$(mktemp -d --tmpdir "test-${roundup_desc//\//-}.XXXXXXXXXXXX")"
+ chmod 755 "$tmpdir"
+ stat=0
+}
+
+_after() {
+ rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
+}
+
+_after_sudo() {
+ if [[ $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() {
+ 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=()
+ if libremessages in_array "network" "$@" && ! [[ $NETWORK ]]; then
+ missing+=('networking')
+ fi
+ if libremessages in_array "sudo" "$@" && ! [[ $SUDO ]]; then
+ missing+=('sudo')
+ fi
+ if (( ${#missing[@]} )); then
+ libremessages warning "Next test requires %s; Skipping (passing)..." "$(echo "${missing[*]}"|sed 's/ /, /g')" &>/dev/tty
+ return 1
+ fi
+ return 0;
+)
+
+empty() (
+ set +x
+ [[ $(stat -c %s "$1") -eq 0 ]]
+)
+
+# Just using '!' doesn't trip `set -e`
+not() (
+ set +x
+ ! eval "$@"
+)
diff --git a/test/testenv b/test/testenv
new file mode 100755
index 0000000..7072326
--- /dev/null
+++ b/test/testenv
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+
+# Parse the arguments
+NETWORK=true
+SUDO=true
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --no-network) shift; unset NETWORK;;
+ --network) shift; NETWORK=true;;
+ --no-sudo) shift; unset SUDO;;
+ --sudo) shift; SUDO=true;;
+ --) shift; break;;
+ *) break;;
+ esac
+done
+export NETWORK SUDO
+
+if [[ $# == 0 ]]; then
+ echo 'You need to run testenv with arguments!' >&2
+ exit 1
+fi
+
+# Set up the working directory, and add the hook to clean it up
+export TMPDIR="$(mktemp --tmpdir -d libretools-test.XXXXXXXXXX)"
+trap "rm -rf '$TMPDIR'" EXIT
+
+# Set up the install to work with
+destdir=$TMPDIR/destdir
+
+old_pwd="$(pwd)"
+if [[ -f $0 ]]; then
+ cd "${0%/*}"
+fi
+if ! make -C .. install DESTDIR="$destdir" &>"$TMPDIR/make-output"; then
+ echo 'error creating local install, cannot run tests' >&2
+ cat "$TMPDIR/make-output"
+ exit 1
+fi
+cd "$old_pwd"
+
+# Set up the environment
+export PATH="$destdir/usr/bin:$PATH"
+export LIBRETOOLS_LIBDIR="$destdir/usr/lib/libretools"
+export XBS_LIBDIR="$destdir/usr/lib/xbs"
+export HOME=$TMPDIR/home
+export XDG_CACHE_HOME="$HOME/.cache"
+export XDG_CONFIG_HOME="$HOME/.config"
+export _librelib_conf_sh_sysconfdir="$destdir/etc"
+export _librelib_conf_sh_pkgconfdir="$destdir/etc/libretools.d"
+
+# Hack to respect our variables in sudo
+_sudo() {
+ local vars=(TMPDIR PATH LIBRETOOLS_LIBDIR XDG_CACHE_HOME XDG_CONFIG_HOME _librelib_conf_sh_sysconfdir)
+ local args=()
+ local var
+ for var in "${vars[@]}"; do
+ args+=("$var=${!var}")
+ done
+ sudo env "${args[@]}" "$@"
+}
+printf '%s\n' \
+ '#!/bin/bash' \
+ "$(declare -f _sudo)" \
+ '_sudo "$@"' \
+ > "$destdir/usr/bin/testsudo"
+chmod 755 "$destdir/usr/bin/testsudo"
+
+# Run the tests
+eval "$@"