aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/tools/src/cover.erl22
-rw-r--r--lib/tools/test/cover_SUITE.erl15
-rw-r--r--lib/tools/test/cover_SUITE_data/compile_beam/z.erl1
3 files changed, 33 insertions, 5 deletions
diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl
index 468225dc13..d7c736b710 100644
--- a/lib/tools/src/cover.erl
+++ b/lib/tools/src/cover.erl
@@ -1945,7 +1945,7 @@ move_clauses([]) ->
%% Given a .beam file, find the .erl file. Look first in same directory as
%% the .beam file, then in <beamdir>/../src
-find_source(File0) ->
+find_source(Module, File0) ->
case filename:rootname(File0,".beam") of
File0 ->
File0;
@@ -1962,11 +1962,27 @@ find_source(File0) ->
true ->
InDotDotSrc;
false ->
- {beam,File0}
+ find_source_from_module(Module, File0)
end
end
end.
+%% In case we can't find the file from the given .beam,
+%% we try to get the information directly from the module source
+find_source_from_module(Module, File) ->
+ Compile = Module:module_info(compile),
+ case lists:keyfind(source, 1, Compile) of
+ {source, Path} ->
+ case filelib:is_file(Path) of
+ true ->
+ Path;
+ false ->
+ {beam, File}
+ end;
+ false ->
+ {beam, File}
+ end.
+
do_parallel_analysis(Module, Analysis, Level, Loaded, From, State) ->
analyse_info(Module,State#main_state.imported),
C = case Loaded of
@@ -2070,7 +2086,7 @@ do_parallel_analysis_to_file(Module, OutFile, Opts, Loaded, From, State) ->
{imported, File0, _} ->
File0
end,
- case find_source(File) of
+ case find_source(Module, File) of
{beam,_BeamFile} ->
reply(From, {error,no_source_code_found});
ErlFile ->
diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl
index 57260a3869..2156390244 100644
--- a/lib/tools/test/cover_SUITE.erl
+++ b/lib/tools/test/cover_SUITE.erl
@@ -277,12 +277,23 @@ analyse(Config) when is_list(Config) ->
?line f:f2(),
?line {ok, "f.COVER.out"} = cover:analyse_to_file(f),
- %% Source code cannot be found by analyse_to_file
+ %% Source code can be found via source
?line {ok,v} = compile:file("compile_beam/v",[debug_info]),
?line code:purge(v),
?line {module,v} = code:load_file(v),
?line {ok,v} = cover:compile_beam(v),
- ?line {error,no_source_code_found} = cover:analyse_to_file(v),
+ {ok,"v.COVER.out"} = cover:analyse_to_file(v),
+
+ %% Source code cannot be found
+ {ok,_} = file:copy("compile_beam/z.erl", "z.erl"),
+ {ok,z} = compile:file(z,[debug_info]),
+ code:purge(z),
+ {module,z} = code:load_file(z),
+ {ok,z} = cover:compile_beam(z),
+ ok = file:delete("z.erl"),
+ {error,no_source_code_found} = cover:analyse_to_file(z),
+ code:purge(z),
+ code:delete(z),
?line {error,{not_cover_compiled,b}} = cover:analyse(b),
?line {error,{not_cover_compiled,g}} = cover:analyse(g),
diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/z.erl b/lib/tools/test/cover_SUITE_data/compile_beam/z.erl
new file mode 100644
index 0000000000..7a2b143dde
--- /dev/null
+++ b/lib/tools/test/cover_SUITE_data/compile_beam/z.erl
@@ -0,0 +1 @@
+-module(z).