Skip to content
This repository

Cover options for EUnit #151

Closed
wants to merge 3 commits into from

3 participants

Andre Graf Tuncer Ayaz Dave Smith
Andre Graf

According to the cover specification file used for coverage analysis during common test run (http://www.erlang.org/doc/apps/common_test/cover_chapter.html#id217564) 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.

added some commits October 25, 2011
Andre Graf 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.
3a5bde1
Andre Graf 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
d0e9564
Dave Smith dizzyd commented on the diff December 27, 2011
src/rebar_eunit.erl
@@ -267,7 +267,18 @@ perform_cover(Config, BeamFiles, SrcModules) ->
267 267
 perform_cover(false, _Config, _BeamFiles, _SrcModules) ->
268 268
     ok;
269 269
 perform_cover(true, Config, BeamFiles, SrcModules) ->
270  
-    cover_analyze(Config, BeamFiles, SrcModules).
  270
+    CoverOpts = rebar_config:get_list(Config, cover_opts, []),
  271
+    {NewBeamFiles, NewSrcModules} = 
  272
+    case proplists:get_value(excl_mods, CoverOpts) of
  273
+        undefined ->
  274
+            {BeamFiles, SrcModules};
  275
+        ExclMods ->
  276
+            {
  277
+                [lists:delete(M, BeamFiles) || M <- ExclMods],
2
Dave Smith
dizzyd added a note December 27, 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?

Andre Graf
dergraf added a note December 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)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Dave Smith dizzyd commented on the diff December 27, 2011
src/rebar_eunit.erl
@@ -355,7 +366,18 @@ cover_init(true, BeamFiles) ->
355 366
             OkOpen
356 367
     end;
357 368
 cover_init(Config, BeamFiles) ->
358  
-    cover_init(rebar_config:get(Config, cover_enabled, false), BeamFiles).
  369
+    CoverOpts = rebar_config:get_list(Config, cover_opts, []),
  370
+    NewBeamFiles = case proplists:get_value(excl_mods, CoverOpts) of
2
Dave Smith
dizzyd added a note December 27, 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?

Andre Graf
dergraf added a note December 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)
end,
lists:filter(DelBeam, BeamFiles)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tuncer Ayaz

Any news on the revised patch?

Andre Graf
Dave Smith dizzyd closed this July 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Oct 25, 2011
Andre Graf 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.
3a5bde1
Andre Graf 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
d0e9564
Dec 28, 2011
Andre Graf added cover opts example e812425
This page is out of date. Refresh to see the latest.
4  rebar.config.sample
@@ -81,6 +81,10 @@
81 81
 %% Whether to print coverage report to console. Default is `false'
82 82
 {cover_print_enabled, false}.
83 83
 
  84
+%% Additional cover options
  85
+%% currently supported: excl_mods
  86
+{cover_opts, [{excl_mods, [module_to_exclude]}]}.
  87
+
84 88
 %% == Common Test ==
85 89
 
86 90
 %% Option to pass extra parameters when launching Common Test
26  src/rebar_eunit.erl
@@ -267,7 +267,18 @@ perform_cover(Config, BeamFiles, SrcModules) ->
267 267
 perform_cover(false, _Config, _BeamFiles, _SrcModules) ->
268 268
     ok;
269 269
 perform_cover(true, Config, BeamFiles, SrcModules) ->
270  
-    cover_analyze(Config, BeamFiles, SrcModules).
  270
+    CoverOpts = rebar_config:get_list(Config, cover_opts, []),
  271
+    {NewBeamFiles, NewSrcModules} = 
  272
+    case proplists:get_value(excl_mods, CoverOpts) of
  273
+        undefined ->
  274
+            {BeamFiles, SrcModules};
  275
+        ExclMods ->
  276
+            {
  277
+                [lists:delete(M, BeamFiles) || M <- ExclMods],
  278
+                [lists:delete(M, SrcModules) || M <- ExclMods]
  279
+            }       
  280
+    end,    
  281
+    cover_analyze(Config, NewBeamFiles, NewSrcModules).
271 282
 
272 283
 cover_analyze(_Config, [], _SrcModules) ->
273 284
     ok;
@@ -355,7 +366,18 @@ cover_init(true, BeamFiles) ->
355 366
             OkOpen
356 367
     end;
357 368
 cover_init(Config, BeamFiles) ->
358  
-    cover_init(rebar_config:get(Config, cover_enabled, false), BeamFiles).
  369
+    CoverOpts = rebar_config:get_list(Config, cover_opts, []),
  370
+    NewBeamFiles = case proplists:get_value(excl_mods, CoverOpts) of
  371
+        undefined ->
  372
+            BeamFiles;
  373
+        ExclMods -> 
  374
+            DelBeam = fun(B) ->
  375
+                    M = list_to_atom(filename:basename(B, ".beam")),
  376
+                    not lists:member(M, ExclMods)
  377
+            end,
  378
+            lists:filter(DelBeam, BeamFiles)
  379
+    end, 
  380
+    cover_init(rebar_config:get(Config, cover_enabled, false), NewBeamFiles).
359 381
 
360 382
 cover_analyze_mod(Module) ->
361 383
     case cover:analyze(Module, coverage, module) of
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.