Mercurial > hg > toybox
comparison tests/chmod.test @ 1485:8700cbe1cb29 draft
Move testsuite out of scripts/test into its own top level tests directory, and make ctrl-c kill "make test" more reliably.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 20 Sep 2014 13:09:14 -0500 |
parents | scripts/test/chmod.test@5d51c5d6df72 |
children |
comparison
equal
deleted
inserted
replaced
1484:19435f12ec63 | 1485:8700cbe1cb29 |
---|---|
1 #!/bin/bash | |
2 | |
3 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com> | |
4 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> | |
5 | |
6 #testing "name" "command" "result" "infile" "stdin" | |
7 | |
8 PERM="---""--x""-w-""-wx""r--""r-x""rw-""rwx" | |
9 | |
10 num2perm() | |
11 { | |
12 for i in 0 1 2 | |
13 do | |
14 num=${1:$i:1} | |
15 printf "%s" ${PERM:$(($num*3)):3} | |
16 done | |
17 echo | |
18 } | |
19 | |
20 # Creating test files to test chmod command | |
21 mkdir dir | |
22 touch file | |
23 | |
24 # We don't need to test all 511 permissions | |
25 for u in 0 1 2 3 4 5 6 7 | |
26 do | |
27 for g in 0 3 6 | |
28 do | |
29 for o in 0 7 | |
30 do | |
31 if [ "$type" == file ] | |
32 then | |
33 type=dir | |
34 rm -rf "./$type" && mkdir $type | |
35 DASH=d | |
36 else | |
37 type=file | |
38 rm -f "./$type" && touch $type | |
39 DASH=- | |
40 fi | |
41 DASHES=$(num2perm $u$g$o) | |
42 testing "chmod $u$g$o $type" "chmod $u$g$o $type && | |
43 ls -ld $type | cut -d' ' -f 1 | cut -d. -f 1" "$DASH$DASHES\n" "" "" | |
44 done | |
45 done | |
46 done | |
47 | |
48 rm -rf dir file && mkdir dir && touch file | |
49 testing "chmod 750 dir 640 file" \ | |
50 "chmod 750 dir 640 file 2>/dev/null || | |
51 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x---\n-rwxr-x---\n" "" "" | |
52 | |
53 rm -rf dir file && mkdir dir && touch file | |
54 testing "chmod 666 dir file" \ | |
55 "chmod 666 dir file && | |
56 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-rw-rw-\n-rw-rw-rw-\n" "" "" | |
57 | |
58 rm -rf dir file && mkdir dir && touch file | |
59 testing "chmod 765 *" "chmod 765 * && | |
60 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrw-r-x\n-rwxrw-r-x\n" "" "" | |
61 | |
62 ##### u,g,o,a=r,w,x | |
63 rm -rf dir file && mkdir dir && touch file | |
64 testing "chmod u=r dir file" "chmod u=r dir file && | |
65 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r-xr-x\n-r--r--r--\n" "" "" | |
66 | |
67 rm -rf dir file && mkdir dir && touch file | |
68 testing "chmod u=w dir file" "chmod u=w dir file && | |
69 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-r-xr-x\n--w-r--r--\n" "" "" | |
70 | |
71 rm -rf dir file && mkdir dir && touch file | |
72 testing "chmod u=x dir file" "chmod u=x dir file && | |
73 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--xr-xr-x\n---xr--r--\n" "" "" | |
74 | |
75 rm -rf dir file && mkdir dir && touch file | |
76 testing "chmod u+r dir file" "chmod u+r dir file && | |
77 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
78 | |
79 rm -rf dir file && mkdir dir && touch file | |
80 testing "chmod u+w dir file" "chmod u+w dir file && | |
81 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
82 | |
83 rm -rf dir file && mkdir dir && touch file | |
84 testing "chmod u+x dir file" "chmod u+x dir file && | |
85 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr--r--\n" "" "" | |
86 | |
87 rm -rf dir file && mkdir dir && touch file | |
88 testing "chmod u-r dir file" "chmod u-r dir file && | |
89 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wxr-xr-x\n--w-r--r--\n" "" "" | |
90 | |
91 rm -rf dir file && mkdir dir && touch file | |
92 testing "chmod u-w dir file" "chmod u-w dir file && | |
93 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" "" | |
94 | |
95 rm -rf dir file && mkdir dir && touch file | |
96 testing "chmod u-x dir file" "chmod u-x dir file && | |
97 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r-xr-x\n-rw-r--r--\n" "" "" | |
98 | |
99 rm -rf dir file && mkdir dir && touch file | |
100 testing "chmod g=r dir file" "chmod g=r dir file && | |
101 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" "" | |
102 | |
103 rm -rf dir file && mkdir dir && touch file | |
104 testing "chmod g=w dir file" "chmod g=w dir file && | |
105 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx-w-r-x\n-rw--w-r--\n" "" "" | |
106 | |
107 rm -rf dir file && mkdir dir && touch file | |
108 testing "chmod g=x dir file" "chmod g=x dir file && | |
109 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw---xr--\n" "" "" | |
110 | |
111 rm -rf dir file && mkdir dir && touch file | |
112 testing "chmod g+r dir file" "chmod g+r dir file && | |
113 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
114 | |
115 rm -rf dir file && mkdir dir && touch file | |
116 testing "chmod g+w dir file" "chmod g+w dir file && | |
117 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxr-x\n-rw-rw-r--\n" "" "" | |
118 | |
119 rm -rf dir file && mkdir dir && touch file | |
120 testing "chmod g+x dir file" "chmod g+x dir file && | |
121 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r-xr--\n" "" "" | |
122 | |
123 rm -rf dir file && mkdir dir && touch file | |
124 testing "chmod g-r dir file" "chmod g-r dir file && | |
125 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw----r--\n" "" "" | |
126 | |
127 rm -rf dir file && mkdir dir && touch file | |
128 testing "chmod g-w dir file" "chmod g-w dir file && | |
129 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
130 | |
131 rm -rf dir file && mkdir dir && touch file | |
132 testing "chmod g-x dir file" "chmod g-x dir file && | |
133 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" "" | |
134 | |
135 rm -rf dir file && mkdir dir && touch file | |
136 testing "chmod o=r dir file" "chmod o=r dir file && | |
137 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" "" | |
138 | |
139 rm -rf dir file && mkdir dir && touch file | |
140 testing "chmod o=w dir file" "chmod o=w dir file && | |
141 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x-w-\n-rw-r---w-\n" "" "" | |
142 | |
143 rm -rf dir file && mkdir dir && touch file | |
144 testing "chmod o=x dir file" "chmod o=x dir file && | |
145 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r----x\n" "" "" | |
146 | |
147 rm -rf dir file && mkdir dir && touch file | |
148 testing "chmod o+r dir file" "chmod o+r dir file && | |
149 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
150 | |
151 rm -rf dir file && mkdir dir && touch file | |
152 testing "chmod o+w dir file" "chmod o+w dir file && | |
153 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xrwx\n-rw-r--rw-\n" "" "" | |
154 | |
155 rm -rf dir file && mkdir dir && touch file | |
156 testing "chmod o+x dir file" "chmod o+x dir file && | |
157 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r-x\n" "" "" | |
158 | |
159 rm -rf dir file && mkdir dir && touch file | |
160 testing "chmod o-r dir file" "chmod o-r dir file && | |
161 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r-----\n" "" "" | |
162 | |
163 rm -rf dir file && mkdir dir && touch file | |
164 testing "chmod o-w dir file" "chmod o-w dir file && | |
165 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
166 | |
167 rm -rf dir file && mkdir dir && touch file | |
168 testing "chmod o-x dir file" "chmod o-x dir file && | |
169 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" "" | |
170 | |
171 rm -rf dir file && mkdir dir && touch file | |
172 testing "chmod a=r dir file" "chmod a=r dir file && | |
173 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" "" | |
174 | |
175 rm -rf dir file && mkdir dir && touch file | |
176 testing "chmod a=w dir file" "chmod a=w dir file && | |
177 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w--w--w-\n--w--w--w-\n" "" "" | |
178 | |
179 rm -rf dir file && mkdir dir && touch file | |
180 testing "chmod a=x dir file" "chmod a=x dir file && | |
181 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" "" | |
182 | |
183 rm -rf dir file && mkdir dir && touch file | |
184 testing "chmod a+r dir file" "chmod a+r dir file && | |
185 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
186 | |
187 rm -rf dir file && mkdir dir && touch file | |
188 testing "chmod a+w dir file" "chmod a+w dir file && | |
189 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxrwx\n-rw-rw-rw-\n" "" "" | |
190 | |
191 rm -rf dir file && mkdir dir && touch file | |
192 testing "chmod a+x dir file" "chmod a+x dir file && | |
193 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" "" | |
194 | |
195 rm -rf dir file && mkdir dir && touch file | |
196 testing "chmod a-r dir file" "chmod a-r dir file && | |
197 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" "" | |
198 | |
199 rm -rf dir file && mkdir dir && touch file | |
200 testing "chmod a-w dir file" "chmod a-w dir file && | |
201 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" "" | |
202 | |
203 rm -rf dir file && mkdir dir && touch file | |
204 testing "chmod a-x dir file" "chmod a-x dir file && | |
205 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" "" | |
206 | |
207 rm -rf dir file && mkdir dir && touch file | |
208 testing "chmod =r dir file" "chmod =r dir file && | |
209 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" "" | |
210 | |
211 rm -rf dir file && mkdir dir && touch file | |
212 testing "chmod =w dir file" "chmod =w dir file && | |
213 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-------\n--w-------\n" "" "" | |
214 | |
215 rm -rf dir file && mkdir dir && touch file | |
216 testing "chmod =x dir file" "chmod =x dir file && | |
217 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" "" | |
218 | |
219 rm -rf dir file && mkdir dir && touch file | |
220 testing "chmod +r dir file" "chmod +r dir file && | |
221 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
222 | |
223 rm -rf dir file && mkdir dir && touch file | |
224 testing "chmod +w dir file" "chmod +w dir file && | |
225 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" | |
226 | |
227 rm -rf dir file && mkdir dir && touch file | |
228 testing "chmod +x dir file" "chmod +x dir file && | |
229 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" "" | |
230 | |
231 rm -rf dir file && mkdir dir && touch file | |
232 testing "chmod -r dir file" "chmod -r dir file && | |
233 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" "" | |
234 | |
235 rm -rf dir file && mkdir dir && touch file | |
236 testing "chmod -w dir file" "chmod -w dir file && | |
237 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" "" | |
238 | |
239 rm -rf dir file && mkdir dir && touch file | |
240 testing "chmod -x dir file" "chmod -x dir file && | |
241 ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" "" | |
242 | |
243 # Removing test files for cleanup purpose | |
244 rm -rf dir file |