Class: Homebrew::TestBot::Junit Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Creates Junit report with only required by BuildPulse attributes See https://github.com/Homebrew/homebrew-test-bot/pull/621#discussion_r658712640
Instance Method Summary collapse
- #build(filters: nil) ⇒ void private
- #initialize(tests) ⇒ void constructor private
- #write(filename) ⇒ void private
Constructor Details
#initialize(tests) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 11 12 13 14 15 16 17 |
# File 'test_bot/junit.rb', line 10 def initialize(tests) require "rexml/document" require "rexml/xmldecl" require "rexml/cdata" @tests = tests @xml_document = T.let(nil, T.nilable(REXML::Document)) end |
Instance Method Details
#build(filters: nil) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'test_bot/junit.rb', line 20 def build(filters: nil) filters ||= [] @xml_document = REXML::Document.new @xml_document << REXML::XMLDecl.new testsuites = @xml_document.add_element "testsuites" @tests.each do |test| next if test.steps.empty? testsuite = testsuites.add_element "testsuite" testsuite.add_attribute "name", "brew-test-bot.#{Utils::Bottles.tag}" testsuite.add_attribute "timestamp", T.must(test.steps.fetch(0).start_time).iso8601 test.steps.each do |step| next unless filters.any? { |filter| step.command_short.start_with? filter } testcase = testsuite.add_element "testcase" testcase.add_attribute "name", step.command_short testcase.add_attribute "status", step.status testcase.add_attribute "time", step.time testcase.add_attribute "timestamp", T.must(step.start_time).iso8601 next if step.passed? elem = testcase.add_element "failure" elem.add_attribute "message", "#{step.status}: #{step.command.join(" ")}" end end end |
#write(filename) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
52 53 54 55 56 57 58 59 |
# File 'test_bot/junit.rb', line 52 def write(filename) output_path = Pathname(filename) output_path.unlink if output_path.exist? output_path.open("w") do |xml_file| pretty_print_indent = 2 T.must(@xml_document).write(xml_file, pretty_print_indent) end end |