Class: SimpleCov::SourceFile
- Inherits:
-
Object
- Object
- SimpleCov::SourceFile
show all
- Includes:
- BuilderContext
- Defined in:
- lib/simplecov/source_file.rb,
lib/simplecov/source_file/line.rb,
lib/simplecov/source_file/branch.rb,
lib/simplecov/source_file/method.rb,
lib/simplecov/source_file/statistics.rb,
lib/simplecov/source_file/skip_chunks.rb,
lib/simplecov/source_file/line_builder.rb,
lib/simplecov/source_file/source_loader.rb,
lib/simplecov/source_file/branch_builder.rb,
lib/simplecov/source_file/method_builder.rb,
lib/simplecov/source_file/builder_context.rb,
lib/simplecov/source_file/ruby_data_parser.rb,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs,
sig/simplecov.rbs
Defined Under Namespace
Modules: BuilderContext, RubyDataParser, SourceLoader
Classes: Branch, BranchBuilder, Line, LineBuilder, Method, MethodBuilder, SkipChunks, Statistics
Instance Attribute Summary collapse
Instance Method Summary
collapse
#real_source_positions, #skip_chunks_for
Constructor Details
#initialize(filename, coverage_data, loaded: true) ⇒ SourceFile
Returns a new instance of SourceFile.
20
21
22
23
24
|
# File 'lib/simplecov/source_file.rb', line 20
def initialize(filename, coverage_data, loaded: true)
@filename = filename
@coverage_data = coverage_data
@loaded = loaded
end
|
Instance Attribute Details
#coverage_data ⇒ Hash[String, untyped]
Returns the value of attribute coverage_data.
18
19
20
|
# File 'lib/simplecov/source_file.rb', line 18
def coverage_data
@coverage_data
end
|
#filename ⇒ String
Returns the value of attribute filename.
18
19
20
|
# File 'lib/simplecov/source_file.rb', line 18
def filename
@filename
end
|
Instance Method Details
#branches ⇒ Array[Branch]
95
96
97
|
# File 'lib/simplecov/source_file.rb', line 95
def branches
@branches ||= BranchBuilder.new(self).call
end
|
#branches_coverage_percent ⇒ Float?
103
104
105
106
107
|
# File 'lib/simplecov/source_file.rb', line 103
def branches_coverage_percent
Deprecation.warn("`SimpleCov::SourceFile#branches_coverage_percent` is deprecated. " \
"Use `covered_percent(:branch)`.")
covered_percent(:branch)
end
|
#branches_for_line(line_number) ⇒ Array[[ Symbol, Integer ]]
129
130
131
|
# File 'lib/simplecov/source_file.rb', line 129
def branches_for_line(line_number)
branches_report.fetch(line_number, [])
end
|
#branches_report ⇒ Hash[Integer, Array[[ Symbol, Integer ]]]
113
114
115
116
|
# File 'lib/simplecov/source_file.rb', line 113
def branches_report
@branches_report ||=
branches.reject(&:skipped?).group_by(&:report_line).transform_values { |bs| bs.map(&:report) }
end
|
The per-criterion coverage statistics for this file. With no argument
answers the {line:, branch:, method:} Hash, and with a criterion symbol
that one CoverageStatistics. Every criterion is present even when it
wasn't enabled during the run, collapsed to 0/0/0; FileList is the
layer that filters to the enabled set.
41
42
43
44
|
# File 'lib/simplecov/source_file.rb', line 41
def coverage_statistics(criterion = nil)
stats = (@coverage_statistics ||= Statistics.new(self).call)
criterion ? stats[criterion] : stats
end
|
#covered_branches ⇒ Array[Branch]
A tree schema, because some conditions like case may have an additional
else that isn't declared in code but is given by default by the
coverage report.
121
122
123
|
# File 'lib/simplecov/source_file.rb', line 121
def covered_branches
@covered_branches ||= branches.select(&:covered?)
end
|
#covered_lines ⇒ Array[Line]
51
52
53
|
# File 'lib/simplecov/source_file.rb', line 51
def covered_lines
@covered_lines ||= lines.select(&:covered?)
end
|
#covered_methods ⇒ Array[Method]
141
142
143
|
# File 'lib/simplecov/source_file.rb', line 141
def covered_methods
@covered_methods ||= methods.select(&:covered?)
end
|
#covered_percent(criterion = :line) ⇒ Float?
Nil if the criterion was not measured.
77
78
79
|
# File 'lib/simplecov/source_file.rb', line 77
def covered_percent(criterion = :line)
coverage_statistics(criterion)&.percent
end
|
#covered_strength(criterion = :line) ⇒ Float?
81
82
83
|
# File 'lib/simplecov/source_file.rb', line 81
def covered_strength(criterion = :line)
coverage_statistics(criterion)&.strength
end
|
#line(number) ⇒ Line?
Answers nil for a number this file has no line for.
72
73
74
|
# File 'lib/simplecov/source_file.rb', line 72
def line(number)
lines.at(number - 1)
end
|
#line_with_missed_branch?(line_number) ⇒ Boolean
133
134
135
|
# File 'lib/simplecov/source_file.rb', line 133
def line_with_missed_branch?(line_number)
branches_for_line(line_number).any? { |_type, count| count.zero? }
end
|
#lines ⇒ Array[Line]
Also known as:
source_lines
46
47
48
|
# File 'lib/simplecov/source_file.rb', line 46
def lines
@lines ||= LineBuilder.new(self).call
end
|
#lines_of_code ⇒ Integer
67
68
69
|
# File 'lib/simplecov/source_file.rb', line 67
def lines_of_code
coverage_statistics[:line]&.total || 0
end
|
#methods ⇒ Array[Method]
137
138
139
|
# File 'lib/simplecov/source_file.rb', line 137
def methods
@methods ||= MethodBuilder.new(self).call
end
|
#methods_coverage_percent ⇒ Float?
149
150
151
152
153
|
# File 'lib/simplecov/source_file.rb', line 149
def methods_coverage_percent
Deprecation.warn("`SimpleCov::SourceFile#methods_coverage_percent` is deprecated. " \
"Use `covered_percent(:method)`.")
covered_percent(:method)
end
|
#missed_branches ⇒ Array[Branch]
125
126
127
|
# File 'lib/simplecov/source_file.rb', line 125
def missed_branches
@missed_branches ||= branches.select(&:missed?)
end
|
#missed_lines ⇒ Array[Line]
55
56
57
|
# File 'lib/simplecov/source_file.rb', line 55
def missed_lines
@missed_lines ||= lines.select(&:missed?)
end
|
#missed_methods ⇒ Array[Method]
145
146
147
|
# File 'lib/simplecov/source_file.rb', line 145
def missed_methods
@missed_methods ||= methods.select(&:missed?)
end
|
#never_lines ⇒ Array[Line]
59
60
61
|
# File 'lib/simplecov/source_file.rb', line 59
def never_lines
@never_lines ||= lines.select(&:never?)
end
|
#no_branches? ⇒ Boolean
99
100
101
|
# File 'lib/simplecov/source_file.rb', line 99
def no_branches?
total_branches.empty?
end
|
#no_lines? ⇒ Boolean
Every line the file has is irrelevant, a file with no lines at all
included.
87
88
89
|
# File 'lib/simplecov/source_file.rb', line 87
def no_lines?
lines.all?(&:never?)
end
|
#not_loaded? ⇒ Boolean
155
156
157
|
# File 'lib/simplecov/source_file.rb', line 155
def not_loaded?
!@loaded
end
|
#project_filename ⇒ String
26
27
28
|
# File 'lib/simplecov/source_file.rb', line 26
def project_filename
@filename.delete_prefix(SimpleCov.root).sub(%r{\A[/\\]}, "")
end
|
#relevant_lines ⇒ Integer
91
92
93
|
# File 'lib/simplecov/source_file.rb', line 91
def relevant_lines
lines.size - never_lines.size - skipped_lines.size
end
|
#skipped_lines ⇒ Array[Line]
63
64
65
|
# File 'lib/simplecov/source_file.rb', line 63
def skipped_lines
@skipped_lines ||= lines.select(&:skipped?)
end
|
#src ⇒ Array[String]
Also known as:
source
Read lazily to suppress reading unused source code.
31
32
33
|
# File 'lib/simplecov/source_file.rb', line 31
def src
@src ||= SourceLoader.call(filename)
end
|
#total_branches ⇒ Array[Branch]
109
110
111
|
# File 'lib/simplecov/source_file.rb', line 109
def total_branches
@total_branches ||= covered_branches + missed_branches
end
|