Skip to content

Commit

Permalink
Always floor coverage instead of rounding
Browse files Browse the repository at this point in the history
We do not want to report a 100% coverage when there are lines
that are not covered.
  • Loading branch information
albertored committed May 24, 2023
1 parent 07a89a3 commit 02537f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/excoveralls/local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ defmodule ExCoveralls.Local do
@moduledoc """
Locally displays the result to screen.
"""



defmodule Count do
@moduledoc """
Expand Down Expand Up @@ -145,16 +145,16 @@ defmodule ExCoveralls.Local do
end

defp format_info([stat, count]) do
coverage = get_coverage(count)
coverage = count |>get_coverage() |> Float.floor(1)
file_width = ExCoveralls.Settings.get_file_col_width
print_string("~5.1f% ~-#{file_width}s ~8w ~8w ~8w",
print_string("~5w% ~-#{file_width}s ~8w ~8w ~8w",
[coverage, stat[:name], count.lines, count.relevant, count.relevant - count.covered])
end

defp format_total(info) do
totals = Enum.reduce(info, %Count{}, fn([_, count], acc) -> append(count, acc) end)
coverage = get_coverage(totals)
print_string("[TOTAL] ~5.1f%", [coverage])
coverage = totals |> get_coverage() |> Float.floor(1)
print_string("[TOTAL] ~5w%", [coverage])
end

defp append(a, b) do
Expand Down
2 changes: 1 addition & 1 deletion lib/excoveralls/stats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ defmodule ExCoveralls.Stats do
if value == trunc(value) do
trunc(value)
else
Float.round(value, 1)
Float.floor(value, 1)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/stats_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ defmodule ExCoveralls.StatsTest do

test "coverage stats are rounded to one decimal place" do
results = Stats.source(@fractional_source_info)
assert(results.coverage == 66.7)
assert(results.coverage == 66.6)
end

describe "update_stats/2" do
Expand Down

0 comments on commit 02537f4

Please sign in to comment.