forked from Percona-QA/percona-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bats2junit.sh
executable file
·54 lines (47 loc) · 1.53 KB
/
bats2junit.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
#!/usr/bin/env bash
# This script transforms bats test results into junit format which jenkins understands
# run bats test with "bats --tap <test_file> | tee test-output.txt"
# then run this script like "bats2junit.sh test-output.txt <suite-name>"
# Created by Tomislav Plavcic, Percona LLC
INPUT_FILE=""
SUITE_NAME=""
FAIL_MODE=0
if [ "$#" -ne 2 ]; then
echo "Usage:"
echo " bats2junit.sh <input-filename> <suite-name>"
fi
INPUT_FILE="$1"
SUITE_NAME="$2"
CHECK_SKIP_COM="^(ok [0-9]* # skip \()(.*\) )(.*)$"
CHECK_SKIP="^(ok [0-9]* # skip )(.*)$"
CHECK_OK="^(ok [0-9]* )(.*)$"
CHECK_FAIL="^(not ok [0-9]* )(.*)$"
echo "<testsuite name=\"${SUITE_NAME}\">"
close_failure() {
if [[ ${FAIL_MODE} -eq 1 ]]; then echo -e "]]>\n </failure>\n</testcase>"; FAIL_MODE=0; fi
}
while read p; do
if [[ $p =~ $CHECK_SKIP_COM ]]; then
close_failure
echo "<testcase name=\"${BASH_REMATCH[3]}\">"
echo -e " <skipped/>\n <system-out>Skip reason:\n<![CDATA["
echo "${BASH_REMATCH[2]%??}"
echo -e "]]>\n </system-out>\n</testcase>"
elif [[ $p =~ $CHECK_SKIP ]]; then
close_failure
echo "<testcase name=\"${BASH_REMATCH[2]}\">"
echo " <skipped/>"
echo "</testcase>"
elif [[ $p =~ $CHECK_OK ]]; then
close_failure
echo "<testcase name=\"${BASH_REMATCH[2]}\"/>"
elif [[ $p =~ $CHECK_FAIL ]]; then
close_failure
echo "<testcase name=\"${BASH_REMATCH[2]}\">"
echo -e " <failure>\n<![CDATA["
FAIL_MODE=1
elif [[ "${FAIL_MODE}" -eq 1 ]]; then
echo "$p"
fi
done < ${INPUT_FILE}
echo "</testsuite>"