From 8e5744170c30d50ef1f3e3a3e52c595870c6e50a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 1 Jun 2013 19:23:19 -0600 Subject: librestage: clean up, add unit tests Contained the text "# TODO refactor this", and I can't just stick to that fragment of code, can I? I actually didn't change too much, despite what the diff looks like. - move everything into a main() routine - redo the usage() text - rename a few variables - fix where "${#repos}" should have been "${#repos[@]}" - use [[...]] instead of [...] - use "if A; then B; else C; fi" instead of "A || C && B" - use CARCH instead of looping over every possible architecture. - only look for files that match PKGEXT, as set in makepkg.conf - pull out duplicate code for error handling - don't warn when creating "staging/REPONAME" --- test/librestage-test.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/librestage-test.sh (limited to 'test/librestage-test.sh') diff --git a/test/librestage-test.sh b/test/librestage-test.sh new file mode 100644 index 0000000..83194b5 --- /dev/null +++ b/test/librestage-test.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env roundup + +describe librestage + + +before() { + tmpdir=$(mktemp -d --tmpdir test-librestage.XXXXXXXXXXXX) + stat=0 + + mkdir -p $XDG_CONFIG_HOME/libretools + echo "WORKDIR='$tmpdir/workdir'" >$XDG_CONFIG_HOME/libretools/libretools.conf + + export HOME=$XDG_CONFIG_HOME + echo 'PKGEXT=.pkg.tar.gz' > $HOME/.makepkg.conf + echo "PKGDEST='$tmpdir/workdir/pkgdest'" >> $HOME/.makepkg.conf + mkdir -p "$tmpdir/workdir/pkgdest" +} + +after() { + rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" +} + +it_displays_usage_text() { + librestage -h >$tmpdir/stdout 2>$tmpdir/stderr + + [[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]] + [[ -z "$(cat "$tmpdir/stderr")" ]] +} + +it_fails_with_0_args() { + librestage >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat "$tmpdir/stdout")" ]] + [[ -n "$(cat "$tmpdir/stderr")" ]] +} + +it_fails_with_invalid_args() { + librestage -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ -z "$(cat "$tmpdir/stdout")" ]] + [[ -n "$(cat "$tmpdir/stderr")" ]] +} + +# This was an actual bug I hit with md/emacs-mdmua a long time ago; solution was +# to use $(get_full_version) +it_stages_split_packages_with_different_versions() { + cp librestage.d/PKGBUILD-split "$tmpdir/PKGBUILD" + cd "$tmpdir" + + makepkg + librestage '~lukeshu' + + # peak at the PKGBUILD to get this info + [[ -f $tmpdir/workdir/staging/~lukeshu/md-0.81-4-any.pkg.tar.gz ]] + [[ -f $tmpdir/workdir/staging/~lukeshu/emacs-mdmua-0.72-4-any.pkg.tar.gz ]] +} + +it_stages_packages_to_multiple_repos() { + cp librestage.d/PKGBUILD-hello "$tmpdir/PKGBUILD" + cd "$tmpdir" + + makepkg + librestage repo1 repo2 repo3 + + [[ -f $tmpdir/workdir/staging/repo1/libretools-hello-1.0-1-any.pkg.tar.gz ]] + [[ -f $tmpdir/workdir/staging/repo2/libretools-hello-1.0-1-any.pkg.tar.gz ]] + [[ -f $tmpdir/workdir/staging/repo3/libretools-hello-1.0-1-any.pkg.tar.gz ]] +} -- cgit v1.2.2