From d1cf84781495ab26fe14424cc937c51bdcae3819 Mon Sep 17 00:00:00 2001 From: Dmitry Vasiliev Date: Fri, 23 Oct 2015 21:48:17 +0200 Subject: Fix possible 'badarith' error for cover Fix possible division by zero in case if a module doesn't export any functions --- plugins/cover.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/cover.mk b/plugins/cover.mk index 41a0c45..36d21fd 100644 --- a/plugins/cover.mk +++ b/plugins/cover.mk @@ -93,7 +93,8 @@ define cover_report.erl true -> N - 1; false -> N end}} || {M, {Y, N}} <- Report], TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]), TotalN = lists:sum([N || {_, {_, N}} <- Report1]), - TotalPerc = round(100 * TotalY / (TotalY + TotalN)), + Perc = fun(Y, N) -> case Y + N of 0 -> 100; S -> round(100 * Y / S) end end, + TotalPerc = Perc(TotalY, TotalN), {ok, F} = file:open("$(COVER_REPORT_DIR)/index.html", [write]), io:format(F, "~n" "~n" @@ -103,7 +104,7 @@ define cover_report.erl io:format(F, "~n", []), [io:format(F, "" "~n", - [M, M, round(100 * Y / (Y + N))]) || {M, {Y, N}} <- Report1], + [M, M, Perc(Y, N)]) || {M, {Y, N}} <- Report1], How = "$(subst $(space),$(comma)$(space),$(basename $(COVERDATA)))", Date = "$(shell date -u "+%Y-%m-%dT%H:%M:%SZ")", io:format(F, "
ModuleCoverage
~p~p%
~n" -- cgit v1.2.3