Module: Slather::CoverageInfo

Included in:
CoverageFile, ProfdataCoverageFile
Defined in:
lib/slather/coverage_info.rb

Instance Method Summary collapse

Instance Method Details

#branch_coverage_data_for_statement_on_line(line_number) ⇒ Object



28
29
30
# File 'lib/slather/coverage_info.rb', line 28

def branch_coverage_data_for_statement_on_line(line_number)
  branch_coverage_data[line_number] || []
end

#ignored?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/slather/coverage_info.rb', line 77

def ignored?
  project.ignore_list.any? do |ignore|
    File.fnmatch(ignore, source_file_pathname_relative_to_repo_root)
  end
end

#include_file?Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
# File 'lib/slather/coverage_info.rb', line 83

def include_file?
  rv = true # default true return value to fix https://github.com/SlatherOrg/slather/issues/561
  project.source_files.any? do |include|
    rv = File.fnmatch(include, source_file_pathname_relative_to_repo_root)
  end

  rv
end

#num_branch_hits_for_statement_on_line(line_number) ⇒ Object



36
37
38
# File 'lib/slather/coverage_info.rb', line 36

def num_branch_hits_for_statement_on_line(line_number)
  branch_coverage_data_for_statement_on_line(line_number).count { |hit_count| hit_count > 0 }
end

#num_branches_for_statement_on_line(line_number) ⇒ Object



32
33
34
# File 'lib/slather/coverage_info.rb', line 32

def num_branches_for_statement_on_line(line_number)
  branch_coverage_data_for_statement_on_line(line_number).length
end

#num_branches_testableObject



53
54
55
56
57
# File 'lib/slather/coverage_info.rb', line 53

def num_branches_testable
  branch_coverage_data.keys.reduce(0) do |sum, line_number|
    sum += num_branches_for_statement_on_line(line_number)
  end
end

#num_branches_testedObject



59
60
61
62
63
# File 'lib/slather/coverage_info.rb', line 59

def num_branches_tested
  branch_coverage_data.keys.reduce(0) do |sum, line_number|
    sum += num_branch_hits_for_statement_on_line(line_number)
  end
end

#num_lines_testableObject



8
9
10
# File 'lib/slather/coverage_info.rb', line 8

def num_lines_testable
  line_coverage_data.compact.count
end

#num_lines_testedObject



4
5
6
# File 'lib/slather/coverage_info.rb', line 4

def num_lines_tested
  line_coverage_data.compact.select { |cd| cd > 0 }.count
end

#percentage_branch_coverage_for_statement_on_line(line_number) ⇒ Object



49
50
51
# File 'lib/slather/coverage_info.rb', line 49

def percentage_branch_coverage_for_statement_on_line(line_number)
  rate_branch_coverage_for_statement_on_line(line_number) * 100
end

#percentage_lines_testedObject



20
21
22
23
24
25
26
# File 'lib/slather/coverage_info.rb', line 20

def percentage_lines_tested
  if num_lines_testable == 0
    100
  else
    rate_lines_tested * 100
  end
end

#rate_branch_coverage_for_statement_on_line(line_number) ⇒ Object



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

def rate_branch_coverage_for_statement_on_line(line_number)
  branch_data = branch_coverage_data_for_statement_on_line(line_number)
  if branch_data.empty?
    0.0
  else
    (num_branch_hits_for_statement_on_line(line_number) / branch_data.length.to_f)
  end
end

#rate_branches_testedObject



65
66
67
68
69
70
71
# File 'lib/slather/coverage_info.rb', line 65

def rate_branches_tested
  if (num_branches_testable > 0)
    (num_branches_tested / num_branches_testable.to_f)
  else
    0.0
  end
end

#rate_lines_testedObject



12
13
14
15
16
17
18
# File 'lib/slather/coverage_info.rb', line 12

def rate_lines_tested
  if num_lines_testable > 0
    (num_lines_tested / num_lines_testable.to_f)
  else
    0
  end
end

#source_file_pathname_relative_to_repo_rootObject



73
74
75
# File 'lib/slather/coverage_info.rb', line 73

def source_file_pathname_relative_to_repo_root
  source_file_pathname.realpath.relative_path_from(Pathname("./").realpath)
end