tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / chgrp / deref
1 #!/bin/sh
2 # see if chgrp can change the group of a symlink
3
4 # Copyright (C) 2000, 2004-2009 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   chgrp --version
22 fi
23
24 . $srcdir/test-lib.sh
25 require_membership_in_two_groups_
26
27 set _ $groups; shift
28 g1=$1
29 g2=$2
30
31 touch f
32 ln -s f symlink
33
34 chgrp -h $g2 symlink 2> /dev/null
35 set _ `ls -ln symlink`
36 g=$5
37 test "$g" = $g2 ||
38   skip_test_ "your system doesn't support changing the owner or group" \
39       "of a symbolic link."
40
41
42 chgrp $g1 f
43 set _ `ls -ln f`; g=$5; test "$g" = $g1 || fail=1
44
45 chgrp -h $g2 symlink || fail=1
46 set _ `ls -ln f`; g=$5; test "$g" = $g1 || fail=1
47 set _ `ls -ln symlink`; g=$5; test "$g" = $g2 || fail=1
48
49 # This should not change the group of f.
50 chgrp -h $g2 symlink || fail=1
51 set _ `ls -ln f`; g=$5; test "$g" = $g1 || fail=1
52 set _ `ls -ln symlink`; g=$5; test "$g" = $g2 || fail=1
53
54 chgrp $g2 f
55 set _ `ls -ln f`; g=$5; test "$g" = $g2 || fail=1
56
57 # This *should* change the group of f.
58 # Though note that the diagnostic you'd get with -c is misleading in that
59 # it says the `group of `symlink'' has been changed.
60 chgrp --dereference $g1 symlink
61 set _ `ls -ln f`; g=$5; test "$g" = $g1 || fail=1
62 set _ `ls -ln symlink`; g=$5; test "$g" = $g2 || fail=1
63
64 Exit $fail