Class: Xccoveralls::Xccov
- Inherits:
-
Object
- Object
- Xccoveralls::Xccov
- Defined in:
- lib/xccoveralls/xccov.rb
Instance Attribute Summary collapse
-
#derived_data_path ⇒ Object
readonly
Returns the value of attribute derived_data_path.
-
#ignorefile_path ⇒ Object
readonly
Returns the value of attribute ignorefile_path.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
- #archive_path ⇒ Object
- #coverage(path) ⇒ Object
- #exec(args) ⇒ Object
- #file(path) ⇒ Object
- #file_paths ⇒ Object
- #files ⇒ Object
-
#initialize(derived_data_path: nil, source_path: nil, ignorefile_path: nil) ⇒ Xccov
constructor
A new instance of Xccov.
- #name(path) ⇒ Object
- #source_digest(path) ⇒ Object
- #test_logs_path ⇒ Object
- #to_json ⇒ Object
- #user_error!(msg) ⇒ Object
Constructor Details
#initialize(derived_data_path: nil, source_path: nil, ignorefile_path: nil) ⇒ Xccov
Returns a new instance of Xccov.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/xccoveralls/xccov.rb', line 10 def initialize( derived_data_path: nil, source_path: nil, ignorefile_path: nil ) @source_path = source_path @derived_data_path = derived_data_path @ignorefile_path = ignorefile_path || File.join( source_path, '.coverallsignore' ) end |
Instance Attribute Details
#derived_data_path ⇒ Object (readonly)
Returns the value of attribute derived_data_path.
7 8 9 |
# File 'lib/xccoveralls/xccov.rb', line 7 def derived_data_path @derived_data_path end |
#ignorefile_path ⇒ Object (readonly)
Returns the value of attribute ignorefile_path.
8 9 10 |
# File 'lib/xccoveralls/xccov.rb', line 8 def ignorefile_path @ignorefile_path end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
6 7 8 |
# File 'lib/xccoveralls/xccov.rb', line 6 def source_path @source_path end |
Instance Method Details
#archive_path ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/xccoveralls/xccov.rb', line 26 def archive_path return @archive_path if @archive_path ext = '.xccovarchive' files = Dir[File.join(test_logs_path, "*#{ext}")] @archive_path = files.sort_by { |filename| File.mtime(filename) } .reverse.first @archive_path || user_error!("Could not find any #{ext} in #{derived_data_path}") @archive_path end |
#coverage(path) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xccoveralls/xccov.rb', line 37 def coverage(path) file_paths.include?(path) || user_error!("No coverage data for #{path}") res = exec(['--file', "'#{path}'"]) res.split("\n").map do |line| line = line.strip.split(/[\s:]/).reject(&:empty?) next unless line[0] =~ /^\d+$/ hits = line[1] hits == '*' ? nil : hits.to_i end end |
#exec(args) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/xccoveralls/xccov.rb', line 92 def exec(args) cmd = %w[xcrun xccov view] + args + %W["#{archive_path}"] FastlaneCore::CommandExecutor.execute( command: cmd, print_command: false ).strip end |
#file(path) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/xccoveralls/xccov.rb', line 66 def file(path) { name: name(path), source_digest: source_digest(path), coverage: coverage(path) } end |
#file_paths ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/xccoveralls/xccov.rb', line 82 def file_paths return @file_paths if @file_paths paths = exec(%w[--file-list]).split("\n") if File.file?(ignorefile_path) ignore = Ignorefile.new(ignorefile_path) ignore.apply!(paths) end @file_paths = paths end |
#files ⇒ Object
74 75 76 |
# File 'lib/xccoveralls/xccov.rb', line 74 def files file_paths.map { |path| file(path) } end |
#name(path) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/xccoveralls/xccov.rb', line 58 def name(path) path.start_with?(source_path) || (return path) Pathname.new(path).relative_path_from( Pathname.new(source_path) ).to_s end |
#source_digest(path) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/xccoveralls/xccov.rb', line 49 def source_digest(path) File.file?(path) || user_error!("File at #{path} does not exist") FastlaneCore::CommandExecutor.execute( command: %w[git hash-object] + %W["#{path}"], print_command: false ).strip end |
#test_logs_path ⇒ Object
22 23 24 |
# File 'lib/xccoveralls/xccov.rb', line 22 def test_logs_path File.join derived_data_path, 'Logs', 'Test' end |
#to_json ⇒ Object
78 79 80 |
# File 'lib/xccoveralls/xccov.rb', line 78 def to_json { source_files: files } end |
#user_error!(msg) ⇒ Object
102 103 104 |
# File 'lib/xccoveralls/xccov.rb', line 102 def user_error!(msg) FastlaneCore::UI.user_error!(msg) end |