From 29231033bfa618e5c4e1c50a5cefba32e02f2708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Nov 2012 13:45:37 +0100 Subject: cover now relies on the compile info to find file sources Prior to this commit, cover relied on a simple heuristic that traverses directory from the beam file to find a source file. The heuristic was maintained with this patch but, if it fails, it fallbacks to the source value in the module compile info. In order to illustrate how it works, one of the tests that could not find its source now passes successfully (showing the source lookup is more robust). --- lib/tools/test/cover_SUITE.erl | 15 +++++++++++++-- lib/tools/test/cover_SUITE_data/compile_beam/z.erl | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 lib/tools/test/cover_SUITE_data/compile_beam/z.erl (limited to 'lib/tools/test') 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). -- cgit v1.2.3 From f3fb48d42329d54b463e7434ff28bb51e4dde4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Nov 2012 13:08:35 +0100 Subject: Ensure cover keeps the proper file source Whenever a module is compiled via compile:forms/2, the source is set to current directory unless a source option is passed to compile. This commit ensures that cover passes the source information to compile:forms/2 to ensure the source won't be modified after the module is cover compiled. --- lib/tools/test/cover_SUITE.erl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/tools/test') diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl index 2156390244..5abc5c41b1 100644 --- a/lib/tools/test/cover_SUITE.erl +++ b/lib/tools/test/cover_SUITE.erl @@ -149,7 +149,9 @@ compile(Config) when is_list(Config) -> ok = beam_lib:crypto_key_fun(simple_crypto_fun(Key)), {ok,crypt} = cover:compile_beam("crypt.beam") end, + Path = filename:join([?config(data_dir, Config), "compile_beam", "v.erl"]), ?line {ok,v} = cover:compile_beam(v), + {source,Path} = lists:keyfind(source, 1, v:module_info(compile)), ?line {ok,w} = cover:compile_beam("w.beam"), ?line {error,{no_abstract_code,"./x.beam"}} = cover:compile_beam(x), ?line {error,{already_cover_compiled,no_beam_found,a}}=cover:compile_beam(a), -- cgit v1.2.3 From 261880cfbebafddb61c728ed873f4e93107d9af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Nov 2012 12:51:34 +0100 Subject: Fix a bug in cover when used with no_auto_import Cover was rewriting guard clauses as non-remote calls. That said, if a guard contains erlang:is_binary(Binary), Cover was incorrectly removing the erlang prefix which lead to errors if is_binary is not auto imported. This commit keeps the abstract format as it is. --- lib/tools/test/cover_SUITE_data/compile_beam/v.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/tools/test') diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/v.erl b/lib/tools/test/cover_SUITE_data/compile_beam/v.erl index 007957297a..7fb0b08d40 100644 --- a/lib/tools/test/cover_SUITE_data/compile_beam/v.erl +++ b/lib/tools/test/cover_SUITE_data/compile_beam/v.erl @@ -1,6 +1,9 @@ -module(v). - --export([f/0]). +-compile({ no_auto_import, [is_integer/1] }). +-export([f/0,f/1]). f() -> ok. + +f(Number) when erlang:is_integer(Number) -> + Number. -- cgit v1.2.3