#!/usr/bin/env bash # Summary of the test results (.trx files of «dotnet test --logger trx»): passed, failed and skipped for each file, # the names of the failed ones and the reasons of the skipped ones. It writes it to the log and, if the runner offers # it, to the job summary (GITHUB_STEP_SUMMARY). No response body nor personal data: only test names and messages. # # .gitea/scripts/riepilogo-prove.sh [saltate ammesse] # # Exits with 1 if a test failed, if the skipped ones are more than those allowed (default 0: the CI has Chromium and # Xvfb, so no test has a reason to be skipped) or if there is no result at all. The only exception is the «da fare» # category: the inconclusive results of FeaturesStillToDo (H.264 conformance streams for the parts the decoder does # not handle yet) whose reason starts with «da fare: » are listed and do not count among the skipped ones. # Any other inconclusive result, even with «da fare: » in its message, is a skipped one. set -euo pipefail cartella="${1:?Indica la cartella con i file .trx.}" ammesse="${2:-${PROVE_SALTATE_AMMESSE:-0}}" [[ "$ammesse" =~ ^[0-9]+$ ]] || { echo "Il numero di prove saltate ammesse deve essere un intero, non «$ammesse»." >&2; exit 2; } shopt -s nullglob file=("$cartella"/*.trx) if (( ${#file[@]} == 0 )); then echo "Nessun risultato delle prove in $cartella: le prove non sono partite." >&2 exit 1 fi riepilogo="$(mktemp)" trap 'rm -f "$riepilogo"' EXIT fallite_totali=0 saltate_totali=0 dafare_totali=0 # «Da fare»: an inconclusive result of FeaturesStillToDo whose reason starts with «da fare: » right after the MSTest # frame («Assert.Inconclusive. », «Assert.Inconclusive failed. », «Assert.Inconclusive non riuscito. »): it marks a part # not written yet, not a broken environment, and is counted apart. Both the test name and the start of the reason are # constrained: no other test can skip silently by writing «da fare: » in its message. da_fare='$1 != "Passed" && $1 != "Failed" && $1 != "Error" && $1 != "Timeout" && $1 != "Aborted" && $2 ~ /^FeaturesStillToDo( |\(|$)/ && $3 ~ /^Assert\.Inconclusive[^.]*\. *da fare: /' { echo "### Prove" echo echo "| Risultati | Totale | Superate | Fallite | Saltate | Da fare |" echo "|---|---:|---:|---:|---:|---:|" } > "$riepilogo" for trx in "${file[@]}"; do nome="$(basename "$trx")" # One result per line (the .trx files are XML over several lines), then name, outcome and first message of each. righe="$(tr '\r\n' ' ' < "$trx" | sed 's/", s); gsub(/&/, "\\&", s); gsub(/[ \t]+/, " ", s) return s } /^.*/, "", testata) messaggio = "" if (match($0, /[^<]*<\/Message>/)) { messaggio = substr($0, RSTART + 9, RLENGTH - 19) } printf "%s\t%s\t%s\n", attributo(testata, "outcome"), testo_xml(attributo(testata, "testName")), testo_xml(messaggio) }')" totale=0; superate=0; fallite=0; saltate=0; dafare=0 if [[ -n "$righe" ]]; then totale=$(printf '%s\n' "$righe" | wc -l) superate=$(printf '%s\n' "$righe" | awk -F'\t' '$1 == "Passed"' | wc -l) fallite=$(printf '%s\n' "$righe" | awk -F'\t' '$1 == "Failed" || $1 == "Error" || $1 == "Timeout" || $1 == "Aborted"' | wc -l) dafare=$(printf '%s\n' "$righe" | awk -F'\t' "$da_fare" | wc -l) fi saltate=$((totale - superate - fallite - dafare)) fallite_totali=$((fallite_totali + fallite)) saltate_totali=$((saltate_totali + saltate)) dafare_totali=$((dafare_totali + dafare)) echo "== $nome: totale $totale · superate $superate · fallite $fallite · saltate $saltate · da fare $dafare" echo "| \`$nome\` | $totale | $superate | $fallite | $saltate | $dafare |" >> "$riepilogo" if (( fallite > 0 )); then echo " Fallite:" # The extra lines are read and discarded (no «head»: with pipefail the SIGPIPE would stop the script). printf '%s\n' "$righe" | awk -F'\t' '$1 == "Failed" || $1 == "Error" || $1 == "Timeout" || $1 == "Aborted" { if (++n > 50) next; m = $3; if (length(m) > 300) m = substr(m, 1, 300) "…"; print " - " $2 ": " m }' fi if (( saltate > 0 )); then echo " Saltate, per motivo:" # The reason without the MSTest frame («Il metodo … ha generato un'eccezione. Assert.Inconclusive.»). printf '%s\n' "$righe" | awk -F'\t' "!($da_fare)"' && $1 != "Passed" && $1 != "Failed" && $1 != "Error" && $1 != "Timeout" && $1 != "Aborted" { m = $3; sub(/^.*Assert\.Inconclusive\. */, "", m); if (m == "") m = "(nessun motivo)"; print m }' \ | sort | uniq -c | sort -rn | awk 'NR <= 30 { sub(/^ */, " "); print }' fi if (( dafare > 0 )); then echo " Da fare (parti non ancora scritte, non contano come saltate):" printf '%s\n' "$righe" | awk -F'\t' "$da_fare"' { if (++n > 60) next; m = $3; sub(/^.*da fare: /, "da fare: ", m); print " - " m }' | sort fi done esito=0 { echo echo "Fallite: $fallite_totali · saltate: $saltate_totali (ammesse: $ammesse) · da fare: $dafare_totali." } >> "$riepilogo" if (( fallite_totali > 0 )); then echo "Prove fallite: $fallite_totali (i file .trx sono fra gli artefatti dell'esecuzione)." >&2 esito=1 fi if (( saltate_totali > ammesse )); then echo "Prove saltate: $saltate_totali, più delle $ammesse ammesse. Qui ci sono Chromium e Xvfb: una prova che si salta segnala un ambiente rotto, non una prova superata." >&2 esito=1 fi if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then cat "$riepilogo" >> "$GITHUB_STEP_SUMMARY" || true fi exit "$esito"