-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·45 lines (42 loc) · 875 Bytes
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
: "${CMD:=$(realpath per)}"
TESTDIR=$(mktemp -d)
trap "rm -rf $TESTDIR" 0
cd $TESTDIR
# testing "args" "expected", green if passed, red if failed
testing () {
$CMD $1 > got || echo "WARNING: $1 exited $?"
printf "%s\n" "$2" > wanted
! diff -u "$TESTDIR/wanted" "$TESTDIR/got"
printf "\033[1;%sm%s\033[0m\n" "$((31+$?))" "$1"
}
touch f777 f7520
chmod 777 f777
chmod 7520 f7520
# Compact Expected Result string
R="read" W="write" X="execute"
testing "0000" "user:
group:
other:
000
---------"
testing "120" "user: $X
group: $W
other:
120
--x-w----"
testing "-S 4567" "user: $R, $X
group: $R, $W
other: $R, $W, $X
special: suid
4567
r-srw-rwx"
testing "-Sn rwxr-xr-x" "0755"
testing "-Sns f7520" "7520
r-s-wS--T"
testing "-nv f777" "777
user: $R, $W, $X
group: $R, $W, $X
other: $R, $W, $X"
testing "-Sn rwSrwsrwT" "7676"
testing "-Sn rwsrwSr-t" "7765"