Module: SimpleCov::UnloadedFileInjector
- Extended by:
- UnloadedFileInjector
- Included in:
- UnloadedFileInjector
- Defined in:
- lib/simplecov/unloaded_file_injector.rb
Overview
Fills in coverage for files that were tracked but never loaded, so they
count toward the denominators instead of being absent from the report.
This is the mechanism; the merge-time policy of when to inject lives in
ResultMerger::UnloadedFiles.
Everything arrives as arguments rather than being read from the SimpleCov singleton, because the merge performs this injection on behalf of processes whose configuration it does not necessarily share (#1250).
Instance Method Summary collapse
-
#call(coverage, paths, synthesize:, lines:) ⇒ Object
Paths already present are left alone, whoever put them there, which is what lets this run over resultsets a previous SimpleCov already injected into without double-counting or overwriting real data.
-
#discover(globs, root:, reject: []) ⇒ Object
Globs expand relative to
rootrather thanDir.pwd: runners that chdir would otherwise silently miss files and produce a different set per environment (#1106). - #rejected?(path, filters) ⇒ Boolean
Instance Method Details
#call(coverage, paths, synthesize:, lines:) ⇒ Object
Paths already present are left alone, whoever put them there, which is what lets this run over resultsets a previous SimpleCov already injected into without double-counting or overwriting real data.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/simplecov/unloaded_file_injector.rb', line 48 def call(coverage, paths, synthesize:, lines:) injected = Set.new augmented = coverage.dup paths.each do |path| next if augmented.key?(path) augmented[path] = SimulateCoverage.call(path, synthesize: synthesize, lines: lines) injected << path end [augmented, injected] end |
#discover(globs, root:, reject: []) ⇒ Object
Globs expand relative to root rather than Dir.pwd: runners that chdir
would otherwise silently miss files and produce a different set per
environment (#1106).
reject: are the producing process's path-decidable filters. Paths its
own report would exclude must not be recorded as tracked, or a merge that
does not share the configuration would simulate them back in. A block
filter is handed the source file and may consult coverage that does not
exist yet, so those still fall to the merging process's filter chain.
26 27 28 29 30 31 32 33 34 |
# File 'lib/simplecov/unloaded_file_injector.rb', line 26 def discover(globs, root:, reject: []) paths = globs.compact .flat_map { |glob| Dir.glob(glob, base: root) } .uniq .map { |path| File.(path, root) } return paths if reject.empty? paths.reject { |path| rejected?(path, reject) } end |
#rejected?(path, filters) ⇒ Boolean
36 37 38 39 |
# File 'lib/simplecov/unloaded_file_injector.rb', line 36 def rejected?(path, filters) candidate = SourceFile.new(path, NO_COVERAGE_YET, loaded: false) filters.any? { |filter| filter.matches?(candidate) } end |