Class: Slather::ProfdataCoverageFile

Inherits:
Object
  • Object
show all
Includes:
CoverageInfo, CoverallsCoverage
Defined in:
lib/slather/profdata_coverage_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CoverallsCoverage

#as_json

Methods included from CoverageInfo

#branch_coverage_data_for_statement_on_line, #num_branch_hits_for_statement_on_line, #num_branches_for_statement_on_line, #num_branches_testable, #num_branches_tested, #num_lines_testable, #num_lines_tested, #percentage_branch_coverage_for_statement_on_line, #percentage_lines_tested, #rate_branch_coverage_for_statement_on_line, #rate_branches_tested, #rate_lines_tested, #source_file_pathname_relative_to_repo_root

Constructor Details

#initialize(project, source) ⇒ ProfdataCoverageFile

Returns a new instance of ProfdataCoverageFile.



12
13
14
15
16
# File 'lib/slather/profdata_coverage_file.rb', line 12

def initialize(project, source)
  self.project = project
  self.source = source
  create_line_data
end

Instance Attribute Details

#line_dataObject

Returns the value of attribute line_data.



10
11
12
# File 'lib/slather/profdata_coverage_file.rb', line 10

def line_data
  @line_data
end

#projectObject

Returns the value of attribute project.



10
11
12
# File 'lib/slather/profdata_coverage_file.rb', line 10

def project
  @project
end

#sourceObject

Returns the value of attribute source.



10
11
12
# File 'lib/slather/profdata_coverage_file.rb', line 10

def source
  @source
end

Instance Method Details

#all_linesObject



41
42
43
44
45
46
# File 'lib/slather/profdata_coverage_file.rb', line 41

def all_lines
  if @all_lines == nil
    @all_lines = self.source.split("\n")[1..-1]
  end
  @all_lines
end

#branch_coverage_dataObject



93
94
95
96
97
# File 'lib/slather/profdata_coverage_file.rb', line 93

def branch_coverage_data
  @branch_coverage_data ||= begin
    Hash.new
  end
end

#cleaned_gcov_dataObject



48
49
50
# File 'lib/slather/profdata_coverage_file.rb', line 48

def cleaned_gcov_data
  source_data
end

#coverage_for_line(line) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/slather/profdata_coverage_file.rb', line 74

def coverage_for_line(line)
  line = line.gsub(":", "|")
  line =~ /^(\s*)(\d*)\|/

  if $2 == nil
    return nil
  end

  match = $2.strip
  case match
  when /[0-9]+/
    match.to_i
  when /#+/
    0
  when "-"
    nil
  end
end

#ignored?Boolean

Returns:

  • (Boolean)


112
113
114
115
116
117
118
119
120
121
# File 'lib/slather/profdata_coverage_file.rb', line 112

def ignored?
  ignore = false
  platform_ignore_list.map do |ignore_suffix|
    ignore = source_file_pathname.to_s.end_with? ignore_suffix
    if ignore
      break
    end
  end
  ignore ? ignore : super
end

#line_coverage_dataObject



68
69
70
71
72
# File 'lib/slather/profdata_coverage_file.rb', line 68

def line_coverage_data
  self.source.split("\n")[1..-1].map do |line|
    coverage_for_line(line)
  end
end

#line_number_in_line(line) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/slather/profdata_coverage_file.rb', line 56

def line_number_in_line(line)
  line =~ /^(\s*)(\d*)\|(\s*)(\d+)\|/
  if $4 != nil
    match = $4.strip
    case match
      when /[0-9]+/
        return match.to_i
    end
  end
  0
end

#line_number_separatorObject



103
104
105
# File 'lib/slather/profdata_coverage_file.rb', line 103

def line_number_separator
  "|"
end

#raw_dataObject



52
53
54
# File 'lib/slather/profdata_coverage_file.rb', line 52

def raw_data
  self.source
end

#source_dataObject



37
38
39
# File 'lib/slather/profdata_coverage_file.rb', line 37

def source_data
  all_lines.join("\n")
end

#source_fileObject



33
34
35
# File 'lib/slather/profdata_coverage_file.rb', line 33

def source_file
  File.new(source_file_pathname)
end

#source_file_basenameObject



99
100
101
# File 'lib/slather/profdata_coverage_file.rb', line 99

def source_file_basename
  File.basename(source_file_pathname, '.swift')
end

#source_file_pathnameObject



26
27
28
29
30
31
# File 'lib/slather/profdata_coverage_file.rb', line 26

def source_file_pathname
  @source_file_pathname ||= begin
    path = self.source.split("\n")[0].sub ":", ""
    path &&= Pathname(path)
  end
end