]> pd.if.org Git - zpackage/blob - t/pathmod.t
47575e6f6361bac2fcf99df7096fe1317686534a
[zpackage] / t / pathmod.t
1 #!/bin/sh
2
3 # vim: syn=sh
4
5 # test addfile
6
7 . tap.sh
8
9 plan 13
10
11 owner=$(id -un)
12 group=$(id -gn)
13
14 newpkg() {
15         pkgid=$1
16         tryrun zpm init $pkgid.zpm
17         if [ $? -eq 0 ]; then
18                 tryrun zpm newpackage -f $pkgid.zpm $pkgid
19                 if [ $? -eq 0 ]; then
20                         shift
21                         tryrun zpm add -u $owner -g $group -f $pkgid.zpm $pkgid "$@"
22                         return $?
23                 else
24                         skip 1 not adding files init failed
25                         return 1
26                 fi
27         else
28                 skip 2 "unable to init $pkgid.zpm"
29         fi
30         return 0
31 }
32
33 oktest() {
34         test $1 $2
35         okexit test $1 $2
36 }
37
38 oknottest() {
39         test $1 $2
40         failsok test $1 $2 fails
41 }
42
43 require rm -rf tmp
44 require mkdir tmp
45 cd tmp || bailout
46
47 # set up a new package
48
49 pkgid=pathmod-1.0-1
50 newpkg $pkgid /bin/true
51 okexit setup package $pkgid
52 PF=$pkgid.zpm
53
54 username=$(zpm pathmod -f $PF $pkgid /bin/true username)
55 okstreq "$username" "$owner" 'default owned by current user'
56 zpm pathmod -f $PF $pkgid /bin/true username=root
57 username=$(zpm pathmod -f $PF $pkgid /bin/true username)
58 okstreq "$username" root 'set username to root'
59 has=$(zpm contents -q -f $PF $pkgid : /bin/true)
60 okstreq "$has" /bin/true 'package has /bin/true'
61
62 zpm packagehash -qs -f $PF $pkgid
63 hash=$(zpm packagehash -f $PF $pkgid)
64 if [ -n "$hash" ]; then
65         pass 'packagehash set'
66         diag $hash
67 else
68         fail 'packagehash set'
69 fi
70
71 zpm pathmod -f $PF $pkgid /bin/true delete
72 zpm contents -q -f $PF $pkgid : /bin/true
73 has=$(zpm contents -q -f $PF $pkgid : /bin/true)
74 okstreq "$has" '' '/bin/true deleted'
75
76 hash=$(zpm packagehash -e -f $PF $pkgid)
77 if [ -z "$hash" ]; then
78         pass 'packagehash cleared'
79 else
80         fail 'packagehash cleared'
81         diag $hash
82 fi
83
84 cd .. || bailout
85 require rm -rf tmp