e9736968d4100cfb86093105aa6d1181169a2246
[platform/upstream/coreutils.git] / tests / chgrp / posix-H
1 #!/bin/sh
2 # Test POSIX-mandated -H option.
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   chgrp --version
7 fi
8
9 . $srcdir/../group-names
10 set _ $groups; shift
11 g1=$1
12 g2=$2
13
14 pwd=`pwd`
15 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
16 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
17 trap '(exit $?); exit $?' 1 2 13 15
18
19 framework_failure=0
20 mkdir -p $tmp || framework_failure=1
21 cd $tmp || framework_failure=1
22
23 mkdir 1 2 3 || framework_failure=1
24 touch 1/1F 2/2F 3/3F || framework_failure=1
25 ln -s 1 1s || framework_failure=1
26 ln -s ../3 2/2s || framework_failure=1
27 chgrp -R $g1 1 2 3 || framework_failure=1
28
29 if test $framework_failure = 1; then
30   echo "$0: failure in testing framework" 1>&2
31   (exit 1); exit 1
32 fi
33
34 fail=0
35
36 chgrp -H -R $g2 1s 2 || fail=1
37
38 # These must have group $g2.
39 # =========================
40 changed='
41 1
42 1/1F
43 2
44 2/2F
45 3
46 '
47 for i in $changed; do
48   # Filter out symlinks (entries that end in `s'), since it's not
49   # possible to change their group/owner information on some systems.
50   case $i in *s) continue;; esac
51   set _ `ls -dgn $i`; shift
52   group=$3
53   test $group = $g2 || fail=1
54 done
55
56 # These must have group $g1.
57 # =========================
58 not_changed='
59 1s
60 2/2s
61 3/3F
62 '
63 for i in $not_changed; do
64   # Filter out symlinks (entries that end in `s'), since it's not
65   # possible to change their group/owner information on some systems.
66   case $i in *s) continue;; esac
67   set _ `ls -dgn $i`; shift
68   group=$3
69   test $group = $g1 || fail=1
70 done
71
72 (exit $fail); exit $fail