summaryrefslogtreecommitdiff
path: root/meson2tap
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-18 13:31:20 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-18 13:31:20 -0400
commit1bec95dbb31f75fa5ba4e43d2ef5e0d4f0f7460d (patch)
tree1286255371f8dfa3171a9a27b2d63e7b0883e5f5 /meson2tap
parenta804dc133f0a3ad59d85052bb702530fe4e35751 (diff)
Generate a TAP file for the unit tests
Diffstat (limited to 'meson2tap')
-rwxr-xr-xmeson2tap73
1 files changed, 73 insertions, 0 deletions
diff --git a/meson2tap b/meson2tap
new file mode 100755
index 0000000..9f72610
--- /dev/null
+++ b/meson2tap
@@ -0,0 +1,73 @@
+#!/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