# frozen_string_literal: truemoduleSimpleCov# Inclusion / exclusion / grouping methods: `cover`, `skip`, `group`,# plus the deprecated `track_files` / `add_filter` / `add_group`# aliases. Mutates the same `filters`, `groups`, and `cover_filters`# collections the main Configuration module exposes.moduleConfigurationattr_writer:filters,:groups## Restrict the universe of files in the coverage report to those matching# one or more globs, regexps, or block predicates. Multiple calls union;# when any `cover` matcher is configured the report drops every file that# doesn't match at least one of them.## Strings are interpreted as shell globs (e.g. "lib/**/*.rb"), not# substring matches — this is a deliberate departure from the legacy# `add_filter` semantics and matches the way `track_files` already# interprets its argument.## When the matcher is a string-glob, `cover` also expands the glob on# disk so files that exist but were never required during the run still# appear in the report (at 0% coverage). This is the "include unloaded# files" half of the legacy `track_files` behavior, rolled into the# same call.## SimpleCov.start do# cover "lib/**/*.rb", "app/**/*.rb"# cover(/_helper\.rb\z/)# cover { |sf| sf.lines.count > 5 }# end#defcover(*args,&block)args.each{|arg|cover_filters<<build_cover_filter(arg)}cover_filters<<SimpleCov::BlockFilter.new(block)ifblockcover_filtersend# Returns the list of configured inclusion filters added via `cover`.defcover_filters@cover_filters||=[]end# Returns the list of string globs passed to `cover` — used by the# disk-discovery pass in `SimpleCov.add_not_loaded_files` so files# matching a `cover` glob appear in the report even when they were# never required during the suite.## Walks into `ArrayFilter` entries (built when a caller passes an# array to `cover`) so a glob nested inside `cover(["lib/**/*.rb",# /helper\.rb\z/])` still drives unloaded-file discovery.defcover_globscollect_cover_globs(cover_filters)end# DEPRECATED: prefer `cover`, which both includes unloaded files (the# historical `track_files` behavior) and restricts the report to the# matching set.deftrack_files(glob)SimpleCov::Deprecation.warn("`SimpleCov.track_files` is deprecated. "\"#{track_files_replacement_hint(glob)}")@tracked_files=globend# `track_files(nil)` is the documented way to clear a previously-set# glob, but `cover(nil)` raises `ConfigurationError`, so don't point# users at it. The `cover` API has no direct equivalent for "reset# the inclusion list" — point users at the `@cover_filters` reset.deftrack_files_replacement_hint(glob)ifglob.nil?"Replace with `SimpleCov.cover_filters.clear` — clearing the inclusion list."else"Replace with `SimpleCov.cover #{glob.inspect}` — `cover` includes unloaded files on disk "\"(the historical `track_files` behavior) and also restricts the report to the matching set. "\"If you want to keep additional files outside #{glob.inspect} in the report, pass every "\"directory you care about, e.g. `cover #{glob.inspect}, \"app/**/*.rb\"`."endend# Returns the glob used to include files that were not explicitly required.deftracked_files@tracked_filesifdefined?(@tracked_files)end# Returns the list of configured exclusion filters added via `skip`# (or the deprecated `add_filter`).deffilters@filters||=[]end## Drop matching files from the coverage report. The inverse of `cover`.## See README for the full grammar; `skip` accepts a String (path-segment# substring), Regexp, block predicate, or Array of any of those.#defskip(filter_argument=nil,&)filters<<parse_filter(filter_argument,&)end# DEPRECATED: alias for `skip`. Same matcher grammar, identical behavior.defadd_filter(filter_argument=nil,&block)example=block?"`SimpleCov.skip { ... }`":"`SimpleCov.skip #{filter_argument.inspect}`"SimpleCov::Deprecation.warn("`SimpleCov.add_filter` is deprecated. "\"Replace with `SimpleCov.skip` (same arguments, same behavior). Example: #{example}.")skip(filter_argument,&block)end# Remove any filters whose `filter_argument` equals the given value.# Returns true when at least one filter was removed, false otherwise.defremove_filter(filter_argument)# rubocop:disable Naming/PredicateMethodbefore=filters.sizefilters.reject!{|filter|filter.respond_to?(:filter_argument)&&filter.filter_argument==filter_argument}filters.size!=beforeend# Remove every filter from the chain, including the defaults installed# by `SimpleCov.start`.defclear_filters@filters=[]end# Returns the configured groups. Add groups using SimpleCov.group.defgroups@groups||={}end# Define a display group for files. Same matcher grammar as `skip`,# but instead of dropping the matching files it bins them under# `group_name` for the formatter. Files matched by no group fall# into the implicit "Ungrouped" bucket.defgroup(group_name,filter_argument=nil,&)groups[group_name]=parse_filter(filter_argument,&)end# DEPRECATED: alias for `group`. Same arguments, same behavior.defadd_group(group_name,filter_argument=nil,&block)example=ifblock"`SimpleCov.group #{group_name.inspect} { ... }`"else"`SimpleCov.group #{group_name.inspect}, #{filter_argument.inspect}`"endSimpleCov::Deprecation.warn("`SimpleCov.add_group` is deprecated. "\"Replace with `SimpleCov.group` (same arguments, same behavior). Example: #{example}.")group(group_name,filter_argument,&block)end# Drop every filter previously installed (defaults plus anything# earlier in this block) so subsequent `skip` calls start from a# clean slate. Order matters — call this before your own `skip`# invocations.defno_default_skipsclear_filtersendprivate# The actual filter processor. Not meant for direct use.defparse_filter(filter_argument=nil,&filter_proc)filter=filter_argument||filter_procraiseArgumentError,"Please specify either a filter or a block to filter with"unlessfilterSimpleCov::Filter.build_filter(filter)end# Build a filter for a `cover` argument. Strings are treated as# globs (not substrings — that's `skip`/`add_filter`'s semantics).defbuild_cover_filter(arg)caseargwhenStringthenSimpleCov::GlobFilter.new(arg)whenRegexpthenSimpleCov::RegexFilter.new(arg)whenProcthenSimpleCov::BlockFilter.new(arg)whenSimpleCov::FilterthenargwhenArraythenSimpleCov::ArrayFilter.new(arg.map{|a|build_cover_filter(a)})elseraiseSimpleCov::ConfigurationError,"Unsupported `cover` argument #{arg.inspect}; "\"expected a String glob, Regexp, Proc, "\"SimpleCov::Filter, or Array of those."endend# Walk a list of cover filters and return the string globs they hold,# descending into `ArrayFilter` wrappers built by `cover(["a", "b"])`.defcollect_cover_globs(filter_list)filter_list.flat_mapdo|filter|casefilterwhenSimpleCov::GlobFilterthenfilter.filter_argumentwhenSimpleCov::ArrayFilterthencollect_cover_globs(filter.filter_argument)else[]endendendendend