-
Notifications
You must be signed in to change notification settings - Fork 227
/
run_tests.sh
executable file
·131 lines (118 loc) · 2.82 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
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
#!/bin/sh
#
# Copyright (C) 2011-2013 pancake <[email protected]>
# Copyright (C) 2011-2012 Edd Barrett <[email protected]>
# Copyright (C) 2012 Simon Ruderich <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Statistics.
TESTS_TOTAL=0
TESTS_SUCCESS=0
TESTS_FAILED=0
TESTS_BROKEN=0
TESTS_FIXED=0
# Let tests.sh know the complete test suite is run, enables statistics.
R2_SOURCED=1
die() {
echo "$1"
exit 1
}
control_c() {
echo
exit 1
}
trap control_c 2
. ./tests.sh
r2 > /dev/null
if [ $? != 0 ]; then
echo "Cannot find r2"
exit 1
fi
R=$PWD
# Run all tests.
T="t"; [ -n "$1" ] && T="$1"
[ -f "$T" -a -x "$T" ] && exec $T
cd $T || die "t/ doesn't exist"
for file in * ; do
[ "$file" = '*' ] && break
if [ -d "$file" ]; then
cd $file
for file2 in *; do
[ "$file2" = '*' ] && break
TEST_NAME=$(echo "${file2}" | sed 's/.sh$//')
NAME=`basename $file2`
TEST_NAME=$file
. ./${file2}
done
cd ..
else
NAME=`basename $file`
TEST_NAME=$NAME
. ./${file}
fi
done
# Print report.
echo
echo "=== Report ==="
echo
printf " SUCCESS"
if [ "${TESTS_SUCCESS}" -gt 0 ]; then
print_success "${TESTS_SUCCESS}"
else
print_failed "${TESTS_SUCCESS}"
fi
printf " FIXED"
if [ "${TESTS_FIXED}" -gt 0 ]; then
print_fixed "${TESTS_FIXED}"
else
print_fixed 0
fi
printf " BROKEN"
if [ "${TESTS_BROKEN}" -gt 0 ]; then
print_broken "${TESTS_BROKEN}"
else
print_broken 0
fi
printf " FAILED"
if [ "${TESTS_FAILED}" -gt 0 ]; then
print_failed "${TESTS_FAILED}"
else
print_failed 0
fi
printf " TOTAL\r"
print_label "[${TESTS_TOTAL}]"
echo
# Save statistics
cd $R
V=`r2 -v 2>/dev/null| grep ^rada| awk '{print $5}'`
touch stats.csv
grep -v "^$V" stats.csv > .stats.csv
echo "$V,${TESTS_SUCCESS},${TESTS_FIXED},${TESTS_BROKEN},${TESTS_FAILED},${FAILED}" >> .stats.csv
sort .stats.csv > stats.csv
rm -f .stats.csv
if [ "${TESTS_FAILED}" -gt 0 ]; then
exit 1
fi
exit 0
# Proper exit code.
if [ "${TESTS_TOTAL}" -eq "${TESTS_SUCCESS}" ]; then
exit 0
elif [ "${TESTS_FAILED}" -eq 0 ]; then
if [ "${TESTS_BROKEN}" -ge 0 ]; then
exit 2
elif [ "${TESTS_FIXED}" -ge 0 ]; then
exit 3
fi
fi
exit 1