Last active
January 6, 2021 22:25
-
-
Save milo-minderbinder/f2dd01380c06f4e76d4a86200f12538a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o errexit -o pipefail -o noclobber -o nounset | |
trap 'e=$?; if [ "$e" -ne "0" ]; then printf "LINE $BASH_LINENO: exit %s <- ${BASH_COMMAND}%s\\n" "$e" "$(printf " <- %s" "${FUNCNAME[@]:-main}")" 1>&2; fi' EXIT | |
get_summary() { | |
local no_color | |
local target_dir | |
local num_tests | |
local num_tests_failed | |
local num_tests_errors | |
local num_tests_skipped | |
no_color=0 | |
if [ "$1" == "--no-color" ]; then | |
no_color=1 | |
shift | |
fi | |
target_dir="$1" | |
num_tests=() | |
num_tests_failed=() | |
num_tests_errors=() | |
num_tests_skipped=() | |
while IFS= read -r -d $'\0'; do | |
>&2 printf '\e[32mINFO\e[0m: parsing test results: %s\n' "${REPLY}" | |
testsuite_info="$(grep -Eo '<testsuite\b[^>]*>' "${REPLY}")" | |
num_tests+=("$(printf '%s' "${testsuite_info}" | sed -E 's/.*[[:blank:]]tests="([^"]*)".*/\1/')") | |
num_tests_failed+=("$(printf '%s' "${testsuite_info}" | sed -E 's/.*[[:blank:]]failures="([^"]*)".*/\1/')") | |
num_tests_errors+=("$(printf '%s' "${testsuite_info}" | sed -E 's/.*[[:blank:]]errors="([^"]*)".*/\1/')") | |
num_tests_skipped+=("$(printf '%s' "${testsuite_info}" | sed -E 's/.*[[:blank:]]skipped="([^"]*)".*/\1/')") | |
done < <(find "${target_dir}" -type f -iname '*.xml' -print0 | xargs -0 grep -El --null '<testsuites?') | |
total_tests="$(printf '%d\n' "${num_tests[@]}" | paste -s -d '+' - | bc)" | |
total_tests="$(printf '%d\n' "${total_tests}" "${num_tests_skipped[@]}" | paste -s -d '-' - | bc)" | |
total_tests_passed="$(printf '%d\n' "${total_tests}" "${num_tests_failed[@]}" "${num_tests_errors[@]}" | paste -s -d '-' - | bc)" | |
total_tests_failed="$(printf '%d\n' "${num_tests_failed[@]}" | paste -s -d '+' - | bc)" | |
total_tests_errors="$(printf '%d\n' "${num_tests_errors[@]}" | paste -s -d '+' - | bc)" | |
total_tests_skipped="$(printf '%d\n' "${num_tests_skipped[@]}" | paste -s -d '+' - | bc)" | |
if [ "${no_color}" -eq "1" ]; then | |
printf '%s\n' "Passed" "Skipped" "Failed" "Errors" "TOTAL" | paste -s - | |
else | |
printf '%s\n' "$(tput setaf 2)Passed" "$(tput setaf 3)Skipped" "$(tput setaf 1)Failed" "$(tput setaf 3)$(tput setab 1)Errors$(tput sgr0)" "TOTAL" | paste -s - | |
fi | |
printf '%d\n' "${total_tests_passed}" "${total_tests_skipped}" "${total_tests_failed}" "${total_tests_errors}" "${total_tests}" | paste -s - | |
} | |
if ! [ -x "$(command -v bc)" ]; then | |
bc() { | |
while read data; do | |
data="$(printf '%s' "${data}" | grep -Eo '[0-9+-]*')" | |
python -c "print($data)" | |
done | |
} | |
fi | |
get_summary "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment