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 | |
| 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')
| -rw-r--r-- | src/test/lib/Makefile | 3 | ||||
| -rwxr-xr-x | src/test/lib/test_to_junit.sh | 56 |
2 files changed, 58 insertions, 1 deletions
diff --git a/src/test/lib/Makefile b/src/test/lib/Makefile index 2c4036f7..35b65419 100644 --- a/src/test/lib/Makefile +++ b/src/test/lib/Makefile @@ -25,7 +25,8 @@ ocaml: | $(BUILD_DIR) cd $(BUILD_DIR) && \ $(SAIL) -ocaml test_lib.sail -o test && \ ocamlopt -I $(ZARITH_DIR) $(ZARITH_LIB) sail_values.ml test.ml run_test_embed.ml -o test_embed.native && \ - ./test_embed.native + ./test_embed.native > test_embed.out && \ + ../test_to_junit.sh < test_embed.out interp: | $(BUILD_DIR) cp test_lib.sail $(BUILD_DIR) && \ 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 |
