-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·101 lines (89 loc) · 2.89 KB
/
test.sh
File metadata and controls
executable file
·101 lines (89 loc) · 2.89 KB
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
#!/bin/bash
# Process test result file line by line and generate result summaries and logs
# Argument: Name of file that contains test results. Has .abs.test extension
function process_test_result() {
if [ -d "$1" ]; then
echo "Invalid call to test_summary_rec"
return
elif [ ${1: -9} != ".abs.test" ]; then
# Warning! Space between : and -9 is necessary
echo "Not valid file extension"
return
fi
local new_log_file="${1:0: -9}.log"
if [ -f "$new_log_file" ]; then
mv -v "$new_log_file" "${new_log_file}.old"
fi
while read line; do
if [ "${line:0:1}" == "#" ]; then
echo "${line:2}" >> $new_log_file
elif [ "${line:0:4}" == "PASS" ]; then
pass=$(($pass + 1))
echo "$line" >> $new_log_file
echo "$separator" >> $new_log_file
elif [ "${line:0:4}" == "FAIL" ]; then
fail=$(($fail + 1))
echo "$line" >> $new_log_file
echo "$separator" >> $new_log_file
test_log_text="${test_log_text}${line:5} ($new_log_file)\n"
elif [ "${line:0:5}" == "XFAIL" ]; then
xfail=$(($xfail + 1))
echo "$line" >> $new_log_file
echo "$separator" >> $new_log_file
elif [ "${line:0:4}" == "SKIP" ]; then
skip=$(($skip + 1))
echo "$line" >> $new_log_file
echo "$separator" >> $new_log_file
fi;
done < $1;
rm -rf $1
}
# Go through the codebase folders recursively searching for .abs.test files
# Argument: Folder to look at
function test_summary_rec() {
if [ ! -d "$1" ]; then
echo "Invalid call to test_summary_rec"
return
fi
for file in "$1"/*; do
if [ -d "$file" ]; then
test_summary_rec "$file"
elif [ "${file: -9}" = ".abs.test" ]; then
# Warning! Space between : and -9 is necessary
process_test_result "$file"
fi
done;
}
test_file="$1"
if [ -z "$test_file" ]; then
echo "Missing test file name"
exit 1
fi
if [ -f "$test_file" ]; then
mv -v "$test_file" "${test_file}.old"
fi
separator="================================================================================"
pass=0
xfail=0
skip=0
fail=0
test_log_text="Tests that failed:\n"
echo "Test run on $(date)" >> $test_file
test_summary_rec "."
if [ $fail == 0 ]; then
test_log_text="${test_log_text}None\n"
fi
total=$(($pass + $xfail + $skip + $fail))
if [ ! $total -eq 0 ]; then
echo "$separator" >> $test_file
echo "Test execution result for $total tests run:" >> $test_file
echo "Passed tests: $pass" >> $test_file
echo "Failed tests: $fail" >> $test_file
echo "Failed tests (expected): $xfail" >> $test_file
echo "Skipped tests: $skip" >> $test_file
echo "" >> $test_file
echo -ne "$test_log_text" >> $test_file
echo "$separator" >> $test_file
fi
cat $test_file
exit 0