[erlang-patches] Fix searching for source files in cover:analyse_to_file/*

Andrew Thompson <>
Sun Aug 22 07:04:58 CEST 2010


This patch breaks current behaviour of cover:analyse_to_file.

Consider the following case. I have src/wtf.erl compiled to
debug_ebin/wtf.beam. I'm running cover from the parent directory of
these 2 directories, lets call it /home/andrew/project.

The new function; path_in_beam is run on debug_ebin/wtf.beam and it
returns "src/wtf.erl", is a relative path.
filelib:is_file() is run on the result and, in our case, returns true.
Thus we hit the {ok, Path} of the case in find_source(). Where the bug
comes in is that the code blindly gets the dirname of the .beam file (in
this case "/home/andrew/project/debug_ebin" and appends the path from
the beam, yielding the path
"/home/andrew/project/debug_ebin/src/wtf.erl". This path is obviously
garbage and thus cover_analyze_to_file fails.

The simplest fix is simply to return Path from that case clause, and not
use filename:dirname and filename:join at all. Since the other function
checks if the file is a valid path from pwd() that should never fail.

I'm not really seeing the usefulness of this patch overall, though,
since the file source is relative so in the vast majority of cases it
will be useless. To check it first (and incompletely at that) seems
like a bad idea.

Either way, this patch should not graduate in its current state.

Andrew


More information about the erlang-patches mailing list