Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/simplecov-console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SimpleCov::Formatter::Console
VERSION = IO.read(File.expand_path("../../VERSION", __FILE__)).strip

ATTRIBUTES = [:table_options, :use_colors, :max_rows, :max_lines,
:missing_len, :show_covered, :sort, :output_style]
:missing_len, :show_covered, :sort, :output_style, :files_to_filter]

class << self
attr_accessor(*ATTRIBUTES)
Expand All @@ -28,6 +28,8 @@ class << self
# configure sort from SORT env var
SimpleCov::Formatter::Console.sort = ENV.fetch('SORT', 'coverage')

# configure to only rea
SimpleCov::Formatter::Console.files_to_filter = ENV.fetch('FILES_TO_FILTER', '').split(', ')
# configure output format ('table', 'block')
SimpleCov::Formatter::Console.output_style = ENV.fetch('OUTPUT_STYLE', 'table')

Expand Down Expand Up @@ -73,17 +75,28 @@ def format(result)
return
end

if SimpleCov::Formatter::Console.files_to_filter.empty?
files = result.files
else
files = result.files.select do |file|
SimpleCov::Formatter::Console.files_to_filter.include?(file.filename)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like files_to_filter would be expected to include absolute paths to each file, is that what you meant for here? I think we can modify this to at least use a path relative to the current project, what do you think?

end
if files.nil? || files.empty? then
return
end
end

if SimpleCov::Formatter::Console.sort == 'coverage'
if show_branch_coverage
files = result.files.sort do |a,b|
files = files.sort do |a,b|
(a.covered_percent <=> b.covered_percent).nonzero? ||
(a.coverage_statistics[:branch].percent <=> b.coverage_statistics[:branch].percent)
end
else
files = result.files.sort_by(&:covered_percent)
files = files.sort_by(&:covered_percent)
end
else
files = result.files.to_a
files = files.to_a
end

covered_files = 0
Expand Down