summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanagiotis PJ Papadomitsos <ppapadomitsos@splunk.com>2015-12-16 14:49:25 -0800
committerPanagiotis PJ Papadomitsos <ppapadomitsos@splunk.com>2015-12-16 14:49:25 -0800
commit8c055a7d96c40d278f0148b91f996edf1873cf5d (patch)
tree6054072187f5e23516f601a6e2dfeb8eb6e27fc5
parent21ae3145dfd9f24af9df962fcbf00fdb55d9b923 (diff)
Add support for total code coverage
-rw-r--r--src/rebar_prv_cover.erl16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl
index 15a067e..f814e2a 100644
--- a/src/rebar_prv_cover.erl
+++ b/src/rebar_prv_cover.erl
@@ -207,6 +207,8 @@ format_table(Stats, CoverFiles) ->
MaxLength = max(lists:foldl(fun max_length/2, 0, Stats), 20),
Header = header(MaxLength),
Seperator = seperator(MaxLength),
+ TotalLabel = format("total", MaxLength),
+ TotalCov = format(calculate_total(Stats), 8),
[io_lib:format("~ts~n~ts~n~ts~n", [Seperator, Header, Seperator]),
lists:map(fun({Mod, Coverage}) ->
Name = format(Mod, MaxLength),
@@ -214,6 +216,8 @@ format_table(Stats, CoverFiles) ->
io_lib:format(" | ~ts | ~ts |~n", [Name, Cov])
end, Stats),
io_lib:format("~ts~n", [Seperator]),
+ io_lib:format(" | ~ts | ~ts |~n", [TotalLabel, TotalCov]),
+ io_lib:format("~ts~n", [Seperator]),
io_lib:format(" coverage calculated from:~n", []),
lists:map(fun(File) ->
io_lib:format(" ~ts~n", [File])
@@ -234,6 +238,16 @@ seperator(Width) ->
format(String, Width) -> io_lib:format("~*.ts", [Width, String]).
+calculate_total(Stats) ->
+ TotalStats = length(Stats),
+ TotalCovInt = round(lists:foldl(
+ fun({_Mod, Coverage, _File}, Acc) ->
+ Acc + (list_to_integer(string:strip(Coverage, right, $%)) / TotalStats);
+ ({_Mod, Coverage}, Acc) ->
+ Acc + (list_to_integer(string:strip(Coverage, right, $%)) / TotalStats)
+ end, 0, Stats)),
+ integer_to_list(TotalCovInt) ++ "%".
+
write_index(State, Coverage) ->
CoverDir = cover_dir(State),
FileName = filename:join([CoverDir, "index.html"]),
@@ -265,6 +279,8 @@ write_index_section(F, [{Section, DataFile, Mods}|Rest]) ->
[strip_coverdir(Report), Mod, Cov])
end,
lists:foreach(fun(M) -> ok = file:write(F, FmtLink(M)) end, Mods),
+ ok = file:write(F, ?FMT("<tr><td><strong>Total</strong></td><td>~ts</td>\n",
+ [calculate_total(Mods)])),
ok = file:write(F, "</table>\n"),
write_index_section(F, Rest).