Class: SimpleCov::FileList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Enumerable[SimpleCov::SourceFile]
Defined in:
lib/simplecov/file_list.rb,
sig/simplecov.rbs

Overview

An Enumerable of SourceFile instances with aggregate coverage helpers. Aggregate readers return nil when the corresponding criterion was not enabled for the run.

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ FileList

Returns a new instance of FileList.

Parameters:



22
23
24
# File 'lib/simplecov/file_list.rb', line 22

def initialize(files)
  @files = files
end

Instance Method Details

#branch_covered_percentFloat?

Returns:

  • (Float, nil)


107
108
109
# File 'lib/simplecov/file_list.rb', line 107

def branch_covered_percent
  coverage_statistics[:branch]&.percent
end

#compute_coverage_statisticsHash[criterion, CoverageStatistics]

Returns:



151
152
153
# File 'lib/simplecov/file_list.rb', line 151

def compute_coverage_statistics
  coverage_statistics_by_file.transform_values { |stats| CoverageStatistics.from(stats) }
end

#compute_coverage_statistics_by_fileHash[criterion, Array[CoverageStatistics]]

Seed the result hash with one entry per criterion the user enabled — so an empty FileList (e.g. a group with no files) still yields the right shape — then fold each file's stats into the matching bucket. SourceFile#coverage_statistics always reports all three criteria; FileList is the layer that filters to the enabled set so disabled criteria don't surface in totals, JSON, or the HTML report.

Returns:



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/simplecov/file_list.rb', line 139

def compute_coverage_statistics_by_file
  seed = enabled_criteria_for_reporting.to_h do |criterion|
    bucket = [] #: Array[CoverageStatistics]
    [criterion, bucket]
  end
  @files.each_with_object(seed) do |file, together|
    file.coverage_statistics.each do |criterion, stats|
      together[criterion] << stats if together.key?(criterion)
    end
  end
end

#countInteger #count(arg0) ⇒ Integer #countInteger

Overloads:

  • #countInteger

    Returns:

    • (Integer)
  • #count(arg0) ⇒ Integer

    Parameters:

    • arg0 (Object)

    Returns:

    • (Integer)
  • #countInteger

    Returns:

    • (Integer)

Yields:

Yield Parameters:

Yield Returns:

  • (boolish)


881
882
883
# File 'sig/simplecov.rbs', line 881

def count: () -> Integer
| (untyped) -> Integer
| () { (SourceFile) -> boolish } -> Integer

#coverage_statisticsHash[criterion, CoverageStatistics] #coverage_statistics(arg0) ⇒ CoverageStatistics?

The per-criterion coverage statistics across all files. With no argument returns the {line:, branch:, method:} Hash; pass a criterion symbol (:line / :branch / :method) to get that one CoverageStatistics.

Overloads:



29
30
31
32
# File 'lib/simplecov/file_list.rb', line 29

def coverage_statistics(criterion = nil)
  stats = (@coverage_statistics ||= compute_coverage_statistics)
  criterion ? stats[criterion] : stats
end

#coverage_statistics_by_fileHash[criterion, Array[CoverageStatistics]]

Returns:



34
35
36
# File 'lib/simplecov/file_list.rb', line 34

def coverage_statistics_by_file
  @coverage_statistics_by_file ||= compute_coverage_statistics_by_file
end

#covered_branchesInteger?

Return total count of covered branches

Returns:

  • (Integer, nil)


98
99
100
# File 'lib/simplecov/file_list.rb', line 98

def covered_branches
  coverage_statistics[:branch]&.covered
end

#covered_linesInteger?

Returns the count of lines that have coverage

Returns:

  • (Integer, nil)


39
40
41
# File 'lib/simplecov/file_list.rb', line 39

def covered_lines
  coverage_statistics[:line]&.covered
end

#covered_methodsInteger?

Return total count of covered methods

Returns:

  • (Integer, nil)


117
118
119
# File 'lib/simplecov/file_list.rb', line 117

def covered_methods
  coverage_statistics[:method]&.covered
end

#covered_percent(criterion = :line) ⇒ Float?

The coverage across all files in percent, for the given criterion (line by default). Returns nil if the criterion was not measured.

Parameters:

  • (criterion)

Returns:

  • (Float, nil)


81
82
83
# File 'lib/simplecov/file_list.rb', line 81

def covered_percent(criterion = :line)
  coverage_statistics(criterion)&.percent
end

#covered_percentagesArray[Float?]

Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages

Returns:

  • (Array[Float?])


60
61
62
# File 'lib/simplecov/file_list.rb', line 60

def covered_percentages
  map(&:covered_percent)
end

#covered_strength(criterion = :line) ⇒ Float?

The strength (average hits per relevant unit) for the given criterion (line by default).

Parameters:

  • (criterion)

Returns:

  • (Float, nil)


