aboutsummaryrefslogtreecommitdiffstats
path: root/test
blob: c07ca31dad6f5e06be842b3ecbddbd0790b0df16 (plain) (blame)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh

rm -rf .testdir

set -v
set -e

! ./xtest 2>/dev/null
! ./xtest . 2>/dev/null

simple_test() {
    test $(printf '%s\n' "$2"/* | ./xtest -$1 | wc -l) -gt 0
    printf '%s\n' "$2"/* | ./xtest -$1 | while read f; do
	test -$1 "$f"
    done

    test $(printf '%s\n' "$2"/* | ./xtest +$1 | wc -l) -gt 0
    printf '%s\n' "$2"/* | ./xtest +$1 | while read f; do
	! test -$1 "$f"
    done

    test $(./xtest -$1 "$2"/* | wc -l) -gt 0
    ./xtest -$1 "$2"/* | while read f; do
	if ! test "$f" = /dev/stdin; then
	    test -$1 "$f"
	fi
    done

    test $(./xtest +$1 "$2"/* | wc -l) -gt 0
    ./xtest +$1 "$2"/* | while read f; do
	if ! test "$f" = /dev/stdout; then
	    ! test -$1 "$f"
	fi
    done
}

simple_test b /dev
simple_test c /dev
simple_test d /dev
simple_test f /dev

mkdir -p .testdir
touch .testdir/r .testdir/w .testdir/x .testdir/k .testdir/u .testdir/g .testdir/rw
printf x > .testdir/s
chmod 100 .testdir/x
chmod 200 .testdir/w
chmod 400 .testdir/r
chmod 1000 .testdir/k
chmod 2000 .testdir/g
chmod 4000 .testdir/u
chmod 600 .testdir/rw
ln -s 'non existent file' .testdir/h
mkfifo .testdir/p
./mksocket .testdir/S
simple_test e .testdir
simple_test r .testdir
simple_test w .testdir
simple_test x .testdir
simple_test s .testdir
simple_test h .testdir
simple_test L .testdir
simple_test p .testdir
simple_test k .testdir
simple_test u .testdir
simple_test g .testdir
simple_test S .testdir

find .testdir -print0 | ./xtest -0x > .testdir/nul
find .testdir | ./xtest -x > .testdir/lf
find .testdir -print0 | ./xtest -0x | tr '\0' '\n' > .testdir/tr
! diff .testdir/nul .testdir/lf >/dev/null
diff .testdir/tr .testdir/lf >/dev/null

for f in 0 1 2 3 4 5 6 x y z; do
    if test $(xtest -t $f | wc -l) = 0; then
	! test -t $f
    else
	test -t $f
    fi
done

! test -e 'non existent file'
test $(./xtest -e 'non existent file' | wc -l) = 0
test $(./xtest +e 'non existent file' | wc -l) = 1

rm -rf .testdir
mkdir -p .testdir
for i in 0 1 2 3 4 5 6 7; do
    touch .testdir/$i
    chmod ${i}00 .testdir/$i
done

test $(./xtest -r .testdir/* | wc -l) = 4
test $(./xtest +r .testdir/* | wc -l) = 4
test $(./xtest -w .testdir/* | wc -l) = 4
test $(./xtest +w .testdir/* | wc -l) = 4
test $(./xtest -x .testdir/* | wc -l) = 4
test $(./xtest +x .testdir/* | wc -l) = 4
test $(./xtest -r +r .testdir/* | wc -l) = 8
test $(./xtest -w +w .testdir/* | wc -l) = 8
test $(./xtest -x +x .testdir/* | wc -l) = 8
test $(./xtest -rw .testdir/* | wc -l) = 6
test $(./xtest -r .testdir/* | ./xtest -w | wc -l) = 2

rm -rf .testdir