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



54
55
56
57
58
59
# File 'lib/slather/profdata_coverage_file.rb', line 54

def all_lines
  if @all_lines == nil
    @all_lines = source_code_lines
  end
  @all_lines
end

#branch_coverage_dataObject



127
128
129
130
131
# File 'lib/slather/profdata_coverage_file.rb', line 127

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

#cleaned_gcov_dataObject



61
62
63
# File 'lib/slather/profdata_coverage_file.rb', line 61

def cleaned_gcov_data
  source_data
end

#coverage_for_line(line) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/slather/profdata_coverage_file.rb', line 98

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

  if $2 == nil
    # Check for thousands or millions (llvm-cov outputs hit counts as 25.3k or 3.8M)
    did_match = line =~ /^(\s*)(\d+\.\d+)(k|M)\|/

    if did_match
      count = $2.strip
      units = $3 == 'k' ? 1000 : 1000000

      (count.to_f * units).to_i
    else
      return nil
    end
  else
    match = $2.strip
    case match
    when /[0-9]+/
      match.to_i
    when /#+/
      0
    when "-"
      nil
    end
  end
end

#ignored?Boolean

Returns:

  • (Boolean)


146
147
148
149
150
151
152
153
154
155
# File 'lib/slather/profdata_coverage_file.rb', line 146

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



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

def line_coverage_data
  source_code_lines.map do |line|
    coverage_for_line(line)
  end
end

#line_number_in_line(line) ⇒ Object



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

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
  else
    # llvm-cov outputs hit counts as 25.3k or 3.8M, so check this pattern as well
    did_match = line =~ /^(\s*)(\d+\.\d+)(k|M)\|(\s*)(\d+)\|/

    if did_match
      match = $5.strip
      case match
        when /[0-9]+/
          return match.to_i
      end
    end
  end
  0
end

#line_number_separatorObject



137
138
139
# File 'lib/slather/profdata_coverage_file.rb', line 137

def line_number_separator
  "|"
end

#path_on_first_line?Boolean

Returns:

  • (Boolean)


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

def path_on_first_line?
  path = self.source.split("\n")[0].sub ":", ""
  !path.include?("1|//")
end

#raw_dataObject



65
66
67
# File 'lib/slather/profdata_coverage_file.rb', line 65

def raw_data
  self.source
end

#source_code_linesObject



46
47
48
# File 'lib/slather/profdata_coverage_file.rb', line 46

def source_code_lines
  self.source.split("\n")[(path_on_first_line? ? 1 : 0)..-1]
end

#source_dataObject



50
51
52
# File 'lib/slather/profdata_coverage_file.rb', line 50

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

#source_fileObject



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

def source_file
  File.new(source_file_pathname)
end

#source_file_basenameObject



133
134
135
# File 'lib/slather/profdata_coverage_file.rb', line 133

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

#source_file_pathnameObject



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

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

#source_file_pathname=(source_file_pathname) ⇒ Object



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

def source_file_pathname= (source_file_pathname)
    @source_file_pathname = source_file_pathname
end