[PATCH] allow user specified compiler options in cover.erl

Tobias Schlager <>
Thu Sep 16 09:56:13 CEST 2010

I would like to propose a small patch of the cover.erl module.

In order to be able to test non-exported functions from another (test) 
module it is necessary to compile the specific module (at least during 
the test phase) with the export_all compiler option. This allows 
complete separation of testing and productive code. At the moment it is 
not possible to combine this with a test code coverage using the cover 
module. The problem is that when cover compiling a module using 
cover:compile_* the code is reloaded into the emulator 
omitting/filtering the passed user options. In my example above the 
export_all option would be removed and the non-exported functions cannot 
be called any more.

The below patch would
* extend the filtering of compiler options in compile_module/2 to allow 
the user to pass the export_all option
* pass the (filtered) user specified compiler options to compile:forms 
in order to have the options enabled when the cover compiled code is 
loaded into the emulator

--- cover.erl.orig	2010-06-11 17:31:53.000000000 +0200
+++ cover.erl.new	2010-09-15 16:46:24.000000000 +0200
@@ -229,6 +229,7 @@
  					{i, Dir} when is_list(Dir) -> true;
  					{d, _Macro} -> true;
  					{d, _Macro, _Value} -> true;
+					export_all -> true;
  					_ -> false
@@ -569,7 +570,7 @@
  	    case get_beam_file(Module,BeamFile0,Compiled0) of
  		{ok,BeamFile} ->
  		    {Reply,Compiled} =
-			case do_compile_beam(Module,BeamFile) of
+			case do_compile_beam(Module,BeamFile,[]) of
  			    {ok, Module} ->
@@ -1227,13 +1228,13 @@
      Options = [debug_info,binary,report_errors,report_warnings] ++ 
      case compile:file(File, Options) of
  	{ok, Module, Binary} ->
-	    do_compile_beam(Module,Binary);
+	    do_compile_beam(Module,Binary,UserOptions);
  	error ->

  %% Beam is a binary or a .beam file name
-do_compile_beam(Module,Beam) ->
+do_compile_beam(Module,Beam,UserOptions) ->
      %% Clear database

@@ -1253,7 +1254,7 @@
  	    %% Compile and load the result
  	    %% It's necessary to check the result of loading since it may
  	    %% fail, for example if Module resides in a sticky directory
-	    {ok, Module, Binary} = compile:forms(Forms, []),
+	    {ok, Module, Binary} = compile:forms(Forms, UserOptions),
  	    case code:load_binary(Module, ?TAG, Binary) of
  		{module, Module} ->

Tobias Schlager

More information about the erlang-patches mailing list