diff options
author | David Ã…berg <davabe@hotmail.com> | 2012-06-12 22:36:09 +0200 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-08-07 13:44:40 +0200 |
commit | 43d5b6257e3a446367aed2bd59f3f87637fcb70f (patch) | |
tree | ba14f753dbafb12ca4475e63ce923633c038e0d1 | |
parent | aec71f93cbcb13a3765b16209871769153af11e2 (diff) |
Enable export of cover data from eunit testrun
-rw-r--r-- | rebar.config.sample | 3 | ||||
-rw-r--r-- | src/rebar_eunit.erl | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/rebar.config.sample b/rebar.config.sample index 1cd85be..a6f5bf7 100644 --- a/rebar.config.sample +++ b/rebar.config.sample @@ -78,6 +78,9 @@ %% Whether to print coverage report to console. Default is `false' {cover_print_enabled, false}. +%% Whether to export coverage report to file. Default is `false' +{cover_export_enabled, false}. + %% == Common Test == %% Override the default "test" directory in which SUITEs are located diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 9b525d8..289ae3d 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -223,6 +223,14 @@ cover_analyze(Config, FilteredModules, SrcModules) -> Index = filename:join([rebar_utils:get_cwd(), ?TEST_DIR, "index.html"]), ?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 case rebar_config:get(Config, cover_print_enabled, false) of true -> @@ -388,6 +396,17 @@ cover_print_coverage(Coverage) -> cover_file(Module) -> 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) -> "not executed"; percentage(Cov, NotCov) -> |