diff options
| author | Fred Hebert <mononcqc@ferd.ca> | 2015-12-18 22:45:07 -0500 | 
|---|---|---|
| committer | Fred Hebert <mononcqc@ferd.ca> | 2015-12-18 22:45:07 -0500 | 
| commit | c66bce829cdf3d11d3640acf8c8be3732ac6e2c6 (patch) | |
| tree | 08710fc3c555da9c2f31228527c411db32d1fb44 | |
| parent | 21ae3145dfd9f24af9df962fcbf00fdb55d9b923 (diff) | |
| parent | ae9c1fa0f8c3243ce6cee267e222625a54e85c7d (diff) | |
Merge pull request #983 from priestjim/feature/cover_totals
Add support for total code coverage
| -rw-r--r-- | src/rebar_prv_cover.erl | 18 | 
1 files changed, 18 insertions, 0 deletions
| diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl index 15a067e..c915141 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,18 @@ seperator(Width) ->  format(String, Width) -> io_lib:format("~*.ts", [Width, String]). +calculate_total(Stats) when length(Stats) =:= 0 -> +    "0%"; +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 +281,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). | 
