brew-test-bot: improve JUnit output.
This commit is contained in:
parent
052293f22c
commit
892d601465
@ -16,17 +16,16 @@ 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, :repository, :name
|
attr_reader :command, :name, :status, :output
|
||||||
attr_accessor :status
|
|
||||||
|
|
||||||
def initialize test, command
|
def initialize test, command, puts_output_on_success = false
|
||||||
@test = test
|
@test = test
|
||||||
@category = test.category
|
@category = test.category
|
||||||
@command = command
|
@command = command
|
||||||
|
@puts_output_on_success = puts_output_on_success
|
||||||
@name = command.split[1].delete '-'
|
@name = command.split[1].delete '-'
|
||||||
@status = :running
|
@status = :running
|
||||||
@repository = HOMEBREW_REPOSITORY
|
@repository = HOMEBREW_REPOSITORY
|
||||||
@test.steps << self
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_file_path full_path=true
|
def log_file_path full_path=true
|
||||||
@ -47,6 +46,10 @@ class Step
|
|||||||
@status.to_s.upcase
|
@status.to_s.upcase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def passed?
|
||||||
|
@status == :passed
|
||||||
|
end
|
||||||
|
|
||||||
def puts_command
|
def puts_command
|
||||||
print "#{Tty.blue}==>#{Tty.white} #{@command}#{Tty.reset}"
|
print "#{Tty.blue}==>#{Tty.white} #{@command}#{Tty.reset}"
|
||||||
tabs = (80 - "PASSED".length + 1 - @command.length) / 8
|
tabs = (80 - "PASSED".length + 1 - @command.length) / 8
|
||||||
@ -58,36 +61,34 @@ class Step
|
|||||||
puts "#{Tty.send status_colour}#{status_upcase}#{Tty.reset}"
|
puts "#{Tty.send status_colour}#{status_upcase}#{Tty.reset}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run test, command, puts_output_on_success = false
|
def run
|
||||||
step = new test, command
|
puts_command
|
||||||
step.puts_command
|
|
||||||
|
|
||||||
command = "#{step.command} &>#{step.log_file_path}"
|
run_command = "#{@command} &>#{log_file_path}"
|
||||||
if command.start_with? 'git '
|
if run_command.start_with? 'git '
|
||||||
Dir.chdir step.repository do
|
Dir.chdir @repository do
|
||||||
`#{command}`
|
`#{run_command}`
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
`#{command}`
|
`#{run_command}`
|
||||||
end
|
end
|
||||||
|
|
||||||
success = $?.success?
|
success = $?.success?
|
||||||
step.status = success ? :passed : :failed
|
@status = success ? :passed : :failed
|
||||||
step.puts_result
|
puts_result
|
||||||
|
|
||||||
return unless File.exists?(step.log_file_path)
|
return unless File.exists?(log_file_path)
|
||||||
output = IO.read(step.log_file_path)
|
@output = IO.read(log_file_path)
|
||||||
if output and output.any? and (not success or puts_output_on_success)
|
if @output and @output.any? \
|
||||||
puts output
|
and (not success or @puts_output_on_success)
|
||||||
|
puts @output
|
||||||
end
|
end
|
||||||
FileUtils.rm step.log_file_path unless ARGV.include? "--keep-logs"
|
FileUtils.rm log_file_path unless ARGV.include? "--keep-logs"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Test
|
class Test
|
||||||
attr_reader :log_root, :category, :name
|
attr_reader :log_root, :category, :name, :core_changed, :formulae, :steps
|
||||||
attr_reader :core_changed, :formulae
|
|
||||||
attr_accessor :steps
|
|
||||||
|
|
||||||
def initialize argument
|
def initialize argument
|
||||||
@hash = nil
|
@hash = nil
|
||||||
@ -249,7 +250,9 @@ class Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test cmd, puts_output_on_success = false
|
def test cmd, puts_output_on_success = false
|
||||||
Step.run self, cmd, puts_output_on_success
|
step = Step.new self, cmd, puts_output_on_success
|
||||||
|
step.run
|
||||||
|
steps << step
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_results
|
def check_results
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuites name="brew-test-bot">
|
<% tests.each do |test| %>
|
||||||
<% tests.each do |test| %>
|
<testsuite name="<%= test.name %>" tests="<%= test.steps.count %>">
|
||||||
<testsuite name="<%= test.name %>" tests="<%= test.steps.count %>">
|
<% test.steps.each do |step| %>
|
||||||
<% test.steps.each do |step| %>
|
<testcase name="<%= step.name %>" status="<%= step.status %>">
|
||||||
<testcase name="<%= step.name %>" status="<%= step.status %>">
|
<system-out><![CDATA[<%= step.output %>]]></system-out>
|
||||||
<% unless step.status == :passed %>
|
<% unless step.passed? %>
|
||||||
<failure />
|
<failure />
|
||||||
<% end %>
|
|
||||||
</testcase>
|
|
||||||
<% end %>
|
|
||||||
</testsuite>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</testsuites>
|
</testcase>
|
||||||
|
<% end %>
|
||||||
|
</testsuite>
|
||||||
|
<% end %>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user