-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtester.sh
103 lines (84 loc) · 2.32 KB
/
tester.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
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
#!/bin/bash
exe="./src/okreadme" # The application (from command arg)
diff="diff -iad" # Diff command, or what ever
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
print_ok() {
if [ "$color_prompt" = yes ]; then
printf "\033[32mOK!\033[0m\n"
else
printf "OK!\n"
fi
}
print_fail() {
if [ "$color_prompt" = yes ]; then
printf "\033[31mFAILS..\033[0m\n"
else
printf "FAILS..\n"
fi
}
run_test() {
printf " - test %s ... " $1
# Validate infile exists (do the same for out validate file)
if [ ! -f "$1" ]; then
print_fail
printf " -> file not exists %s\n" $1
continue;
fi
if [ ! -f "$2" ]; then
print_fail
printf " -> file not exists %s\n" $2
continue;
fi
rm -r tests/**/*.test
printf " - test %s ... " "$1"
run_out=${1%%.*}".test"
# Run application, redirect in file to app, and output to out file
"./$exe" "$1" > $run_out 2>&1
e_code=$?
if [ "$3" = "success" ]; then
if [ $e_code != 0 ]; then
print_fail
printf " -> result code is %s\n" $e_code
return
fi
else
if [ $e_code = 0 ]; then
print_fail
printf " -> result code is %s\n" $e_code
return
fi
fi
# Execute diff
# echo "$diff $run_out $2"
$diff $run_out $2
# Check exit code from previous command (ie diff)
# We need to add this to a variable else we can't print it
# as it will be changed by the if [
# Iff not 0 then the files differ (at least with diff)
e_code=$?
if [ $e_code != 0 ]; then
print_fail
printf " -> fail diff %s\n" $e_code
else
print_ok
fi
}
echo "[Run Tests, Success Cases]"
for file in tests/success/*.input; do
# Padd file_base with suffixes
file_in="${file%%.*}.input" # The in file
file_out="${file%%.*}.output" # The out file
run_test $file_in $file_out "success"
done
echo ""
echo "[Run Tests, Error Cases]"
for file in tests/fail/*.input; do
# Padd file_base with suffixes
file_in="${file%%.*}.input" # The in file
file_out="${file%%.*}.output" # The out file
run_test $file_in $file_out "fail"
done
# Clean exit with status 0
exit 0