diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-09-30 00:27:23 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-10-01 17:35:22 -0400 |
commit | 4014f6c2cc579645aac56f51aa6063db7815c3a8 (patch) | |
tree | 549afea90ba2a0283c1507cd276a28d3e4fb243a | |
parent | 61e61226d8aeb2a973656a263cd0c523e9e55c88 (diff) |
test: Clean up (config) file writing
Instead of using in inconsistent mish-mash of `mkdir` and `echo >` and
`printf >>`, use more readable and identifiable indented-heredocs:
install -Dm644 /dev/stdin "FILENAME" <<-eot
CONTENTS
eot
-rwxr-xr-x | test/lib-blacklist-test.sh | 30 | ||||
-rw-r--r-- | test/lib-messages-test.sh | 11 | ||||
-rw-r--r-- | test/libredbdiff-test.sh | 13 | ||||
-rw-r--r-- | test/librefetch-test.sh | 33 | ||||
-rw-r--r-- | test/libremakepkg-test.sh | 17 | ||||
-rw-r--r-- | test/librerelease-test.sh | 36 | ||||
-rw-r--r-- | test/librestage-test.sh | 22 | ||||
-rw-r--r-- | test/pkgbuild-check-nonfree-test.sh | 15 | ||||
-rwxr-xr-x | test/test-common.sh | 15 | ||||
-rw-r--r-- | test/toru-path-test.sh | 20 |
10 files changed, 115 insertions, 97 deletions
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh index 742f1c2..920e99d 100755 --- a/test/lib-blacklist-test.sh +++ b/test/lib-blacklist-test.sh @@ -51,8 +51,9 @@ it_prints_urls_only_for_valid_references() { } 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 + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST='phony://example.com' + eot libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || status=$? @@ -62,8 +63,9 @@ it_fails_update_with_no_blacklist_or_network() { } 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 + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST='phony://example.com' + eot libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || status=$? @@ -73,8 +75,9 @@ it_fails_cat_with_no_blacklist_or_network() { } it_fails_update_when_BLACKLIST_is_unset() { - mkdir -p $XDG_CONFIG_HOME/libretools - echo "BLACKLIST=" >$XDG_CONFIG_HOME/libretools/libretools.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST= + eot libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || status=$? @@ -84,9 +87,10 @@ it_fails_update_when_BLACKLIST_is_unset() { } 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 + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST='${_blacklist_url@Q} + eot libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || status=$? @@ -97,8 +101,9 @@ it_fails_cat_when_syntax_error_in_conf() { 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 + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST=${_blacklist_url@Q} + eot libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr @@ -107,8 +112,9 @@ it_downloads_the_blacklist_as_needed() { 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 + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST=${_blacklist_url@Q} + eot libreblacklist update libreblacklist update diff --git a/test/lib-messages-test.sh b/test/lib-messages-test.sh index d5cde09..d0b4497 100644 --- a/test/lib-messages-test.sh +++ b/test/lib-messages-test.sh @@ -45,11 +45,12 @@ it_allows_subheadings_to_flag() { -b bdesc \ Head1: \ -c cdesc > $tmpdir/out - printf '%s\n' \ - ' -a adesc' \ - ' -b bdesc' \ - ' Head1:' \ - ' -c cdesc' > $tmpdir/exp + cat > $tmpdir/exp <<-eot + -a adesc + -b bdesc + Head1: + -c cdesc + eot diff -u $tmpdir/exp $tmpdir/out } diff --git a/test/libredbdiff-test.sh b/test/libredbdiff-test.sh index 8c2f6e3..6cebbf6 100644 --- a/test/libredbdiff-test.sh +++ b/test/libredbdiff-test.sh @@ -6,13 +6,12 @@ describe libredbdiff before() { common_before - mkdir -p "$XDG_CONFIG_HOME/libretools" - printf '%s\n' \ - 'statedir="$PWD"' \ - "mirror_prbl='https://repo.parabola.nu/\$repo/os/\$arch'" \ - "mirror_arch='https://mirrors.kernel.org/archlinux/\$repo/os/\$arch'" \ - 'repos=(libre)' \ - > $XDG_CONFIG_HOME/libretools/libredbdiff.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libredbdiff.conf" <<-'eot' + statedir="$PWD" + mirror_prbl='https://repo.parabola.nu/$repo/os/$arch' + mirror_arch='https://mirrors.kernel.org/archlinux/$repo/os/$arch' + repos=(libre) + eot } it_displays_help() { diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh index 5ee5ba3..8cc7281 100644 --- a/test/librefetch-test.sh +++ b/test/librefetch-test.sh @@ -6,25 +6,24 @@ describe librefetch before() { common_before - mkdir -p "$XDG_CONFIG_HOME"/{pacman,libretools} "$tmpdir/workdir/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/workdir/srcdest -source ${_librelib_conf_sh_sysconfdir}/makepkg.d/librefetch.conf -EOF - + mkdir -p "$tmpdir/workdir/srcdest" + + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot + 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@Q}/workdir/srcdest + source ${_librelib_conf_sh_sysconfdir@Q}/makepkg.d/librefetch.conf + eot 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" + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/librefetch.conf" <<-eot + MIRRORS=("phony://example.com/dir/") + DOWNLOADER=/usr/bin/false + eot } it_displays_help() { diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh index ce3aa80..a1955bc 100644 --- a/test/libremakepkg-test.sh +++ b/test/libremakepkg-test.sh @@ -136,7 +136,9 @@ it_detects_distcc_files() { cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" - echo "CHROOTEXTRAPKG+=(distcc-nozeroconf socat)" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf + cat >> "$XDG_CONFIG_HOME/libretools/chroot.conf" <<-eot + CHROOTEXTRAPKG+=(distcc-nozeroconf socat) + eot trap 'sed -i /CHROOTEXTRAPKGs+=/d "$XDG_CONFIG_HOME"/libretools/chroot.conf' RETURN libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty testsudo librechroot -l "$roundup_test_name" install-name distcc-nozeroconf socat @@ -156,12 +158,13 @@ it_detects_distcc_files() { it_doesnt_symlink_outputs() { require network sudo || return 0 - echo "WORKDIR='$tmpdir/workdir'" > $XDG_CONFIG_HOME/libretools/libretools.conf - mkdir -p $XDG_CONFIG_HOME/pacman - { - printf 'PKGDEST=%q\n' "$tmpdir/workdir/pkgdest" - printf 'SRCPKGDEST=%q\n' "$tmpdir/workdir/srcpkgdest" - } >$XDG_CONFIG_HOME/pacman/makepkg.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + WORKDIR=${tmpdir@Q}/workdir + eot + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot + PKGDEST=${tmpdir@Q}/workdir/pkgdest + SRCPKGDEST=${tmpdir@Q}/workdir/srcpkgdest + eot trap 'rm -f -- "$XDG_CONFIG_HOME/libretools/libretools.conf" "$XDG_CONFIG_HOME/pacman/makepkg.conf"' RETURN cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD" diff --git a/test/librerelease-test.sh b/test/librerelease-test.sh index b8e6e75..58089f4 100644 --- a/test/librerelease-test.sh +++ b/test/librerelease-test.sh @@ -6,17 +6,15 @@ describe librerelease before() { common_before - mkdir -p $XDG_CONFIG_HOME/libretools - { - echo "WORKDIR='$tmpdir/workdir'" - echo 'REPODEST=ssh://repo@repo.parabola.nu:1863/~/staging/$LIBREUSER/staging/' - } >$XDG_CONFIG_HOME/libretools/libretools.conf - mkdir -p $XDG_CONFIG_HOME/pacman - { - echo 'PKGEXT=.pkg.tar.gz' - echo "PKGDEST='$tmpdir/workdir/pkgdest'" - echo "GPGKEY=YOURKEY" - } >$XDG_CONFIG_HOME/pacman/makepkg.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + WORKDIR=${tmpdir@Q}/workdir + REPODEST=ssh://repo@repo.parabola.nu:1863/~/staging/$LIBREUSER/staging/ + eot + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot + PKGEXT=.pkg.tar.gz + PKGDEST=${tmpdir@Q}/workdir/pkgdest + GPGKEY=YOURKEY + eot mkdir -p "$tmpdir/workdir/pkgdest" } @@ -39,14 +37,14 @@ it_lists_all_files() { unset WORKDIR LC_ALL=C librerelease -l &>"$tmpdir/list" - cat > "$tmpdir/list-correct" <<EOF - -> repo1 - file1 - file2 - -> repo2 - file with spaces - sub/subfolder -EOF + cat > "$tmpdir/list-correct" <<-eot + -> repo1 + file1 + file2 + -> repo2 + file with spaces + sub/subfolder + eot diff "$tmpdir/list-correct" "$tmpdir/list" } diff --git a/test/librestage-test.sh b/test/librestage-test.sh index 8caf5d6..4f617ca 100644 --- a/test/librestage-test.sh +++ b/test/librestage-test.sh @@ -6,15 +6,15 @@ describe librestage before() { common_before - mkdir -p $XDG_CONFIG_HOME/libretools - echo "WORKDIR='$tmpdir/workdir'" > $XDG_CONFIG_HOME/libretools/libretools.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + WORKDIR=${tmpdir@Q}/workdir + eot - mkdir -p $XDG_CONFIG_HOME/pacman - { - printf 'PKGDEST=%q\n' "$tmpdir/workdir/pkgdest" - printf 'SRCPKGDEST=%q\n' "$tmpdir/workdir/srcpkgdest" - echo "PACKAGER='Test Suite <test@localhost>'" - } >$XDG_CONFIG_HOME/pacman/makepkg.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot + PKGDEST=${tmpdir@Q}/workdir/pkgdest + SRCPKGDEST=${tmpdir@Q}/workdir/srcpkgdest + PACKAGER='Test Suite <test@localhost>' + eot mkdir -p "$tmpdir/workdir/pkgdest" mkdir -p "$tmpdir/workdir/srcpkgdest" @@ -66,8 +66,10 @@ it_guesses_the_repo() { it_stages_packages_without_PKGDEST() { nochroot=false; require network sudo || nochroot=true - echo "PKGDEST=''" >> $XDG_CONFIG_HOME/pacman/makepkg.conf - echo "SRCPKGDEST=''" >> $XDG_CONFIG_HOME/pacman/makepkg.conf + cat >> "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot + PKGDEST='' + SRCPKGDEST='' + eot cp librestage.d/PKGBUILD-hello "$tmpdir/PKGBUILD" cd "$tmpdir" diff --git a/test/pkgbuild-check-nonfree-test.sh b/test/pkgbuild-check-nonfree-test.sh index 306ab00..ec1246e 100644 --- a/test/pkgbuild-check-nonfree-test.sh +++ b/test/pkgbuild-check-nonfree-test.sh @@ -6,13 +6,14 @@ describe pkgbuild-check-nonfree before() { common_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 + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + BLACKLIST='phony://example.com' + eot + + install -Dm644 /dev/stdin "$XDG_CACHE_HOME/libretools/blacklist.txt" <<-eot + linux:linux-libre:nonfree blobs and firmwares + skype + eot } it_displays_usage_text() { diff --git a/test/test-common.sh b/test/test-common.sh index 478694c..64ff660 100755 --- a/test/test-common.sh +++ b/test/test-common.sh @@ -39,13 +39,14 @@ common_before() { # Configure libretools export chrootdir="${chrootdir:-$TMPDIR/chroots}" - mkdir -p "$XDG_CONFIG_HOME"/libretools - - echo "BLACKLIST=https://git.parabola.nu/blacklist.git/plain/blacklist.txt" >"$XDG_CONFIG_HOME"/libretools/libretools.conf - - printf 'CHROOTDIR=%q\n' "${chrootdir}" > "$XDG_CONFIG_HOME"/libretools/chroot.conf - printf 'CHROOT=%q\n' default >> "$XDG_CONFIG_HOME"/libretools/chroot.conf - echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME"/libretools/libretools.conf <<-eot + BLACKLIST=https://git.parabola.nu/blacklist.git/plain/blacklist.txt + eot + install -Dm644 /dev/stdin "$XDG_CONFIG_HOME"/libretools/chroot.conf <<-eot + CHROOTDIR=${chrootdir@Q} + CHROOT=default + CHROOTEXTRAPKG=() + eot } common_after() { diff --git a/test/toru-path-test.sh b/test/toru-path-test.sh index 86571be..1feb341 100644 --- a/test/toru-path-test.sh +++ b/test/toru-path-test.sh @@ -12,9 +12,13 @@ it_displays_help() { it_runs() { mkdir -p "$XDG_CONFIG_HOME"/libretools - printf 'TORUPATH=%q\n' "$tmpdir" >> "$XDG_CONFIG_HOME"/libretools/libretools.conf - echo 'REPOS=(libre)' >> "$XDG_CONFIG_HOME"/libretools/libretools.conf - printf 'ABSROOT=%q\n' "$PWD/toru.d" >> "$HOME"/.abs.conf + cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + TORUPATH=${tmpdir@Q} + REPOS=(libre) + eot + cat >> "$HOME/.abs.conf" <<-eot + ABSROOT=${PWD@Q}/toru.d + eot toru-path @@ -39,9 +43,13 @@ it_runs() { it_sets_torupath() { mkdir -p "$XDG_CONFIG_HOME"/libretools - printf 'TORUPATH=%q\n' "$tmpdir" >> "$XDG_CONFIG_HOME"/libretools/libretools.conf - echo 'REPOS=(libre)' >> "$XDG_CONFIG_HOME"/libretools/libretools.conf - printf 'ABSROOT=%q\n' "$PWD/toru.d" >> "$HOME"/.abs.conf + cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot + TORUPATH=${tmpdir@Q} + REPOS=(libre) + eot + cat >> "$HOME/.abs.conf" <<-eot + ABSROOT=${PWD@Q}/toru.d + eot mkdir -p "$tmpdir/x" T="$tmpdir/x" toru-path |