Cover compilation is lossy

Adam Lindberg adam@REDACTED
Tue Mar 22 15:35:49 CET 2011


Hi,

I'm having a bit of a peculiar situation.

In my mocking framework, meck, I want to enable mocking of cover 
compiled modules. I can do this in most situations, but there is one 
case where it doesn't work because of how cover compiles modules.

If I have a module 'm',  which have a function 'f' and compile that with 
[debug_info], I can get the original beam code (from disk) and the 
abstract code (from the module in memory). Both these can be used to 
restore the original module when done mocking (load the binary or 
recompile the abstract code).

When cover compiling 'm' without any special flags, the same is true. 
But when using for example [{d, 'TEST'}] in cover, cover will compile 
the module accordingly, BUT it will not save the compile option in the 
module info. It will neither save the new abstract code that it used to 
compile the module. This makes it impossible to either a) restore the 
module from abstract code or b) recompile it using the options provided.

So, how could I go about restoring the cover compiled module as seen in 
memory before mocking?

  * I can't restore the beam (since it isn't cover compiled).
  * I can't restore the abstract code (since it isn't "cover compiled").
  * I can't recompile the original source (since the compile options are 
thrown away by cover).

Is there any way to get to the module beam code or abstract code for a 
cover compiled module? Or is the only way to fix cover to actually save 
the correct abstract code / compile options?

(Current meck source code can be found here: 
https://github.com/eproxus/meck/blob/master/src/meck.erl#L463 
backup_original/1 and restore_original/2 are of particular interest)

Cheers,
Adam



More information about the erlang-questions mailing list