Cover options for EUnit #151

wants to merge 3 commits into


None yet

3 participants


According to the cover specification file used for coverage analysis during common test run ( it is possible to specify several options to control the cover behavior.

While for common test these options can be possibly specified through the ct_extra_params option, the cover behavior during eunit tests can't be controlled. This patch introduces a new configuration tuple {cover_opts, []}. At the moment rebar_eunit.erl only considers the option {excl_mods, [my_mod_to_exclude]} which will remove my_mod_to_exclude from the source and beam-files used during cover analysis.

dergraf added some commits Oct 25, 2011
@dergraf dergraf Added cover_opts
In rebar.config you can now provide the cover_opts tuple which should contain a proplist with other information. At the moment just the {excl_mods, [my_mod_to_exclude]} option is implemented, which will turn off cover for the modules specified.
@dergraf dergraf cover init
forgot to exclude the cover-excludes during cover init. we ended up with cover compiled modules which were excluded from the cover analysis
@dizzyd dizzyd commented on the diff Dec 28, 2011
@@ -267,7 +267,18 @@ perform_cover(Config, BeamFiles, SrcModules) ->
perform_cover(false, _Config, _BeamFiles, _SrcModules) ->
perform_cover(true, Config, BeamFiles, SrcModules) ->
- cover_analyze(Config, BeamFiles, SrcModules).
+ CoverOpts = rebar_config:get_list(Config, cover_opts, []),
+ {NewBeamFiles, NewSrcModules} =
+ case proplists:get_value(excl_mods, CoverOpts) of
+ undefined ->
+ {BeamFiles, SrcModules};
+ ExclMods ->
+ {
+ [lists:delete(M, BeamFiles) || M <- ExclMods],
dizzyd Dec 28, 2011

Wouldn't it be more efficient to filter the lists on is_member rather than deleting every item? Or am I missing something here?

dergraf Dec 28, 2011

you are right. my solution is far from being optimal. Actually lists:delete inside the list comprehension produces a list of lists. As you have suggested a comprehension using lists:member will do it as well:

[M || M <- BeamFiles, not lists:member(M, ExclMods)],
[M || M <- SrcModules, not lists:member(M, ExclMods)]

@dizzyd dizzyd commented on the diff Dec 28, 2011
@@ -355,7 +366,18 @@ cover_init(true, BeamFiles) ->
cover_init(Config, BeamFiles) ->
- cover_init(rebar_config:get(Config, cover_enabled, false), BeamFiles).
+ CoverOpts = rebar_config:get_list(Config, cover_opts, []),
+ NewBeamFiles = case proplists:get_value(excl_mods, CoverOpts) of
dizzyd Dec 28, 2011

Why does this section of code do something completely different than the above section that does roughly the same thing? Maybe we need to have a function which does this work of exclusion?

dergraf Dec 28, 2011

True. Since cover_init and perform_cover do only share the config this was an unobtrusive way of dealing with it. As perform_cover uses the module names and cover_init the file names such a function must be able to deal with both such as e.g:

DelBeam =
fun(B) when is_list(B) ->
M = list_to_atom(filename:basename(B, ".beam")),
not lists:member(M, ExclMods);
(B) when is_atom(B) ->
not lists:member(B, ExclMods)
lists:filter(DelBeam, BeamFiles)

I am feeling ambivalent about that one... I could live with this redundancy


Any news on the revised patch?

@dizzyd dizzyd closed this Jul 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment