Skip to content

Instantly share code, notes, and snippets.

@yandod
Created June 17, 2011 21:21
Show Gist options
  • Save yandod/1032377 to your computer and use it in GitHub Desktop.
Save yandod/1032377 to your computer and use it in GitHub Desktop.
TAP (Test Anything Protocal) format test result to Jenkins readable xml.
#!/usr/bin/ruby
require 'rexml/document'
xml = REXML::Document.new
xml << REXML::XMLDecl.new('1.0', 'UTF-8')
testsuites = xml.add_element("testsuites")
#initialize vars
test_suite = nil
ok = 0
ng = 0
while line = gets
if (/exit/ =~ line)
break
end
if (/^# test:/ =~ line)
if (test_suite != nil)
test_suite.attributes["tests"] = ok + ng
test_suite.attributes["failuers"] = ng;
test_suite.attributes["errors"] = ng;
end
test_suite = testsuites.add_element("testsuite",{"name" => line[8..-1].chop})
ok = 0
ng = 0
end
if (/^ok / =~ line)
ok+=1
test_suite.add_element("testcase",{"name" => line.chop})
end
if (/^not ok/ =~ line)
ng+=1
test_suite.add_element("testcase",{"name" => line.chop}).add_element("error")
end
end
xml.write
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment