Class: Homebrew::TestBot::Junit Private

Inherits:
Object
  • Object
show all
Defined in:
test_bot/junit.rb

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

Constructor Details

#initialize(tests) ⇒ Junit

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.

Returns a new instance of Junit.



9
10
11
# File 'test_bot/junit.rb', line 9

def initialize(tests)
  @tests = tests
end

Instance Method Details

#build(filters: nil) ⇒ Object

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.



13
14
15
16
17
18
19
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
# File 'test_bot/junit.rb', line 13

def build(filters: nil)
  filters ||= []

  require "rexml/document"
  require "rexml/xmldecl"
  require "rexml/cdata"

  @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", test.steps.first.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", 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) ⇒ Object

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.



48
49
50
51
52
53
54
55
# File 'test_bot/junit.rb', line 48

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
    @xml_document.write(xml_file, pretty_print_indent)
  end
end