Class: Trainer::TestParser
- Inherits:
-
Object
- Object
- Trainer::TestParser
- Defined in:
- lib/trainer/test_parser.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#file_content ⇒ Object
Returns the value of attribute file_content.
-
#raw_json ⇒ Object
Returns the value of attribute raw_json.
Class Method Summary collapse
-
.auto_convert(config) ⇒ Object
Returns a hash with the path being the key, and the value defining if the tests were successful.
Instance Method Summary collapse
-
#initialize(path, config = {}) ⇒ TestParser
constructor
A new instance of TestParser.
-
#tests_successful? ⇒ Bool
Were all tests successful? Is false if at least one test failed.
-
#to_junit ⇒ Object
Returns the JUnit report as String.
Constructor Details
#initialize(path, config = {}) ⇒ TestParser
Returns a new instance of TestParser.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/trainer/test_parser.rb', line 64 def initialize(path, config = {}) path = File.(path) UI.user_error!("File not found at path '#{path}'") unless File.exist?(path) if File.directory?(path) && path.end_with?(".xcresult") parse_xcresult(path) else 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 end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/trainer/test_parser.rb', line 3 def data @data end |
#file_content ⇒ Object
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_json ⇒ Object
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 # Xcode 11 files += Dir["#{containing_dir}/**/Logs/Test/*.xcresult"] files += Dir["#{containing_dir}/Test/*.xcresult"] files += Dir["#{containing_dir}/*.xcresult"] files << containing_dir if File.extname(containing_dir) == ".xcresult" if files.empty? UI.user_error!("No test result files found in directory '#{containing_dir}', make sure the file name ends with 'TestSummaries.plist' or '.xcresult'") end return_hash = {} files.each do |path| if config[:output_directory] FileUtils.mkdir_p(config[:output_directory]) # Remove .xcresult or .plist extension if path.end_with?(".xcresult") filename = File.basename(path).gsub(".xcresult", config[:extension]) else filename = File.basename(path).gsub(".plist", config[:extension]) end to_path = File.join(config[:output_directory], filename) else # Remove .xcresult or .plist extension if path.end_with?(".xcresult") to_path = path.gsub(".xcresult", config[:extension]) else to_path = path.gsub(".plist", config[:extension]) end 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.
87 88 89 |
# File 'lib/trainer/test_parser.rb', line 87 def tests_successful? self.data.collect { |a| a[:number_of_failures] }.all?(&:zero?) end |
#to_junit ⇒ Object
Returns the JUnit report as String
82 83 84 |
# File 'lib/trainer/test_parser.rb', line 82 def to_junit JunitGenerator.new(self.data).generate end |