diff options
Diffstat (limited to 'tests/chmod.test')
-rwxr-xr-x | tests/chmod.test | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/tests/chmod.test b/tests/chmod.test index b2b5a488..6c4de0c0 100755 --- a/tests/chmod.test +++ b/tests/chmod.test @@ -24,28 +24,20 @@ mkdir dir touch file # We don't need to test all 512 permissions -for u in 0 1 2 3 4 5 6 7 -do - for g in 0 3 6 - do - for o in 0 7 - do - if [ "$type" == file ] - then - type=dir - rm -rf "./$type" && mkdir $type - DASH=d - else - type=file - rm -f "./$type" && touch $type - DASH=- - fi - DASHES=$(num2perm $u$g$o) - testing "$u$g$o $type" "chmod $u$g$o $type && - ls -ld $type | cut -d' ' -f 1 | cut -d. -f 1" "$DASH$DASHES\n" "" "" - done - done -done +for U in $(seq 0 7); do for G in 0 3 6; do for O in 0 7; do for T in dir file; do + chmod 777 $T 2>/dev/null + rm -rf $T + if [ "$T" == file ]; then + touch file + C=- + else + mkdir dir + C=d + fi + testing "$U$G$O $T" "chmod $U$G$O $T && ls -ld $T | cut -d' ' -f 1" \ + "${C}$(num2perm $U$G$O)\n" "" "" +done; done; done; done +unset U G O T C rm -rf dir file && mkdir dir && touch file 640 testing "750 dir 640 file" "chmod 750 dir 640 file && @@ -54,6 +46,7 @@ testing "750 dir 640 file" "chmod 750 dir 640 file && chtest() { + chmod -fR 700 dir file 2>/dev/null rm -rf dir file && mkdir dir && touch file testing "$1 dir file" \ "chmod $1 dir file && ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" \ @@ -107,10 +100,32 @@ chtest +x "drwxr-xr-x\n-rwxr-xr-x\n" chtest -r "d-wx--x--x\n--w-------\n" chtest -w "dr-xr-xr-x\n-r--r--r--\n" chtest -x "drw-r--r--\n-rw-r--r--\n" +chtest a-w,a+x "dr-xr-xr-x\n-r-xr-xr-x\n" + +# macOS doesn't allow +s in /tmp +touch s-supported +chmod +s s-supported 2>/dev/null || SKIP=1 +rm s-supported chtest g+s "drwxr-sr-x\n-rw-r-Sr--\n" chtest u+s "drwsr-xr-x\n-rwSr--r--\n" +chtest +s "drwsr-sr-x\n-rwSr-Sr--\n" chtest o+s "drwxr-xr-x\n-rw-r--r--\n" +unset SKIP + chtest +t "drwxr-xr-t\n-rw-r--r-T\n" +chtest a=r+w+x "drwxrwxrwx\n-rwxrwxrwx\n" + +# (chtest starts off with a directory that's +x...) +testing "+X" \ + "mkdir -m 000 Xd && touch Xf && chmod +X Xd Xf && ls -ld Xd Xf | cut -d' ' -f 1" \ + "d--x--x--x\n-rw-r--r--\n" "" "" + +mkdir foo +ln -s bar foo/baz +# If you explicitly ask us, we'll try (and fail) to chmod a symlink. +testing "-R symlink arg" 'chmod -R 750 foo/baz 2>/dev/null; echo $?' "1\n" "" "" +# If you only imply that you might want us to do that, we'll skip it. +testing "-R symlink recurse" 'chmod -R 750 foo; echo $?' "0\n" "" "" # Removing test files for cleanup purpose rm -rf dir file |