aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2013-10-08 16:32:59 +0100
committerMike McQuaid2013-10-08 16:45:22 +0100
commit01901314e9303ddb40b391d7fab781c5de032371 (patch)
treed8b8006eec65e18b9bf753ba35121a328b516ddf /Library
parent85c1e5d02e9b136e25ea5a5fd0cae79ace73cbf6 (diff)
downloadbrew-01901314e9303ddb40b391d7fab781c5de032371.tar.bz2
brew-test-bot: use REXML to write JUnit file.
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/Contributions/cmd/brew-test-bot.rb39
-rw-r--r--Library/Contributions/cmd/brew-test-bot.xml.erb20
2 files changed, 33 insertions, 26 deletions
diff --git a/Library/Contributions/cmd/brew-test-bot.rb b/Library/Contributions/cmd/brew-test-bot.rb
index f035eddef..f0e60da89 100755
--- a/Library/Contributions/cmd/brew-test-bot.rb
+++ b/Library/Contributions/cmd/brew-test-bot.rb
@@ -15,7 +15,9 @@
require 'formula'
require 'utils'
require 'date'
-require 'erb'
+require 'rexml/document'
+require 'rexml/xmldecl'
+require 'rexml/cdata'
EMAIL_SUBJECT_FILE = "brew-test-bot.#{MacOS.cat}.email.txt"
HOMEBREW_CONTRIBUTED_CMDS = HOMEBREW_REPOSITORY + "Library/Contributions/cmd/"
@@ -395,11 +397,36 @@ else
end
if ARGV.include? "--junit"
- xml_erb = HOMEBREW_CONTRIBUTED_CMDS + "brew-test-bot.xml.erb"
- erb = ERB.new IO.read xml_erb
- open("brew-test-bot.xml", "w") do |xml|
- # Remove empty lines and null characters from ERB result.
- xml.write erb.result(binding).gsub(/^\s*$\n|\000/, '')
+ xml_document = REXML::Document.new
+ xml_document << REXML::XMLDecl.new
+ testsuites = xml_document.add_element 'testsuites'
+ tests.each do |test|
+ testsuite = testsuites.add_element 'testsuite'
+ testsuite.attributes['name'] = "brew-test-bot.#{MacOS.cat}"
+ testsuite.attributes['tests'] = test.steps.count
+ test.steps.each do |step|
+ testcase = testsuite.add_element 'testcase'
+ testcase.attributes['name'] = step.command_short
+ testcase.attributes['status'] = step.status
+ testcase.attributes['time'] = step.time
+ failure = testcase.add_element 'failure' if step.failed?
+ if step.has_output?
+ # Remove null characters from step output.
+ output = REXML::CData.new step.output.delete("\000")
+ if step.passed?
+ system_out = testcase.add_element 'system-out'
+ system_out.text = output
+ else
+ failure.attributes['message'] = "#{step.status}: #{step.command}"
+ failure.text = output
+ end
+ end
+ end
+ end
+
+ open("brew-test-bot.xml", "w") do |xml_file|
+ pretty_print_indent = 2
+ xml_document.write(xml_file, pretty_print_indent)
end
end
diff --git a/Library/Contributions/cmd/brew-test-bot.xml.erb b/Library/Contributions/cmd/brew-test-bot.xml.erb
deleted file mode 100644
index 7007c54b4..000000000
--- a/Library/Contributions/cmd/brew-test-bot.xml.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<testsuites>
- <% tests.each do |test| %>
- <testsuite name="brew-test-bot.<%= MacOS.cat %>" tests="<%= test.steps.count %>">
- <% test.steps.each do |step| %>
- <testcase name="<%= step.command_short %>" status="<%= step.status %>" time="<%= step.time %>">
- <% if step.has_output? %>
- <% if step.failed? %>
- <failure message="<%= step.status %>: <%= step.command %>"><![CDATA[<%= step.output %>]]></failure>
- <% else %>
- <system-out><![CDATA[<%= step.output %>]]></system-out>
- <% end %>
- <% elsif step.failed? %>
- <failure />
- <% end %>
- </testcase>
- <% end %>
- </testsuite>
- <% end %>
-</testsuites>