#!/usr/bin/env bash # Copyright (C) 2018 Luke Shumaker # SPDX-License-Identifier: AGPL-3.0-or-later test='' output='' is_tap=maybe while read -r line; do if [[ $line = '--x-- '*' --x--' ]]; then is_tap=false msg=${line#'--x-- '} msg=${msg%' --x--'} case "$msg" in 'Running '*) test=${msg#'Running '} output="$line"$'\n' ;; 'Result of '*) output+="$line"$'\n' result=${msg##*:} n=${test#TEST-} n=${n%%-*} if (( result == 0 )); then printf 'ok %d %s\n' "${n#0}" "$test" else printf 'not ok %d %s\n' "${n#0}" "$test" fi printf '%s' "$output" | sed 's/^/# /' test='' output='' ;; esac else if [[ $is_tap = maybe && ( $line = TAP* || $line = 1..* ) ]]; then # Maybe I'll convince upstream to emit TAP... printf '%s\n' "$line" sed '$d' exit 0 fi if [[ -n $test ]]; then output+="$line"$'\n' else case "$line" in 'ALL '*' TESTS PASSED') m=${line#'ALL '} m=${m%%' '*} printf '1..%d\n' "${m#0}" exit 0 :;; 'TOTAL FAILURES: '*' OF '*) m=${line##*' '} printf '1..%d\n' "${m#0}" exit 0 :;; *) : # discard ;; esac fi fi done < <(sed 's/\r$//' | cat -v) echo 'Bail out!'