From a3d4cc1259babf1541d5e278f11fc9ec9be75bb0 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sun, 19 Apr 2015 12:54:32 -0500 Subject: track and cleanup code paths for different contexts --- test/rebar_compile_SUITE.erl | 13 ++++++++----- test/rebar_profiles_SUITE.erl | 11 ++++++++--- test/rebar_test_utils.erl | 3 ++- test/rebar_xref_SUITE.erl | 4 ++-- 4 files changed, 20 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 2fdf36d..ee262a1 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -102,10 +102,11 @@ build_checkout_deps(Config) -> Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}], {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])), - rebar_test_utils:run_and_check( + {ok, State} = rebar_test_utils:run_and_check( Config, RebarConfig, ["compile"], {ok, [{app, Name1}, {checkout, Name2}]} ), + code:add_paths(rebar_state:code_paths(State, all_deps)), ok = application:load(list_to_atom(Name2)), Loaded = application:loaded_applications(), {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded). @@ -307,10 +308,11 @@ deps_in_path(Config) -> ?assertEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, PkgName)]]), %% Build things - rebar_test_utils:run_and_check( + {ok, State} = rebar_test_utils:run_and_check( Config, RConf, ["compile"], {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]} ), + code:add_paths(rebar_state:code_paths(State, all_deps)), %% Find src name in there ?assertNotEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, DepName)]]), @@ -326,11 +328,12 @@ deps_in_path(Config) -> ?assertEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, PkgName)]]), %% Rebuild - rebar_test_utils:run_and_check( + {ok, State1} = rebar_test_utils:run_and_check( Config, RConf, ["compile"], {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]} ), %% Find src name in there + code:add_paths(rebar_state:code_paths(State1, all_deps)), ?assertNotEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, DepName)]]), %% find pkg name in there @@ -373,11 +376,11 @@ checkout_priority(Config) -> %% Rebuild and make sure the checkout apps are in path code:set_path(StartPaths), - rebar_test_utils:run_and_check( + {ok, State} = rebar_test_utils:run_and_check( Config, RConf, ["compile"], {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]} ), - + code:add_paths(rebar_state:code_paths(State, all_deps)), [DepPath] = [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, DepName)]], [PkgPath] = [Path || Path <- code:get_path(), diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 6288053..72969d3 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -160,9 +160,12 @@ profiles_remain_applied_with_config_present(Config) -> rebar_test_utils:create_config(AppDir, RebarConfig), - rebar_test_utils:run_and_check(Config, RebarConfig, + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "not_ok", "compile"], {ok, [{app, Name}]}), + Path = filename:join([AppDir, "_build", "not_ok", "lib", Name, "ebin"]), + code:add_path(Path), + Mod = list_to_atom("not_a_real_src_" ++ Name), true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])). @@ -196,7 +199,8 @@ test_profile_applied_before_compile(Config) -> RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:create_config(AppDir, RebarConfig), - rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}), + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}), + code:add_paths(rebar_state:code_paths(State, all_deps)), S = list_to_atom("not_a_real_src_" ++ Name), true = lists:member({d, 'TEST'}, proplists:get_value(options, S:module_info(compile), [])). @@ -211,7 +215,8 @@ test_profile_applied_before_eunit(Config) -> RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:create_config(AppDir, RebarConfig), - rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}), + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}), + code:add_paths(rebar_state:code_paths(State, all_deps)), T = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), true = lists:member({d, 'TEST'}, proplists:get_value(options, T:module_info(compile), [])). diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index d245c82..f764146 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -56,7 +56,8 @@ run_and_check(Config, RebarConfig, Command, Expect) -> ?assertEqual({error, Reason}, Res); {ok, Expected} -> {ok, _} = Res, - check_results(AppDir, Expected); + check_results(AppDir, Expected), + Res; return -> Res end diff --git a/test/rebar_xref_SUITE.erl b/test/rebar_xref_SUITE.erl index b2438cf..75d6786 100644 --- a/test/rebar_xref_SUITE.erl +++ b/test/rebar_xref_SUITE.erl @@ -44,7 +44,7 @@ init_per_testcase(Case, Config) -> [{app_name, Name}, {rebar_config, RebarConfig} | UpdConfig]. -end_per_testcase(_, Config) -> +end_per_testcase(_, _Config) -> ok. all() -> @@ -112,7 +112,7 @@ verify_test_results(xref_test, AppName, XrefResults, _QueryResults) -> ok; verify_test_results(xref_ignore_test, AppName, XrefResults, _QueryResults) -> AppModules = ["behaviour1", "behaviour2", "mymod", "othermod", "somemod"], - [Behaviour1Mod, Behaviour2Mod, MyMod, OtherMod, SomeMod] = + [_Behaviour1Mod, _Behaviour2Mod, _MyMod, _OtherMod, SomeMod] = [list_to_atom(AppName ++ "_" ++ Mod) || Mod <- AppModules], UndefFuns = proplists:get_value(undefined_functions, XrefResults), ?assertNot(lists:keymember(undefined_function_calls, 1, XrefResults)), -- cgit v1.1