From d8969b1f9631dc15d5fb6b3b33a4a69dbfb7358a Mon Sep 17 00:00:00 2001 From: Robert Norton Date: Wed, 19 Jul 2017 14:05:04 +0100 Subject: borrow some of aa's bash code to convert library test suite output to junit xml for jenkins. --- src/test/lib/Makefile | 3 ++- src/test/lib/test_to_junit.sh | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 src/test/lib/test_to_junit.sh (limited to 'src/test/lib') 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+=" \n" +} + +function yellow { + (( fail += 1 )) + printf "$1: ${YELLOW}$2${NC}\n" + XML+=" \n $2\n \n" +} + +function red { + (( fail += 1 )) + printf "$1: ${RED}$2${NC}\n" + XML+=" \n $2\n \n" +} + +function finish_suite { + printf "$1: Passed ${pass} out of $(( pass + fail ))\n" + XML=" \n$XML \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 -- cgit v1.2.3