Class: Fastlane::Helper::ForsisHelper::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/forsis/helper/forsis_helper.rb

Class Method Summary collapse

Class Method Details

.generate(junit_report_path, sonarqube_report_path) ⇒ Object



7
8
9
10
11
12
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
# File 'lib/fastlane/plugin/forsis/helper/forsis_helper.rb', line 7

def self.generate(junit_report_path, sonarqube_report_path)
  junit_file = Nokogiri::XML(File.open(junit_report_path))
  sonarqube_file = File.open("#{sonarqube_report_path}/Test_sonarqube_report.xml", 'w')
  test_suites = junit_file.xpath("//testsuite")
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.testExecutions({ version: :'1' }) do
      test_suites.each do |test_file|
        file_name = `echo #{test_file["name"]}| cut -d'.' -f 2`.gsub(/\n/, '')
        file_path = get_test_file_path(file_name)
        test_cases = []
        test_file.children.each do |child|
          test_cases << child if child.instance_of?(Nokogiri::XML::Element)
        end
        xml.file({ path: :"#{file_path}" }) do
          test_cases.each do |test|
            test_duration = (test["time"].to_f * 1000).round
            test_failures = []
            test.children.each do |test_child|
              test_failures << test_child if test_child.instance_of?(Nokogiri::XML::Element)
            end
            xml.testCase({ name: :"#{test["name"]}", duration: :"#{test_duration}" }) do
              test_failures.each do |failure|
                failure_type = failure.name
                failure_message = failure["message"]
                failure_description = failure.text
                xml.send(failure_type, failure_description, message: failure_message)
              end
            end
          end
        end
      end
    end
  end
  sonarqube_file.puts(builder.to_xml)
  sonarqube_file.close
end

.get_test_file_path(file_name) ⇒ Object



44
45
46
# File 'lib/fastlane/plugin/forsis/helper/forsis_helper.rb', line 44

def self.get_test_file_path(file_name)
  `find . -iname "#{file_name}.swift"`.gsub(/\n/, '')
end