summaryrefslogtreecommitdiff
path: root/meson2tap
blob: 79b8b17b8461a9e99b0f027ff797590aa9fbf6b9 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env ruby
# Copyright (C) 2018  Luke Shumaker
# SPDX-License-Identifier: AGPL-3.0-or-later

require 'yaml'

def indent(para, depth)
	pfix = " "*depth
	return para.lines.map{|line|pfix+line}.join
end

def bail(reason)
	puts "Bail out! #{reason}"
	exit
end

puts "TAP version 13"
section = nil
yblock = nil
plan = nil
head = ""
STDIN.each_line do |line|
	if section.nil?
		case line.chomp
		when /^--- (.*) ---$/
			section = $1
			yblock[section] = ""
		when /^\s*$/
		# ignore
		when /^\s*([0-9]+)\/([0-9]+) (.*\S)\s+(OK|FAIL|SKIP)\s+(\S* \S*) (.*)$/
			n = $1
			m = $2
			if plan.nil?
				puts "1..#{m}"
				plan = m
				print head
			elsif m != plan
				bail("m:#{m} != plan:#{plan}")
			end
			name = $3
			result = $4
			duration = $5
			comment = $6
			case result
			when "OK"
				puts "ok #{n} #{name}"
			when "FAIL"
				puts "not ok #{n} #{name}"
			when "SKIP"
				puts "ok #{n} #{name} # SKIP"
			else
				bail("unparsable line: #{line}")
			end
			yblock = {}
			yblock['_duration'] = duration
			yblock['_exitstatus'] = comment
		else
			if plan.nil?
				head += "# #{line}"
			else
				print "# #{line}"
			end
		end
	else
		case line.chomp
		when "-------"
			puts indent(YAML::dump(yblock), 4)
			yblock = nil
			section = nil
		when /^--- (.*) ---$/
			section = $1
			yblock[section] = ""
		else
			yblock[section] += line
		end
	end
end