74 lines
1.3 KiB
Plaintext
74 lines
1.3 KiB
Plaintext
|
#!/usr/bin/env ruby
|
||
|
require 'yaml'
|
||
|
|
||
|
def indent(para, depth)
|
||
|
pfix = " "*depth
|
||
|
return para.lines.map{|line|pfix+line}.join
|
||
|
end
|
||
|
|
||
|
def bail(reason)
|
||
|
abort("Bail out! #{reason}")
|
||
|
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
|