brew-test-bot: add optional JUnit support.

This commit is contained in:
Mike McQuaid 2013-05-25 21:32:43 +01:00
parent 05f92b5c98
commit b1f00c5757

View File

@ -6,15 +6,17 @@
# --keep-logs: Write and keep log files under ./brewbot/ # --keep-logs: Write and keep log files under ./brewbot/
# --cleanup: Clean the Homebrew directory. Very dangerous. Use with care. # --cleanup: Clean the Homebrew directory. Very dangerous. Use with care.
# --skip-setup: Don't check the local system is setup correctly. # --skip-setup: Don't check the local system is setup correctly.
# --junit: Generate a JUnit XML test results file.
require 'formula' require 'formula'
require 'utils' require 'utils'
require 'date' require 'date'
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 attr_reader :command, :repository, :name
attr_accessor :status attr_accessor :status
def initialize test, command def initialize test, command
@ -269,17 +271,16 @@ class Test
status == :passed status == :passed
end end
def self.run argument def run
test = new argument cleanup_before
test.cleanup_before download
test.download setup unless ARGV.include? "--skip-setup"
test.setup unless ARGV.include? "--skip-setup" formulae.each do |f|
test.formulae.each do |formula| formula(f)
test.formula formula
end end
test.homebrew if test.core_changed homebrew if core_changed
test.cleanup_after cleanup_after
test.check_results check_results
end end
end end
@ -287,11 +288,27 @@ if Pathname.pwd == HOMEBREW_PREFIX and ARGV.include? "--cleanup"
odie 'cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output.' odie 'cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output.'
end end
tests = []
any_errors = false any_errors = false
if ARGV.named.empty? if ARGV.named.empty?
# With no arguments just build the most recent commit. # With no arguments just build the most recent commit.
any_errors = Test.run 'HEAD' test = Test.new('HEAD')
any_errors = test.run
tests << test
else else
ARGV.named.each { |argument| any_errors = Test.run(argument) or any_errors } ARGV.named.each do |argument|
test = Test.new(argument)
any_errors = test.run or any_errors
tests << test
end end
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|
xml.write erb.result binding
end
end
exit any_errors ? 0 : 1 exit any_errors ? 0 : 1