Skip to content

Commit

Permalink
filter fully covered modules from terminal output (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Nov 24, 2021
1 parent 541de61 commit 8c08c4b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.17.0 - 2021-11-24

### Added

- Added a `:terminal_option` for `:filter_fully_covered`, defaulting to `true`
- this option filters fully covered modules from the terminal output

## 0.16.0 - 2021-10-04

### Changed
Expand Down
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ config :chaps,
template_path: "lib/templates/html/htmlcov/"
],
terminal_options: [
file_column_width: 40
file_column_width: 40,
filter_fully_covered: false
]
19 changes: 16 additions & 3 deletions lib/chaps/local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,27 @@ defmodule Chaps.Local do
def coverage(stats, options \\ []) do
file_width = Chaps.Settings.get_file_col_width()
print_files? = Chaps.Settings.get_print_files()
filter_fully_covered? = Chaps.Settings.get_terminal_filter_fully_covered()

count_info =
Enum.map(stats, fn stat -> [stat, calculate_count(stat[:coverage])] end)

count_info = sort(count_info, options)

filter_fully_covered_disclaimer =
if filter_fully_covered? do
"\nFully covered modules were omitted (the :filter_fully_covered terminal option is on).\n"
else
""
end

if print_files? do
"""
----------------
#{print_string("~-6s ~-#{file_width}s ~8s ~8s ~8s", ["COV", "FILE", "LINES", "RELEVANT", "MISSED"])}
#{Enum.join(format_body(count_info), "\n")}
#{Enum.join(format_body(count_info, filter_fully_covered?) ++ [""], "\n")}\
#{format_total(count_info)}
#{filter_fully_covered_disclaimer}\
----------------\
"""
else
Expand Down Expand Up @@ -145,8 +154,12 @@ defmodule Chaps.Local do
end)
end

defp format_body(info) do
Enum.map(info, &format_info/1)
defp format_body(info, filter_fully_covered?) do
info
|> Enum.reject(fn [_stat, count] ->
filter_fully_covered? and get_coverage(count) == 100.0
end)
|> Enum.map(&format_info/1)
end

defp format_info([stat, count]) do
Expand Down
12 changes: 12 additions & 0 deletions lib/chaps/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ defmodule Chaps.Settings do
""",
type: :integer,
default: 80
],
filter_fully_covered: [
doc: """
Wether to filter fully covered modules from the terminal table.
""",
type: :boolean,
default: true
]
]

Expand Down Expand Up @@ -189,6 +196,11 @@ defmodule Chaps.Settings do
get_terminal_options()[:print_files]
end

@doc false
def get_terminal_filter_fully_covered do
get_terminal_options()[:filter_fully_covered]
end

@doc false
def get_xml_base_dir do
get_coverage_options()[:xml_base_dir]
Expand Down
12 changes: 8 additions & 4 deletions test/chaps/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ defmodule Chaps.HtmlTest do
get_coverage_options: fn -> coverage_options(0.0) end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Html.execute(@source_info, output_dir: @test_output_dir)
end) =~ @stats_result
Expand All @@ -63,7 +64,8 @@ defmodule Chaps.HtmlTest do
get_coverage_options: fn -> coverage_options(0.0) end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Html.execute(@source_info)
end) =~ @stats_result
Expand All @@ -78,7 +80,8 @@ defmodule Chaps.HtmlTest do
get_coverage_options: fn -> coverage_options(100) end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
output =
capture_io(fn ->
assert catch_exit(Html.execute(@source_info)) == {:shutdown, 1}
Expand All @@ -95,7 +98,8 @@ defmodule Chaps.HtmlTest do
get_coverage_options: fn -> coverage_options(49.9) end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Html.execute(@source_info)
end) =~ @stats_result
Expand Down
3 changes: 2 additions & 1 deletion test/chaps/json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ defmodule Chaps.JsonTest do
get_coverage_options: fn -> %{"output_dir" => @test_output_dir} end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Json.execute(@source_info)
end) =~ @stats_result
Expand Down
3 changes: 2 additions & 1 deletion test/chaps/lcov_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ defmodule Chaps.LcovTest do
get_coverage_options: fn -> %{"output_dir" => @test_output_dir} end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Lcov.execute(@source_info)
end) =~ @stats_result
Expand Down
18 changes: 12 additions & 6 deletions test/chaps/local_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ defmodule Chaps.LocalTest do
%{"treat_no_relevant_lines_as_covered" => true}
end,
get_file_col_width: fn -> 40 end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert String.contains?(
Local.coverage(@empty_source_info),
"[TOTAL] 100.0%"
Expand All @@ -95,7 +96,8 @@ defmodule Chaps.LocalTest do
default_coverage_value: fn -> 0.0 end,
get_coverage_options: fn -> [] end,
get_file_col_width: fn -> 40 end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert String.contains?(
Local.coverage(@empty_source_info),
"[TOTAL] 0.0%"
Expand All @@ -107,7 +109,8 @@ defmodule Chaps.LocalTest do
get_coverage_options: fn -> [minimum_coverage: 100] end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
output =
capture_io(fn ->
assert catch_exit(Local.execute(@source_info)) == {:shutdown, 1}
Expand All @@ -124,7 +127,8 @@ defmodule Chaps.LocalTest do
get_coverage_options: fn -> [minimum_coverage: 49.9] end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Local.execute(@source_info)
end) =~ @stats_result
Expand All @@ -135,7 +139,8 @@ defmodule Chaps.LocalTest do
get_coverage_options: fn -> [minimum_coverage: 49.9] end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end do
get_print_files: fn -> true end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Local.execute(@source_info)
end) =~ ""
Expand All @@ -146,7 +151,8 @@ defmodule Chaps.LocalTest do
get_coverage_options: fn -> [minimum_coverage: 49.9] end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> false end do
get_print_files: fn -> false end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Local.execute(@source_info)
end) =~ @stats_no_files_results
Expand Down
3 changes: 2 additions & 1 deletion test/chaps/xml_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ defmodule Chaps.XmlTest do
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end,
get_xml_base_dir: fn -> "base_dir" end do
get_xml_base_dir: fn -> "base_dir" end,
get_terminal_filter_fully_covered: fn -> false end do
assert capture_io(fn ->
Xml.execute(@source_info)
end) =~ @stats_result
Expand Down

0 comments on commit 8c08c4b

Please sign in to comment.