diff options
| author | Robert Norton | 2017-07-19 14:05:04 +0100 |
|---|---|---|
| committer | Robert Norton | 2017-07-19 14:05:04 +0100 |
| commit | d8969b1f9631dc15d5fb6b3b33a4a69dbfb7358a (patch) | |
| tree | 1ca0c42cfd1c8fecc35913bae71a4a25c953985d /src/test/lib/test_to_junit.sh | |
| parent | 7c9184d1bb7a09fbcf864cf8c4a9b37f463a9d1d (diff) | |
borrow some of aa's bash code to convert library test suite output to junit xml for jenkins.
Diffstat (limited to 'src/test/lib/test_to_junit.sh')
| -rwxr-xr-x | src/test/lib/test_to_junit.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/test/lib/test_to_junit.sh b/src/test/lib/test_to_junit.sh new file mode 100755 index 00000000..65753835 --- /dev/null +++ b/src/test/lib/test_to_junit.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + + +pass=0 +fail=0 + +XML="" + +function green { + (( pass += 1 )) + printf "$1: ${GREEN}$2${NC}\n" + XML+=" <testcase name=\"$1\"/>\n" +} + +function yellow { + (( fail += 1 )) + printf "$1: ${YELLOW}$2${NC}\n" + XML+=" <testcase name=\"$1\">\n <error message=\"$2\">$2</error>\n </testcase>\n" +} + +function red { + (( fail += 1 )) + printf "$1: ${RED}$2${NC}\n" + XML+=" <testcase name=\"$1\">\n <error message=\"$2\">$2</error>\n </testcase>\n" +} + +function finish_suite { + printf "$1: Passed ${pass} out of $(( pass + fail ))\n" + XML=" <testsuite name=\"$1\" tests=\"$(( pass + fail ))\" failures=\"${fail}\" timestamp=\"$(date)\">\n$XML </testsuite>\n" + printf "$XML" > $1.xml + XML="" + pass=0 + fail=0 +} + +test_regex="^(.*): (pass|fail)$" +while read line; do + if [[ $line =~ $test_regex ]] ; then + test_name=${BASH_REMATCH[1]} + test_status=${BASH_REMATCH[2]} + if [[ $test_status == pass ]] ; then + green $test_name $test_status + else + red $test_name $test_status + fi + else + echo $line + fi +done +finish_suite all_tests |
