aboutsummaryrefslogtreecommitdiff
path: root/scripts/test/chmod.test
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-07-04 21:21:45 -0500
committerRob Landley <rob@landley.net>2014-07-04 21:21:45 -0500
commitd6f8c41e25428c8a0caf6f52fbe665d3baa06adc (patch)
treeff088176fddd5fe2c76664d6f247018788b2f1c9 /scripts/test/chmod.test
parentef0ed68d5ba5794c1352e64273d4c5039e62476b (diff)
downloadtoybox-d6f8c41e25428c8a0caf6f52fbe665d3baa06adc.tar.gz
Cut down from 1000+ file attribute tests to a more manageable number.
Diffstat (limited to 'scripts/test/chmod.test')
-rw-r--r--scripts/test/chmod.test62
1 files changed, 28 insertions, 34 deletions
diff --git a/scripts/test/chmod.test b/scripts/test/chmod.test
index 71a9580b..f370d601 100644
--- a/scripts/test/chmod.test
+++ b/scripts/test/chmod.test
@@ -5,48 +5,42 @@
#testing "name" "command" "result" "infile" "stdin"
-declare -a StrForMod=('---' '--x' '-w-' '-wx' 'r--' 'r-x' 'rw-' 'rwx')
-#StrForMod[0]='---'
-#StrForMod[1]='--x'
-#StrForMod[2]='-w-'
-#StrForMod[3]='-wx'
-#StrForMod[4]='r--'
-#StrForMod[5]='r-x'
-#StrForMod[6]='rw-'
-#StrForMod[7]='rwx'
+PERM="---""--x""-w-""-wx""r--""r-x""rw-""rwx"
+
+num2perm()
+{
+ for i in 0 1 2
+ do
+ num=${1:$i:1}
+ printf "%s" ${PERM:$(($num*3)):3}
+ done
+ echo
+}
# Creating test files to test chmod command
mkdir dir
touch file
-for u in {0..7}
-do
- for g in {0..7}
- do
- for o in {0..7}
- do
- rm -rf dir && mkdir dir
- uu=${StrForMod[$u]}
- gg=${StrForMod[$g]}
- oo=${StrForMod[$o]}
- testing "chmod $u$g$o dir" "chmod $u$g$o dir &&
- ls -ld dir | cut -d' ' -f 1" "d$uu$gg$oo\n" "" ""
- done
- done
-done
-
-for u in {0..7}
+# We don't need to test all 511 permissions
+for u in 0 1 2 3 4 5 6 7
do
- for g in {0..7}
+ for g in 0 3 6
do
- for o in {0..7}
+ for o in 0 7
do
- rm -rf file && touch file
- uu=${StrForMod[$u]}
- gg=${StrForMod[$g]}
- oo=${StrForMod[$o]}
- testing "chmod $u$g$o file" "chmod $u$g$o file &&
- ls -ld file | cut -d' ' -f 1" "-$uu$gg$oo\n" "" ""
+ 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 "chmod $u$g$o $type" "chmod $u$g$o $type &&
+ ls -ld $type | cut -d' ' -f 1" "$DASH$DASHES\n" "" ""
done
done
done