Enable export of cover data from eunit testrun

This commit is contained in:
David Åberg 2012-06-12 22:36:09 +02:00 committed by Tuncer Ayaz
parent aec71f93cb
commit 43d5b6257e
2 changed files with 22 additions and 0 deletions

View file

@ -78,6 +78,9 @@
%% Whether to print coverage report to console. Default is `false' %% Whether to print coverage report to console. Default is `false'
{cover_print_enabled, false}. {cover_print_enabled, false}.
%% Whether to export coverage report to file. Default is `false'
{cover_export_enabled, false}.
%% == Common Test == %% == Common Test ==
%% Override the default "test" directory in which SUITEs are located %% Override the default "test" directory in which SUITEs are located

View file

@ -223,6 +223,14 @@ cover_analyze(Config, FilteredModules, SrcModules) ->
Index = filename:join([rebar_utils:get_cwd(), ?TEST_DIR, "index.html"]), Index = filename:join([rebar_utils:get_cwd(), ?TEST_DIR, "index.html"]),
?CONSOLE("Cover analysis: ~s\n", [Index]), ?CONSOLE("Cover analysis: ~s\n", [Index]),
%% Export coverage data, if configured
case rebar_config:get(Config, cover_export_enabled, false) of
true ->
cover_export_coverdata();
false ->
ok
end,
%% Print coverage report, if configured %% Print coverage report, if configured
case rebar_config:get(Config, cover_print_enabled, false) of case rebar_config:get(Config, cover_print_enabled, false) of
true -> true ->
@ -388,6 +396,17 @@ cover_print_coverage(Coverage) ->
cover_file(Module) -> cover_file(Module) ->
filename:join([?TEST_DIR, atom_to_list(Module) ++ ".COVER.html"]). filename:join([?TEST_DIR, atom_to_list(Module) ++ ".COVER.html"]).
cover_export_coverdata() ->
ExportFile = filename:join([rebar_utils:get_cwd(),
?TEST_DIR,
"eunit.coverdata"]),
case cover:export(ExportFile) of
ok ->
?CONSOLE("Coverdata export: ~s~n", [ExportFile]);
{error,Reason} ->
?ERROR("Coverdata export failed: ~p~n", [Reason])
end.
percentage(0, 0) -> percentage(0, 0) ->
"not executed"; "not executed";
percentage(Cov, NotCov) -> percentage(Cov, NotCov) ->