-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_tests.sh
executable file
·47 lines (38 loc) · 1.41 KB
/
run_tests.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
46
#!/bin/bash
#
# Author: Divye Kapoor (divyekapoor@gmail.com)
#
# Runs tests on the grepurls binary.
# The tests could be a bit better, but this is what works right now.
set -e
binary=./grepurls
for f in `ls testdata`; do
filename=testdata/${f}
echo -n Running ${filename}...
# Use shell redirection to supply input
redirect_output=/tmp/grepurls.redirect.out
${binary} < ${filename} > ${redirect_output}
# Use direct filename read to supply input and pipe it to wc -l
file_output=/tmp/grepurls.file.out
${binary} ${filename} > ${file_output}
# Diff outputs.
diff_redirect_output=/tmp/grepurls.redirect.diff
diff_file_output=/tmp/grepurls.file.diff
diff_flags='-y --suppress-common-lines'
(diff ${diff_flags} ${redirect_output} expected/${f} > ${diff_redirect_output} && \
diff ${diff_flags} ${file_output} expected/${f} > ${diff_file_output} && echo ' PASS') || \
(echo ' FAIL' && cat ${diff_redirect_output} ${diff_redirect_output})
done
for f in `ls faildata`; do
filename=faildata/${f}
echo -n Running ${filename}...
redirect_result=$(${binary} < ${filename} | wc -l)
file_result=$(${binary} ${filename} | wc -l)
expected_result=0
if [[ "${redirect_result}" -eq "${expected_result}" && "${file_result}" -eq "${expected_result}" ]]; then
echo ' PASS'
else
echo ' FAIL'
echo Redirect: "x${redirect_result}x" Direct: "x${file_result}x" Expected: "x${expected_result}x"
fi
done