88
89
90
# File 'lib/simplecov/file_list.rb', line 88

def covered_strength(criterion = :line)
  coverage_statistics(criterion)&.strength
end

#eachvoid #eachEnumerator[SourceFile, untyped]

Delegated to the underlying Array.

Overloads:

  • #eachvoid

    This method returns an undefined value.

  • #eachEnumerator[SourceFile, untyped]

    Returns:

Yields:

Yield Parameters:

Yield Returns:

  • (void)


876
877
# File 'sig/simplecov.rbs', line 876

def each: () { (SourceFile) -> void } -> void
| () -> Enumerator[SourceFile, untyped]

#empty?Boolean

Returns:

  • (Boolean)


884
# File 'sig/simplecov.rbs', line 884

def empty?: () -> bool

#enabled_criteria_for_reportingArray[criterion]

:line (or its :oneshot_line synonym) is reported when either criterion is enabled; the JRuby-gated branch/method criteria are reported when they pass their own engine-support check.

Returns:

  • (Array[criterion])


158
159
160
161
162
163
164
# File 'lib/simplecov/file_list.rb', line 158

def enabled_criteria_for_reporting
  criteria = [] #: Array[SimpleCov::criterion]
  criteria << :line   if SimpleCov.line_coverage?
  criteria << :branch if SimpleCov.branch_coverage?
  criteria << :method if SimpleCov.method_coverage?
  criteria
end

#least_covered_fileString?

Finds the least covered file and returns that file's name, or nil for an empty list (e.g. a fully filtered result).

Returns:

  • (String, nil)


66
67
68
69
70
71
# File 'lib/simplecov/file_list.rb', line 66

def least_covered_file
  # `covered_percent` is nil only for an unmeasured criterion, and :line
  # is always measured, so the `|| 0.0` arm never fires at runtime; it
  # exists to satisfy min_by's Comparable requirement.
  min_by { |file| file.covered_percent || 0.0 }&.filename
end

#lengthInteger

Returns:

  • (Integer)


879
# File 'sig/simplecov.rbs', line 879

def length: () -> Integer

#lines_of_codeInteger?

Returns the overall amount of relevant lines of code across all files in this list

Returns:

  • (Integer, nil)


74
75
76
# File 'lib/simplecov/file_list.rb', line 74

def lines_of_code
  coverage_statistics[:line]&.total
end

#mapvoid

This method returns an undefined value.



880
# File 'sig/simplecov.rbs', line 880

def map: [U] () { (SourceFile) -> U } -> Array[U]

#method_covered_percentFloat?

Returns:

  • (Float, nil)


126
127
128
# File 'lib/simplecov/file_list.rb', line 126

def method_covered_percent
  coverage_statistics[:method]&.percent
end

#missed_branchesInteger?

Return total count of covered branches

Returns:

  • (Integer, nil)


103
104
105
# File 'lib/simplecov/file_list.rb', line 103

def missed_branches
  coverage_statistics[:branch]&.missed
end

#missed_linesInteger?

Returns the count of lines that have been missed

Returns:

  • (Integer, nil)


44
45
46
# File 'lib/simplecov/file_list.rb', line 44

def missed_lines
  coverage_statistics[:line]&.missed
end

#missed_methodsInteger?

Return total count of missed methods

Returns:

  • (Integer, nil)


122
123
124
# File 'lib/simplecov/file_list.rb', line 122

def missed_methods
  coverage_statistics[:method]&.missed
end

#never_linesInteger

Returns the count of lines that are not relevant for coverage

Returns:

  • (Integer)


49
50
51
# File 'lib/simplecov/file_list.rb', line 49

def never_lines
  sum { |f| f.never_lines.size }
end

#sizeInteger

Returns:

  • (Integer)


878
# File 'sig/simplecov.rbs', line 878

def size: () -> Integer

#skipped_linesInteger

Returns the count of skipped lines

Returns:

  • (Integer)


54
55
56
# File 'lib/simplecov/file_list.rb', line 54

def skipped_lines
  sum { |f| f.skipped_lines.size }
end

#to_aArray[SourceFile]

Returns:



885
# File 'sig/simplecov.rbs', line 885

def to_a: () -> Array[SourceFile]

#to_aryArray[SourceFile]

Returns:



886
# File 'sig/simplecov.rbs', line 886

def to_ary: () -> Array[SourceFile]

#total_branchesInteger?

Return total count of branches in all files

Returns:

  • (Integer, nil)


93
94
95
# File 'lib/simplecov/file_list.rb', line 93

def total_branches
  coverage_statistics[:branch]&.total
end

#total_methodsInteger?

Return total count of methods in all files

Returns:

  • (Integer, nil)


112
113
114
# File 'lib/simplecov/file_list.rb', line 112

def total_methods
  coverage_statistics[:method]&.total
end