From 4f60c538ec7111597176984e32d3996e4b5adb17 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Mon, 24 Sep 2018 08:12:56 +0000 Subject: [PATCH] add test file for install adjust tap.sh --- t/install.t | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ t/tap.sh | 25 +++++++++-- 2 files changed, 146 insertions(+), 4 deletions(-) create mode 100755 t/install.t diff --git a/t/install.t b/t/install.t new file mode 100755 index 0000000..6631ddf --- /dev/null +++ b/t/install.t @@ -0,0 +1,125 @@ +#!/bin/sh + +# vim: syn=sh + +# test addfile + +. tap.sh + +plan 31 + +newpkg() { + pkgid=$1 + tryrun zpm init $pkgid.zpm + tryrun zpm newpackage -f $pkgid.zpm $pkgid + if [ $? -eq 0 ]; then + shift + tryrun zpm add -f $pkgid.zpm $pkgid "$@" + else + skip 1 not adding files init failed + return 1 + fi + return 0 +} + + +require rm -rf tmp +require mkdir tmp +cd tmp || bailout + +# set up a new package + +pkgid=itest-1.0-1 +newpkg $pkgid /bin/true +okexit setup package $pkgid +PF=$pkgid.zpm + +#require zpm init $PF +#require zpm newpackage -f $PF $pkgid +#require zpm add -f $PF $pkgid /bin/true + +# +# install via pkgfiles +# +require zpm pkg -f $PF $pkgid status=installing +zpm pkgfiles -d $PF -R. $pkgid 2>&1 +okexit ran pkgfiles + +test -f bin/true +okexit bin/true installed + +require zpm pkg -f $PF $pkgid status=packaged +ns=$(zpm pkg -f $PF $pkgid status) +okstreq "$ns" "packaged" set package status + +require rm -rf bin + +# +# install via install +# + +# TODO should probably have merge set the status to merged by default + +require zpm init local.db +zpm install -R. -d local.db -f $PF $pkgid +#zpm list -f local.db -v | diagstdin +okexit installed +ns=$(zpm pkg -f local.db $pkgid status) +okstreq "$ns" "installed" "install set package status" + +test -f bin/true +okexit bin/true installed via zpm-install + +# +# upgrade package +# + +# update the package version +require zpm pkg -f $PF $pkgid version=2.0 +newver=$(zpm pkg -f $PF itest version) +okstreq "$newver" "2.0" "have updated version" + +rm -f test.out +tryrun zpm add -v -f $PF itest /bin/false +if [ $? -ne 0 ]; then + diag h2 + cat test.out | diagstdin + zpm list -f $PF | diagstdin + bailout add failed +fi + +zpm install -R. -d local.db -f $PF itest-2.0-1 +okexit installed +if [ $? -ne 0 ]; then + cat test.out | diagstdin + zpm list -f $PF | diagstdin + bailout add failed +fi +test -f bin/false +okexit bin/false installed via zpm-install + +ns=$(zpm pkg -f local.db $pkgid status) +okstreq "$ns" "updated" "install set $pkgid status" +ns=$(zpm pkg -f local.db itest-2.0-1 status) +okstreq "$ns" "installed" "install set itest-2.0-1 status" + +# +# upgrade package removing a file +# +pkgid=itest-3.0-1 +newpkg $pkgid /bin/true +okexit setup package $pkgid +PF=$pkgid.zpm +zpm install -R. -d local.db -f $PF $pkgid | diagstdin +okexit upgraded to $pkgid + +ns=$(zpm pkg -f local.db $pkgid status) +okstreq "$ns" "installed" "install set $pkgid status" + +test -f bin/false +failsok removed bin/false + +cd .. || bailout +require rm -rf tmp + +finish diff --git a/t/tap.sh b/t/tap.sh index 580fcbd..0d03831 100755 --- a/t/tap.sh +++ b/t/tap.sh @@ -7,23 +7,30 @@ tryrun() { note="$@" program=$1 shift - $program "$@" >> test.out 2>&1 - if [ $? -ne 0 ]; then + $program "$@" > test.out 2>&1 + rv=$? + if [ $rv -ne 0 ]; then printf 'not '; fi tn=$((tn + 1)) printf 'ok %d - %s %s\n' $tn $program "$*" + if [ $rv -ne 0 ]; then + cat test.out | diagstdin + fi + return $rv } require() { note="$*" program=$1 shift - $program "$@" >> test.out 2>&1 + $program "$@" > test.out 2>&1 rv=$? tn=$((tn + 1)) if [ $rv -ne 0 ]; then printf 'not ok %d - %s %s\n' $tn $program "$*" + cat test.out | diagstdin + rm test.out bailout "exit status $rv"; fi printf 'ok %d - %s %s\n' $tn $program "$*" @@ -75,7 +82,7 @@ exitwith() { note= if [ $rv -ne $1 ]; then printf 'not '; - note=$(printf '# got "%d" expected "%d"' "$rv" "$1") + note=$(printf 'got "%d" expected "%d"' "$rv" "$1") fi shift tn=$((tn + 1)) @@ -106,3 +113,13 @@ finish() { printf '1..%d\n' $tn fi } + +skip() { + tap_skipping=$1 + shift + while [ $tap_skipping -gt 0 ]; do + tn=$((tn + 1)) + tap_skipping=$((tap_skipping - 1)) + printf 'ok %d - skip %s\n' $tn "$*" + done +} -- 2.40.0