blob: f229a922467f340495e00b8a9be474a315f73f66 (
plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#!/bin/sh
REF_OUT="ref.out"
TEST_OUT="test.out"
testfiles()
{
echo "Finding path '$@'..."
find "$@" > "$REF_OUT"
sed -i '/.*\.out/d' "$REF_OUT"
./myfind "$@" > "$TEST_OUT"
[ $(echo "$?") -eq 0 ] && echo "Return value OK"
sed -i '/.*\.out/d' "$TEST_OUT"
diff "$REF_OUT" "$TEST_OUT" && echo "Success"
}
testperm()
{
echo "Finding perm '$@'..."
find "$@" > "$REF_OUT"
sed -i '/.*\.out/d' "$REF_OUT"
./myfind "$@" > "$TEST_OUT"
[ $(echo "$?") -eq 0 ] && echo "Return value OK"
sed -i '/.*\.out/d' "$TEST_OUT"
diff "$REF_OUT" "$TEST_OUT" && echo "Success"
}
testug()
{
echo "Finding '$@'..."
find "$@" > "$REF_OUT"
sed -i '/.*\.out/d' "$REF_OUT"
./myfind "$@" > "$TEST_OUT"
[ $(echo "$?") -eq 0 ] && echo "Return value OK"
sed -i '/.*\.out/d' "$TEST_OUT"
diff "$REF_OUT" "$TEST_OUT" && echo "Success"
}
testflags()
{
echo "Finding flags '$@'..."
find "$@" > "$REF_OUT"
sed -i '/.*\.out/d' "$REF_OUT"
./myfind "$@" > "$TEST_OUT"
[ $(echo "$?") -eq 0 ] && echo "Return value OK"
sed -i '/.*\.out/d' "$TEST_OUT"
diff "$REF_OUT" "$TEST_OUT" && echo "Success"
}
testboth()
{
echo "Finding '$@'..."
find "$@" > "$REF_OUT"
sed -i '/.*\.out/d' "$REF_OUT"
./myfind "$@" > "$TEST_OUT"
[ $(echo "$?") -eq 0 ] && echo "Return value OK"
sed -i '/.*\.out/d' "$TEST_OUT"
diff "$REF_OUT" "$TEST_OUT" && echo "Success"
}
testerror()
{
echo "Attempting to find '$@'..."
find "$@" > "$REF_OUT"
sed -i '/.*\.out/d' "$REF_OUT"
./myfind "$@" > "$TEST_OUT"
ret=$(echo "$?")
([ "$ret" -eq 1 ] && echo "Return value OK") || echo "Invalid return value " $ret
sed -i '/.*\.out/d' "$TEST_OUT"
diff "$REF_OUT" "$TEST_OUT" && echo "Success"
}
clean()
{
rm "$REF_OUT" "$TEST_OUT"
}
# Files
echo "Tests files:"
echo "======"
testfiles
testfiles tests
testfiles src
testfiles src///
echo
echo "============================================="
echo
# Perms
mkdir foo
touch foo/foo foo/bar foo/baz
chmod 123 foo/foo
chmod 777 foo/bar
chmod 644 foo/baz
echo "Tests perm:"
echo "======"
# Should only match foo/foo
testperm foo -perm 123
# Should match foo/bar and foo/foo
testperm foo -perm -121
# Should match foo/bar and foo/baz
testperm foo -perm /641
# Should only match foo/bar
testperm foo -perm /060
# Should only match foo/foo
chmod 644 foo/bar
chmod 644 foo/baz
testperm foo -perm -121
echo
echo "============================================="
echo
echo "Tests user:"
echo "======"
testug foo -user marcellus
# sudo chown nobody foo/bar
testug foo -user marcellus
testug foo -user nobody
echo
echo "============================================="
echo
echo "Tests group:"
echo "======"
testug foo -group marcellus
# sudo chown :wheel foo/bar
testug foo -group marcellus
testug foo -group wheel
# Clean
rm -rf foo
echo
echo "============================================="
echo
# Flags
echo "Tests flags:"
echo "======"
testflags -type d
testflags -type f
testflags -name '*'
testflags -newer Makefile
echo
echo "============================================="
echo
# Both
echo "Tests both:"
echo "======"
testboth tests -type d
testboth src/ -type f
testboth ../ -name '*.h' -a -type f
testboth ../ -name Makefile -o -newer Makefile
echo
echo "============================================="
echo
# Errors
echo "Error tests:"
echo "======"
testerror -type ff
testerror -name
testerror -newer
testerror -type
testerror -name '*.c' -print -newer -o -print
mkdir foo
touch foo/foo foo/bar foo/baz
testerror foo -user dghdfkhg
rm -rf foo
testerror -name '*.c' -a -a -group marcellus
testerror -name '*.c' -o -a -group marcellus
testerror -name '*.c' -a -o -group marcellus
testerror -name '*.c' -o -o -group marcellus
# Cleanup
clean
|