summaryrefslogtreecommitdiff
path: root/integration2tap
blob: d0435cc4a59d84293ce8e254a2ecf51460e93904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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!'