osi-tools/meson2tap

78 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-08-18 17:31:20 +00:00
#!/usr/bin/env ruby
2018-08-18 18:42:42 +00:00
# Copyright (C) 2018 Luke Shumaker
# SPDX-License-Identifier: AGPL-3.0-or-later
2018-08-18 18:19:11 +00:00
2018-08-18 17:31:20 +00:00
require 'yaml'
def indent(para, depth)
pfix = " "*depth
return para.lines.map{|line|pfix+line}.join
end
def bail(reason)
2018-08-18 18:19:11 +00:00
puts "Bail out! #{reason}"
exit
2018-08-18 17:31:20 +00:00
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