diff options
author | Dmitry Vasiliev <[email protected]> | 2015-10-23 21:48:17 +0200 |
---|---|---|
committer | Dmitry Vasiliev <[email protected]> | 2015-10-23 21:48:17 +0200 |
commit | d1cf84781495ab26fe14424cc937c51bdcae3819 (patch) | |
tree | a398818c91c64d594807f497acdd7f9a7376a7c2 | |
parent | d7b4e589f1716e2de5087a491ea1701d294dccbc (diff) | |
download | erlang.mk-d1cf84781495ab26fe14424cc937c51bdcae3819.tar.gz erlang.mk-d1cf84781495ab26fe14424cc937c51bdcae3819.tar.bz2 erlang.mk-d1cf84781495ab26fe14424cc937c51bdcae3819.zip |
Fix possible 'badarith' error for cover
Fix possible division by zero in case if a module doesn't export any
functions
-rw-r--r-- | plugins/cover.mk | 5 |
1 files 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, "<!DOCTYPE html><html>~n" "<head><meta charset=\"UTF-8\">~n" @@ -103,7 +104,7 @@ define cover_report.erl io:format(F, "<table><tr><th>Module</th><th>Coverage</th></tr>~n", []), [io:format(F, "<tr><td><a href=\"~p.COVER.html\">~p</a></td>" "<td>~p%</td></tr>~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, "</table>~n" |