Class: Trainer::TestParser

Inherits:
Object
  • Object
show all
Defined in:
lib/trainer/test_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, config = {}) ⇒ TestParser

Returns a new instance of TestParser.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/trainer/test_parser.rb', line 49

def initialize(path, config = {})
  path = File.expand_path(path)
  UI.user_error!("File not found at path '#{path}'") unless File.exist?(path)

  self.file_content = File.read(path)
  self.raw_json = Plist.parse_xml(self.file_content)
  return if self.raw_json["FormatVersion"].to_s.length.zero? # maybe that's a useless plist file

  ensure_file_valid!
  parse_content(config[:xcpretty_naming])
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/trainer/test_parser.rb', line 3

def data
  @data
end

#file_contentObject

Returns the value of attribute file_content.



5
6
7
# File 'lib/trainer/test_parser.rb', line 5

def file_content
  @file_content
end

#raw_jsonObject

Returns the value of attribute raw_json.



7
8
9
# File 'lib/trainer/test_parser.rb', line 7

def raw_json
  @raw_json
end

Class Method Details

.auto_convert(config) ⇒ Object

Returns a hash with the path being the key, and the value defining if the tests were successful



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
43
44
45
46
47
# File 'lib/trainer/test_parser.rb', line 11

def self.auto_convert(config)
  FastlaneCore::PrintTable.print_values(config: config,
                                         title: "Summary for trainer #{Trainer::VERSION}")

  containing_dir = config[:path]
  # Xcode < 10
  files = Dir["#{containing_dir}/**/Logs/Test/*TestSummaries.plist"]
  files += Dir["#{containing_dir}/Test/*TestSummaries.plist"]
  files += Dir["#{containing_dir}/*TestSummaries.plist"]
  # Xcode 10
  files += Dir["#{containing_dir}/**/Logs/Test/*.xcresult/TestSummaries.plist"]
  files += Dir["#{containing_dir}/Test/*.xcresult/TestSummaries.plist"]
  files += Dir["#{containing_dir}/*.xcresult/TestSummaries.plist"]
  files += Dir[containing_dir] if containing_dir.end_with?(".plist") # if it's the exact path to a plist file

  if files.empty?
    UI.user_error!("No test result files found in directory '#{containing_dir}', make sure the file name ends with 'TestSummaries.plist'")
  end

  return_hash = {}
  files.each do |path|
    if config[:output_directory]
      FileUtils.mkdir_p(config[:output_directory])
      filename = File.basename(path).gsub(".plist", config[:extension])
      to_path = File.join(config[:output_directory], filename)
    else
      to_path = path.gsub(".plist", config[:extension])
    end

    tp = Trainer::TestParser.new(path, config)
    File.write(to_path, tp.to_junit)
    puts "Successfully generated '#{to_path}'"

    return_hash[to_path] = tp.tests_successful?
  end
  return_hash
end

Instance Method Details

#tests_successful?Bool

Returns were all tests successful? Is false if at least one test failed.

Returns:

  • (Bool)

    were all tests successful? Is false if at least one test failed



67
68
69
# File 'lib/trainer/test_parser.rb', line 67

def tests_successful?
  self.data.collect { |a| a[:number_of_failures] }.all?(&:zero?)
end

#to_junitObject

Returns the JUnit report as String



62
63
64
# File 'lib/trainer/test_parser.rb', line 62

def to_junit
  JunitGenerator.new(self.data).generate
end