This repository was archived by the owner on Aug 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunTests.sh
126 lines (95 loc) · 1.87 KB
/
runTests.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# File: runTests.sh
# Author: Jozef Méry - [email protected]
# Project: FLP-2021-xmeryj00-simplify-bkg
# Date: 8.3.2021
# Description: Automated test script.
# Console colors
RED="\033[0;31m"
GREEN="\033[0;32m"
YEL="\033[0;33m"
CLEAR="\033[0m"
testPass=0
testFiles=10
((testTotal=$testFiles * 3)) # 3 tests per file
bin="./simplify-bkg"
testDir="./test"
print() {
# interpret backslashes
echo -e $1
}
fail() {
print "[${RED}FAIL${CLEAR}] $1"
}
pass() {
print "[${GREEN}PASS${CLEAR}] $1"
}
exitPass() {
print "[${GREEN}TEST SET PASSED${CLEAR}]"
exit 0
}
exitFail() {
print "[${RED}TEST SET FAILED${CLEAR}]"
exit 1
}
callBin() {
eval "$bin $1"
}
formatTestPath() {
local path="$testDir/test$1"
echo "$path"
}
runTest() {
# $1 - flag "i", "1", or "2"
# $2 - test number
# echo $1
# echo $2
local path=$(formatTestPath $2)
callBin "-$1 $path.in" > $path.temp
diff $path.temp $path.out${1}
if [ "$?" == "0" ]
then
((++testPass))
pass "[TEST $2] $bin -$1 $path.in"
else
fail "[TEST $2] $bin -$1 $path.in"
fi
rm $path.temp
}
testFlags() {
local flags=("i" "1" "2")
for f in "${flags[@]}"
do
runTest $f $1 # $1 - test number
done
}
runTests() {
for (( i=1; i<=$testFiles; ++i ))
do
testFlags $i
done
}
# clearly mark program entry point and exit
main() {
print "Running ${bin} tests ..."
if [[ -f ${bin} ]]
then
pass "${bin} found"
else
fail "${bin} file not found."
exitFail
fi
print "-------------------------------------------------"
runTests
print "-------------------------------------------------"
print "TESTS FINISHED"
print "-------------------------------------------------"
print "${testPass} PASSED OUT OF ${testTotal}"
if [[ $testPass == $testTotal ]]
then
exitPass
else
exitFail
fi
}
main