diff options
| author | Alasdair Armstrong | 2017-07-26 14:12:09 +0100 |
|---|---|---|
| committer | Alasdair Armstrong | 2017-07-26 14:12:09 +0100 |
| commit | 678ab0e23ba4a8d95010df2bd2467dae7d544e29 (patch) | |
| tree | 0b2e02773327b9483f24b2e1ad46b7235ec9633e /src/test/lib/test_to_junit.sh | |
| parent | 26e59493cde0ffbf1868426fe3bec158f2dbaad0 (diff) | |
| parent | 18cf235fad35a0e06e26ea91ee0e1c673febddb8 (diff) | |
Merge remote-tracking branch 'origin/master' into sail_new_tc
Diffstat (limited to 'src/test/lib/test_to_junit.sh')
| -rwxr-xr-x | src/test/lib/test_to_junit.sh | 62 |
1 files changed, 62 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..71e908bd --- /dev/null +++ b/src/test/lib/test_to_junit.sh @@ -0,0 +1,62 @@ +#!/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="" + +XML_FILE=tests.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" >> $XML_FILE + XML="" + pass=0 + fail=0 +} + +test_regex="^\"*([^\"]*)\"*: (pass|fail)$" +echo "<testsuites>" > $XML_FILE +for result_file in $@; do + 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 < "$result_file" + finish_suite $result_file +done +echo "</testsuites>" >> $XML_FILE |
