Mercurial > hg > toybox
annotate scripts/test/chgrp.test @ 672:9d5959d6885d
Test tweaks. Set +x on two scripts (so they can be run standalone), fix chgrp so it doesn't abort test all.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 07 Oct 2012 22:57:27 -0500 |
parents | cd4475a2efde |
children | 3d7526f6115b |
rev | line source |
---|---|
605 | 1 #!/bin/bash |
2 | |
3 [ -f testing.sh ] && . testing.sh | |
4 | |
5 VERBOSE=1 | |
6 | |
7 if [ "$(id -u)" -ne 0 ] | |
8 then | |
9 echo "SKIPPED: chgrp (not root)" | |
672
9d5959d6885d
Test tweaks. Set +x on two scripts (so they can be run standalone), fix chgrp so it doesn't abort test all.
Rob Landley <rob@landley.net>
parents:
605
diff
changeset
|
10 continue 2>/dev/null |
605 | 11 exit |
12 fi | |
13 | |
14 # We chgrp between "root" and the last group in /etc/group. | |
15 | |
16 GRP="$(sed -n '$s/:.*//p' /etc/group)" | |
17 | |
18 # Set up a little testing hierarchy | |
19 | |
20 rm -rf testdir && | |
21 mkdir -p testdir/dir/dir/dir testdir/dir2 && | |
22 touch testdir/dir/file && | |
23 ln -s ../dir/dir testdir/dir2/dir && | |
24 ln -s ../dir/file testdir/dir2/file || exit 1 | |
25 | |
26 # Wrapper to reset groups and return results | |
27 | |
28 IN="cd testdir && chgrp -R $GRP dir dir2 &&" | |
29 OUT="&& cd .. && echo \$(ls -lR testdir | awk '{print \$4}')" | |
30 | |
31 # The groups returned by $OUT are, in order: | |
32 # dir dir2 dir/dir dir/file dir/dir/dir dir2/dir dir2/file | |
33 | |
34 #testing "name" "command" "result" "infile" "stdin" | |
35 | |
36 # Basic smoketest | |
37 testing "chgrp dir" "$IN chgrp root dir $OUT" \ | |
38 "root $GRP $GRP $GRP $GRP $GRP $GRP\n" "" "" | |
39 testing "chgrp file" "$IN chgrp root dir/file $OUT" \ | |
40 "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" | |
41 testing "chgrp dir and file" "$IN chgrp root dir dir/file $OUT" \ | |
42 "root $GRP $GRP root $GRP $GRP $GRP\n" "" "" | |
43 | |
44 # symlinks (affect target, not symlink) | |
45 testing "chgrp symlink->file" "$IN chgrp root dir2/file $OUT" \ | |
46 "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" | |
47 testing "chgrp symlink->dir" "$IN chgrp root dir2/dir $OUT" \ | |
48 "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" | |
49 testing "chgrp -h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ | |
50 "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" | |
51 | |
52 # What does -h do (affect symlink, not target) | |
53 testing "chgrp -h symlink->file" "$IN chgrp -h root dir2/file $OUT" \ | |
54 "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" | |
55 testing "chgrp -h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ | |
56 "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" | |
57 | |
58 # chgrp -R (note, -h is implied by -R) | |
59 | |
60 testing "chgrp -R dir" "$IN chgrp -R root dir $OUT" \ | |
61 "root $GRP root root root $GRP $GRP\n" "" "" | |
62 testing "chgrp -R dir2" "$IN chgrp -R root dir2 $OUT" \ | |
63 "$GRP root $GRP $GRP $GRP root root\n" "" "" | |
64 testing "chgrp -R symlink->dir" "$IN chgrp -R root dir2/dir $OUT" \ | |
65 "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" | |
66 testing "chgrp -R symlink->file" "$IN chgrp -R root dir2/file $OUT" \ | |
67 "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" | |
68 | |
69 # chgrp -RP (same as -R by itself) | |
70 | |
71 testing "chgrp -RP dir2" "$IN chgrp -RP root dir2 $OUT" \ | |
72 "$GRP root $GRP $GRP $GRP root root\n" "" "" | |
73 testing "chgrp -RP symlink->dir" "$IN chgrp -RP root dir2/dir $OUT" \ | |
74 "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" | |
75 testing "chgrp -RP symlink->file" "$IN chgrp -RP root dir2/file $OUT" \ | |
76 "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" | |
77 | |
78 # chgrp -RH (change target but only recurse through symlink->dir on cmdline) | |
79 | |
80 testing "chgrp -RH dir2" "$IN chgrp -RH root dir2 $OUT" \ | |
81 "$GRP root root root $GRP $GRP $GRP\n" "" "" | |
82 testing "chgrp -RH symlink->dir" "$IN chgrp -RH root dir2/dir $OUT" \ | |
83 "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" | |
84 testing "chgrp -RH symlink->file" "$IN chgrp -RH root dir2/file $OUT" \ | |
85 "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" | |
86 | |
87 # chgrp -RL (change target and always recurse through symlink->dir) | |
88 | |
89 testing "chgrp -RL dir2" "$IN chgrp -RL root dir2 $OUT" \ | |
90 "$GRP root root root root $GRP $GRP\n" "" "" | |
91 testing "chgrp -RL symlink->dir" "$IN chgrp -RL root dir2/dir $OUT" \ | |
92 "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" | |
93 testing "chgrp -RL symlink->file" "$IN chgrp -RL root dir2/file $OUT" \ | |
94 "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" | |
95 | |
96 # -HLP are NOPs without -R | |
97 testing "chgrp -H without -R" "$IN chgrp -H root dir2/dir $OUT" \ | |
98 "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" | |
99 testing "chgrp -L without -R" "$IN chgrp -L root dir2/dir $OUT" \ | |
100 "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" | |
101 testing "chgrp -P without -R" "$IN chgrp -P root dir2/dir $OUT" \ | |
102 "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" | |
103 | |
104 rm -rf testdir |