forked from alx-tools/Betty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·173 lines (142 loc) · 3.31 KB
/
test.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
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
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
tests_folder="tests"
tests_style_folder="$tests_folder/style"
tests_doc_folder="$tests_folder/doc"
style_exec="betty-style.pl"
doc_exec="betty-doc.pl"
errors=0
# # # # # # # # # # # # #
# Testing coding style #
# # # # # # # # # # # # #
echo -e "Testing coding style specs..."
for dir in $tests_style_folder/*/
do
dir=${dir%*/}
echo -e "Found ${CYAN}${dir##*/}${NC} folder..."
for file in ${dir}/*.{c,h}
do
if [ "${file}" == "${dir}/*.c" ] || [ "${file}" == "${dir}/*.h" ]
then
continue
fi
if [[ "${file}" == *.c ]]
then
current_test=${file%*.c}
else
current_test=${file%*.h}
fi
echo -e "\tTesting ${PURPLE}${current_test}${NC}..."
src="${file}"
expected="$current_test.expected"
if [ ! -f $expected ]
then
echo -e "\t${RED}Missing expected output, ignored${NC}"
echo
continue
fi
output=$(./$style_exec $src)
exp=$(cat $expected)
if [ "$output" != "$exp" ]
then
echo -e "\t${RED}Error. The output is not the one expected:${NC}"
echo "$output"
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
fi
echo
done
done
# # # # # # # # # # # # #
# Testing documentation #
# # # # # # # # # # # # #
echo -e "Testing documentation style specs..."
dir=${tests_doc_folder%*/}
echo -e "Found ${CYAN}${dir##*/}${NC} folder..."
for file in ${dir}/*.{c,h}
do
if [ "${file}" == "${dir}/*.c" ] || [ "${file}" == "${dir}/*.h" ]
then
continue
fi
if [[ "${file}" == *.c ]]
then
current_test=${file%*.c}
else
current_test=${file%*.h}
fi
echo -e "\tTesting ${PURPLE}${current_test}${NC}..."
src="${file}"
expected_stdout="$current_test.expected.stdout"
expected_stderr="$current_test.expected.stderr"
if [ ! -f $expected_stdout ]
then
echo -e "\t${RED}Missing expected_stdout, ignored${NC}"
echo
continue
fi
if [ ! -f $expected_stderr ]
then
echo -e "\t${RED}Missing expected_stderr, ignored${NC}"
echo
continue
fi
rm -f "/tmp/stderr"
output=$(./$doc_exec $src 2> /tmp/stderr)
status=$(echo $?)
err=$(cat /tmp/stderr)
exp_stdout=$(cat $expected_stdout)
exp_stderr=$(cat $expected_stderr)
if [ "$output" != "$exp_stdout" ]
then
echo -e "\t${RED}Error. The output (stdout) is not the one expected:${NC}"
echo "$output"
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
fi
if [ "$err" != "$exp_stderr" ]
then
echo -e "\t${RED}Error. The error output (stderr) is not the one expected:${NC}"
echo "$err"
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
fi
if [ "$status" == "0" ]
then
if [[ $err = *[!\ ]* ]]
then
echo -e "\t${RED}Error. The error output (stderr) should be empty if the program successed:${NC}"
echo $err
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
fi
else
if [[ $err = *[!\ ]* ]]
then
echo -e "\t${GREEN}Test passed successfully!${NC}"
else
echo -e "\t${RED}Error. The error output (stderr) should be empty if the program successed:${NC}"
echo $err
let errors++
fi
fi
echo
done
# # # # # # # # # # # #
# Count total errors #
# # # # # # # # # # # #
if [ $errors -gt 0 ]
then
echo -e "${RED}${errors} test(s) didn't passed...${NC}"
exit 1
fi
echo -e "${GREEN}All tests passed successfully!${NC}"
exit 0