]> pd.if.org Git - zpackage/blobdiff - t/install.t
rework zpm-add
[zpackage] / t / install.t
index 6631ddfa04a84b681e312b54e20f7451a83698b7..e9c05aa18d1e94de73580fd07cb81c595b42a4f0 100755 (executable)
@@ -6,22 +6,39 @@
 
 . tap.sh
 
-plan 31
+plan 67
+
+owner=$(id -un)
+group=$(id -gn)
 
 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
+               tryrun zpm newpackage -f $pkgid.zpm $pkgid
+               if [ $? -eq 0 ]; then
+                       shift
+                       tryrun zpm add -u $owner -g $group -f $pkgid.zpm -p $pkgid "$@"
+                       return $?
+               else
+                       skip 1 not adding files init failed
+                       return 1
+               fi
+       else
+               skip 2 "unable to init $pkgid.zpm"
        fi
        return 0
 }
 
+oktest() {
+       test $1 $2
+       okexit test $1 $2
+}
+
+oknottest() {
+       test $1 $2
+       failsok test $1 $2 fails
+}
 
 require rm -rf tmp
 require mkdir tmp
@@ -36,14 +53,14 @@ PF=$pkgid.zpm
 
 #require zpm init $PF
 #require zpm newpackage -f $PF $pkgid
-#require zpm add -f $PF $pkgid /bin/true
+#require zpm add -f $PF -p $pkgid /bin/true
 
 #
-# install via pkgfiles
+# install via syncfs
 #
 require zpm pkg -f $PF $pkgid status=installing
-zpm pkgfiles -d $PF -R. $pkgid 2>&1
-okexit ran pkgfiles
+zpm syncfs -d $PF -R. $pkgid 2>&1 | diagstdin
+okexit ran syncfs
 
 test -f bin/true
 okexit bin/true installed
@@ -61,7 +78,7 @@ require rm -rf bin
 # 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 install -R. -d local.db -f $PF $pkgid 2>&1 | diagstdin
 #zpm list -f local.db -v | diagstdin
 okexit installed
 ns=$(zpm pkg -f local.db $pkgid status)
@@ -80,7 +97,7 @@ 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
+tryrun zpm add -f $PF -p itest /bin/false
 if [ $? -ne 0 ]; then
        diag h2
        cat test.out | diagstdin
@@ -88,7 +105,7 @@ if [ $? -ne 0 ]; then
        bailout add failed
 fi
 
-zpm install -R. -d local.db -f $PF itest-2.0-1
+zpm install -R. -d local.db -f $PF itest-2.0-1 2>&1 | diagstdin
 okexit installed
 if [ $? -ne 0 ]; then
        cat test.out | diagstdin
@@ -110,7 +127,7 @@ 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
+zpm install -R. -d local.db -f $PF $pkgid 2>&1 | diagstdin
 okexit upgraded to $pkgid
 
 ns=$(zpm pkg -f local.db $pkgid status)
@@ -119,6 +136,89 @@ okstreq "$ns" "installed" "install set $pkgid status"
 test -f bin/false
 failsok removed bin/false
 
+#
+# install second package
+#
+require ln bin/true bin/sh
+pkgid=second-1.0-1
+newpkg $pkgid bin/sh
+okexit setup package $pkgid
+require rm bin/sh
+PF=$pkgid.zpm
+zpm install -R. -d local.db -f $PF $pkgid 2>&1 | diagstdin
+okexit installed $pkgid
+oktest -f bin/sh
+
+#
+# update a file
+#
+ohash=$(zpm hash bin/true)
+require mv bin/true bin/save
+require sh -c 'echo false > bin/true'
+nhash=$(zpm hash bin/true)
+pkgid=itest-4.0-1
+newpkg $pkgid bin/true
+okexit setup package $pkgid
+require mv bin/save bin/true
+PF=$pkgid.zpm
+zpm install -R. -d local.db -f $PF $pkgid 2>&1 | diagstdin
+okexit installed $pkgid
+rhash=$(zpm hash bin/true)
+okstreq "$rhash" "$nhash" "updated bin/true"
+
+skiponfail() {
+       rv=$?
+       if [ $rv -ne 0 ]; then
+               skip "$1" "$2"
+               return 0
+       fi
+       return 1
+}
+
+#
+# package with passing pre-script
+#
+pkgid=third-1.0-1
+PF=$pkgid.zpm
+newpkg $pkgid /bin/echo
+skiponfail 3 "can't create $pkgid" || {
+       zpm script -s -f $PF -p pre-install $pkgid /bin/true
+       okexit "add true pre-install script to $pkgid"
+       skiponfail 2 "can't set $pkgid pre-install script" || {
+               tryrun zpm install -v -R. -d local.db -f $PF $pkgid
+               okexit installed $pkgid
+               oktest -f bin/echo
+       }
+}
+
+#
+# package with failing pre-script
+#
+pkgid=fourth-1.0-1
+PF=$pkgid.zpm
+newpkg $pkgid /bin/head
+skiponfail 3 "can't create $pkgid" || {
+       zpm script -s -f $PF -p pre-install $pkgid /bin/false
+       okexit "add false pre-install script to $pkgid"
+       skiponfail 1 "can't set $pkgid pre-install script" || {
+               zpm install -R. -d local.db -f $PF $pkgid 2>/dev/null
+               failsok failed to install $pkgid
+       }
+}
+
+tryrun zpm uninstall -R. -d local.db third-1.0-1
+test -f bin/echo
+failsok bin/echo removed
+
+pkgid=fifth-1.0-1
+PF=$pkgid.zpm
+newpkg $pkgid /bin/head
+#zpm list -f $PF 2>&1 | diagstdin
+skiponfail 1 "can't create $pkgid" || {
+       tryrun zpm install -R. -d local.db -f $PF 2>/dev/null
+       okexit "install with implicit package id"
+}
+
 cd .. || bailout
 require rm -rf tmp