brew-test-bot: add times, cleanup JUnit output.
This commit is contained in:
parent
892d601465
commit
f0008a7e8f
@ -16,7 +16,7 @@ require 'erb'
|
|||||||
HOMEBREW_CONTRIBUTED_CMDS = HOMEBREW_REPOSITORY + "Library/Contributions/cmd/"
|
HOMEBREW_CONTRIBUTED_CMDS = HOMEBREW_REPOSITORY + "Library/Contributions/cmd/"
|
||||||
|
|
||||||
class Step
|
class Step
|
||||||
attr_reader :command, :name, :status, :output
|
attr_reader :command, :name, :status, :output, :time
|
||||||
|
|
||||||
def initialize test, command, puts_output_on_success = false
|
def initialize test, command, puts_output_on_success = false
|
||||||
@test = test
|
@test = test
|
||||||
@ -26,6 +26,7 @@ class Step
|
|||||||
@name = command.split[1].delete '-'
|
@name = command.split[1].delete '-'
|
||||||
@status = :running
|
@status = :running
|
||||||
@repository = HOMEBREW_REPOSITORY
|
@repository = HOMEBREW_REPOSITORY
|
||||||
|
@time = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_file_path full_path=true
|
def log_file_path full_path=true
|
||||||
@ -46,8 +47,8 @@ class Step
|
|||||||
@status.to_s.upcase
|
@status.to_s.upcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def passed?
|
def failed?
|
||||||
@status == :passed
|
@status == :failed
|
||||||
end
|
end
|
||||||
|
|
||||||
def puts_command
|
def puts_command
|
||||||
@ -61,9 +62,14 @@ class Step
|
|||||||
puts "#{Tty.send status_colour}#{status_upcase}#{Tty.reset}"
|
puts "#{Tty.send status_colour}#{status_upcase}#{Tty.reset}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_output?
|
||||||
|
@output and @output.any?
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
puts_command
|
puts_command
|
||||||
|
|
||||||
|
start_time = Time.now
|
||||||
run_command = "#{@command} &>#{log_file_path}"
|
run_command = "#{@command} &>#{log_file_path}"
|
||||||
if run_command.start_with? 'git '
|
if run_command.start_with? 'git '
|
||||||
Dir.chdir @repository do
|
Dir.chdir @repository do
|
||||||
@ -72,6 +78,8 @@ class Step
|
|||||||
else
|
else
|
||||||
`#{run_command}`
|
`#{run_command}`
|
||||||
end
|
end
|
||||||
|
end_time = Time.now
|
||||||
|
@time = end_time - start_time
|
||||||
|
|
||||||
success = $?.success?
|
success = $?.success?
|
||||||
@status = success ? :passed : :failed
|
@status = success ? :passed : :failed
|
||||||
@ -79,8 +87,7 @@ class Step
|
|||||||
|
|
||||||
return unless File.exists?(log_file_path)
|
return unless File.exists?(log_file_path)
|
||||||
@output = IO.read(log_file_path)
|
@output = IO.read(log_file_path)
|
||||||
if @output and @output.any? \
|
if has_output? and (not success or @puts_output_on_success)
|
||||||
and (not success or @puts_output_on_success)
|
|
||||||
puts @output
|
puts @output
|
||||||
end
|
end
|
||||||
FileUtils.rm log_file_path unless ARGV.include? "--keep-logs"
|
FileUtils.rm log_file_path unless ARGV.include? "--keep-logs"
|
||||||
@ -310,7 +317,8 @@ if ARGV.include? "--junit"
|
|||||||
xml_erb = HOMEBREW_CONTRIBUTED_CMDS + "brew-test-bot.xml.erb"
|
xml_erb = HOMEBREW_CONTRIBUTED_CMDS + "brew-test-bot.xml.erb"
|
||||||
erb = ERB.new IO.read xml_erb
|
erb = ERB.new IO.read xml_erb
|
||||||
open("brew-test-bot.xml", "w") do |xml|
|
open("brew-test-bot.xml", "w") do |xml|
|
||||||
xml.write erb.result binding
|
# Remove empty lines from ERB result.
|
||||||
|
xml.write erb.result(binding).gsub /^\s*$\n/, ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<% tests.each do |test| %>
|
<testsuites>
|
||||||
<testsuite name="<%= test.name %>" tests="<%= test.steps.count %>">
|
<% tests.each do |test| %>
|
||||||
<% test.steps.each do |step| %>
|
<testsuite name="<%= test.name %>" package="brew-test-bot" tests="<%= test.steps.count %>">
|
||||||
<testcase name="<%= step.name %>" status="<%= step.status %>">
|
<% test.steps.each do |step| %>
|
||||||
<system-out><![CDATA[<%= step.output %>]]></system-out>
|
<testcase name="<%= step.name %>" status="<%= step.status %>" time="<%= step.time %>">
|
||||||
<% unless step.passed? %>
|
<% if step.has_output? %>
|
||||||
|
<system-out><![CDATA[<%= step.output %>]]></system-out>
|
||||||
|
<% end %>
|
||||||
|
<% if step.failed? %>
|
||||||
<failure />
|
<failure />
|
||||||
|
<% end %>
|
||||||
|
</testcase>
|
||||||
<% end %>
|
<% end %>
|
||||||
</testcase>
|
</testsuite>
|
||||||
<% end %>
|
<% end %>
|
||||||
</testsuite>
|
<testsuites>
|
||||||
<% end %>
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user