31d0c6f97257d589ffe311113e288e7efdef2de5
[platform/upstream/coreutils.git] / tests / chmod / usage
1 #!/bin/sh
2 # Verify that chmod works correctly with odd option combinations.
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   chmod --version
7 fi
8
9 . $srcdir/../lang-default
10
11 pwd=`pwd`
12 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
13 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
14 trap '(exit $?); exit $?' 1 2 13 15
15
16 framework_failure=0
17 mkdir -p $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
19
20 if test $framework_failure = 1; then
21   echo "$0: failure in testing framework" 1>&2
22   (exit 1); exit 1
23 fi
24
25 fail=0
26
27 # Each line in this list is a set of arguments, followed by :,
28 # followed by the set of files it will attempt to chmod,
29 # or empty if the usage is erroneous.
30 # Many of these test cases are due to Glenn Fowler.
31 # These test cases assume GNU behavior for "options" like -w.
32 cases='
33   --         :
34   -- --      :
35   -- -- -- f : -- f
36   -- -- -w f : -w f
37   -- -- f    : f
38   -- -w      :
39   -- -w -- f : -- f
40   -- -w -w f : -w f
41   -- -w f    : f
42   -- f       :
43   -w         :
44   -w --      :
45   -w -- -- f : -- f
46   -w -- -w f : -w f
47   -w -- f    : f
48   -w -w      :
49   -w -w -- f : f
50   -w -w -w f : f
51   -w -w f    : f
52   -w f       : f
53   f          :
54   f --       :
55   f -w       : f
56   f f        :
57   u+gr f     :
58   ug,+x f    :
59 '
60
61 all_files=`echo "$cases" | sed 's/.*://'|sort -u`
62
63 old_IFS=$IFS
64 IFS='
65 '
66 for case in $cases; do
67   IFS=$old_IFS
68   args=`expr "$case" : ' *\(.*[^ ]\) *:'`
69   files=`expr "$case" : '.*: *\(.*\)'`
70
71   case $files in
72   '')
73     touch -- $all_files || framework_failure=1
74     chmod $args 2>/dev/null && fail=1
75     ;;
76   ?*)
77     touch -- $files || framework_failure=1
78     chmod $args || fail=1
79     for file in $files; do
80       # Test for misparsing args by creating all $files but $file.
81       # chmod has a bug if it succeeds even though $file is absent.
82       rm -f -- $all_files && touch -- $files && rm -- $file \
83           || framework_failure=1
84       chmod $args 2>/dev/null && fail=1
85     done
86     ;;
87   esac
88 done
89
90 if test $framework_failure = 1; then
91   echo "$0: failure in testing framework" 1>&2
92   fail=1
93 fi
94
95 (exit $fail); exit $fail