a22017eb63bc4c72a58dccb94a9e0c3d922b4e08
[platform/upstream/coreutils.git] / tests / chmod / equals
1 #!/bin/sh
2 # Make sure chmod mode arguments of the form A=B work properly.
3 # Before fileutils-4.1.2, some of them didn't.
4 # Also, before coreutils-5.3.1, =[ugo] sometimes didn't work.
5
6 if test "$VERBOSE" = yes; then
7   set -x
8   chmod --version
9 fi
10
11 pwd=`pwd`
12 tmp=equals.$$
13 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
14 trap '(exit $?); exit' 1 2 13 15
15
16 framework_failure=0
17 mkdir $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
19 touch f || framework_failure=1
20
21 if test $framework_failure = 1; then
22   echo "$0: failure in testing framework" 1>&2
23   (exit 1); exit 1
24 fi
25
26 fail=0
27
28 expected_u=-rwx------
29 expected_g=----rwx---
30 expected_o=-------rwx
31
32 for src in u g o; do
33   for dest in u g o; do
34     test $dest = $src && continue
35     chmod a=,$src=rwx,$dest=$src,$src= f || fail=1
36     set _ `ls -l f`; shift; actual_perms=$1
37     expected_perms=`eval 'echo \$expected_'$dest`
38     test "$actual_perms" = "$expected_perms" || fail=1
39   done
40 done
41
42 umask 027
43 chmod a=,u=rwx,=u f || fail=1
44 set _ `ls -l f`; shift; actual_perms=$1
45 test "$actual_perms" = "-rwxr-x---" || fail=1
46
47 (exit $fail); exit $fail