summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mock_pkg_resource.erl2
-rw-r--r--test/rebar_compile_SUITE.erl40
-rw-r--r--test/rebar_erlydtl_SUITE.erl72
-rw-r--r--test/rebar_eunit_SUITE.erl12
-rw-r--r--test/rebar_install_deps_SUITE.erl81
-rw-r--r--test/rebar_profiles_SUITE.erl196
-rw-r--r--test/rebar_test_utils.erl7
-rw-r--r--test/rebar_unlock_SUITE.erl40
-rw-r--r--test/rebar_unlock_SUITE_data/rebar.lock40
-rw-r--r--test/rebar_upgrade_SUITE.erl15
-rw-r--r--test/rebar_xref_SUITE.erl4
11 files changed, 411 insertions, 98 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl
index 615e8a5..560caef 100644
--- a/test/mock_pkg_resource.erl
+++ b/test/mock_pkg_resource.erl
@@ -152,7 +152,7 @@ find_parts([{AppName, Deps}|Rest], Skip, Acc) ->
end.
to_graph_parts(Dict) ->
- LastUpdated = now(),
+ LastUpdated = os:timestamp(),
dict:fold(fun(K,V,{Ks,Vs}) ->
{_,Deps} = lists:keyfind(<<"deps">>, 1, V),
{[{K,LastUpdated}|Ks],
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 2fdf36d..bdab075 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -19,7 +19,8 @@
delete_beam_if_source_deleted/1,
checkout_priority/1,
compile_plugins/1,
- highest_version_of_pkg_dep/1]).
+ highest_version_of_pkg_dep/1,
+ parse_transform_test/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -46,7 +47,8 @@ all() ->
build_all_srcdirs, recompile_when_hrl_changes,
recompile_when_opts_change, dont_recompile_when_opts_dont_change,
dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted,
- deps_in_path, checkout_priority, compile_plugins, highest_version_of_pkg_dep].
+ deps_in_path, checkout_priority, compile_plugins, highest_version_of_pkg_dep,
+ parse_transform_test].
build_basic_app(Config) ->
AppDir = ?config(apps, Config),
@@ -102,10 +104,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 +310,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 +330,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 +378,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(),
@@ -446,3 +451,24 @@ highest_version_of_pkg_dep(Config) ->
Config, RConf, ["compile"],
{ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
).
+
+parse_transform_test(Config) ->
+ AppDir = ?config(apps, Config),
+
+ RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ ExtraSrc = <<"-module(pascal). "
+ "-export([parse_transform/2]). "
+ "parse_transform(Forms, _Options) -> "
+ "Forms.">>,
+
+ ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
+
+ EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
+ true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).
diff --git a/test/rebar_erlydtl_SUITE.erl b/test/rebar_erlydtl_SUITE.erl
deleted file mode 100644
index c9054fd..0000000
--- a/test/rebar_erlydtl_SUITE.erl
+++ /dev/null
@@ -1,72 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
--module(rebar_erlydtl_SUITE).
-
--export([suite/0,
- init_per_suite/1,
- end_per_suite/1,
- init_per_testcase/2,
- end_per_testcase/2,
- all/0,
- compile/1]).
-
--include_lib("common_test/include/ct.hrl").
--include_lib("eunit/include/eunit.hrl").
--include_lib("kernel/include/file.hrl").
-
-%% ===================================================================
-%% common_test callbacks
-%% ===================================================================
-
-suite() ->
- [].
-
-init_per_suite(Config) ->
- Config.
-
-end_per_suite(_Config) ->
- ok.
-
-
-init_per_testcase(_, Config) ->
- UpdConfig = rebar_test_utils:init_rebar_state(Config),
- AppDir = ?config(apps, UpdConfig),
-
- Name = rebar_test_utils:create_random_name("erlydtlapp_"),
- Vsn = rebar_test_utils:create_random_vsn(),
- rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
-
- write_dtl_file(AppDir, Name),
-
- RebarConfig = [{erl_opts, [debug_info]},
- {erlydtl_opts, []}],
- [{app_name, Name},
- {rebar_config, RebarConfig} | UpdConfig].
-
-end_per_testcase(_, _Config) ->
- ok.
-
-all() ->
- [compile].
-
-compile(Config) ->
- AppDir = ?config(apps, Config),
- AppName = ?config(app_name, Config),
- RebarConfig = ?config(rebar_config, Config),
- Beam = beam_file(AppDir, AppName),
- rebar_test_utils:run_and_check(
- Config, RebarConfig, ["erlydtl", "compile"],
- {ok, [{file, Beam}]}
- ).
-
-beam_file(AppDir, AppName) ->
- filename:join([AppDir, "_build", "default", "lib",
- AppName, "ebin", AppName++"_template_dtl.beam"]).
-
-write_dtl_file(Dir, AppName) ->
- Erl = filename:join([Dir, "priv", "templates", AppName++"_template.dtl"]),
- ok = filelib:ensure_dir(Erl),
- ok = ec_file:write(Erl, get_body()).
-
-get_body() ->
- ["[]"].
diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl
index 4ec92f2..ac74146 100644
--- a/test/rebar_eunit_SUITE.erl
+++ b/test/rebar_eunit_SUITE.erl
@@ -164,8 +164,8 @@ test_basic_defines(Config) ->
AppOpts = proplists:get_value(options, App:module_info(compile), []),
SuiteOpts = proplists:get_value(options, Suite:module_info(compile), []),
Expect = [{d, some_define}],
- lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts) end, Expect),
- lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts) end, Expect).
+ lists:foreach(fun(E) -> true = lists:member(E, AppOpts) end, Expect),
+ lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts) end, Expect).
test_multi_defines(Config) ->
AppDir = ?config(apps, Config),
@@ -198,10 +198,10 @@ test_multi_defines(Config) ->
AppOpts2 = proplists:get_value(options, App2:module_info(compile), []),
SuiteOpts2 = proplists:get_value(options, Suite2:module_info(compile), []),
Expect = [{d, some_define}],
- lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts1) end, Expect),
- lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts1) end, Expect),
- lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts2) end, Expect),
- lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts2) end, Expect).
+ lists:foreach(fun(E) -> true = lists:member(E, AppOpts1) end, Expect),
+ lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts1) end, Expect),
+ lists:foreach(fun(E) -> true = lists:member(E, AppOpts2) end, Expect),
+ lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts2) end, Expect).
test_single_app_flag(Config) ->
AppDir = ?config(apps, Config),
diff --git a/test/rebar_install_deps_SUITE.erl b/test/rebar_install_deps_SUITE.erl
index aebd3e3..d1a1118 100644
--- a/test/rebar_install_deps_SUITE.erl
+++ b/test/rebar_install_deps_SUITE.erl
@@ -2,6 +2,7 @@
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
+-include_lib("kernel/include/file.hrl").
all() -> [{group, git}, {group, pkg}].
@@ -9,7 +10,7 @@ groups() ->
[{all, [], [flat, pick_highest_left, pick_highest_right,
pick_smallest1, pick_smallest2,
circular1, circular2, circular_skip,
- fail_conflict]},
+ fail_conflict, default_profile, nondefault_profile]},
{git, [], [{group, all}]},
{pkg, [], [{group, all}]}].
@@ -114,7 +115,17 @@ deps(fail_conflict) ->
{[{"B", [{"C", "2", []}]},
{"C", "1", []}],
[{"C","2"}],
- rebar_abort}.
+ rebar_abort};
+deps(default_profile) ->
+ {[{"B", []},
+ {"C", []}],
+ [],
+ {ok, ["B", "C"]}};
+deps(nondefault_profile) ->
+ {[{"B", []},
+ {"C", []}],
+ [],
+ {ok, ["B", "C"]}}.
setup_project(fail_conflict, Config0, Deps) ->
DepsType = ?config(deps_type, Config0),
@@ -134,6 +145,25 @@ setup_project(fail_conflict, Config0, Deps) ->
mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Deps)}])
end,
[{rebarconfig, RebarConf} | Config];
+setup_project(nondefault_profile, Config0, Deps) ->
+ DepsType = ?config(deps_type, Config0),
+ Config = rebar_test_utils:init_rebar_state(
+ Config0,
+ "nondefault_profile_"++atom_to_list(DepsType)++"_"
+ ),
+ AppDir = ?config(apps, Config),
+ rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]),
+ TopDeps = rebar_test_utils:top_level_deps(Deps),
+ RebarConf = rebar_test_utils:create_config(AppDir, [{profiles, [
+ {nondef, [{deps, TopDeps}]}
+ ]}]),
+ case DepsType of
+ git ->
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]);
+ pkg ->
+ mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Deps)}])
+ end,
+ [{rebarconfig, RebarConf} | Config];
setup_project(Case, Config0, Deps) ->
DepsType = ?config(deps_type, Config0),
Config = rebar_test_utils:init_rebar_state(
@@ -174,6 +204,53 @@ fail_conflict(Config) ->
),
check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)).
+default_profile(Config) ->
+ {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
+ AppDir = ?config(apps, Config),
+ {ok, Apps} = Expect = ?config(expect, Config),
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["as", "profile", "install_deps"], Expect
+ ),
+ check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)),
+ BuildDir = filename:join([AppDir, "_build"]),
+ [?assertMatch({ok, #file_info{type=directory}},
+ file:read_file_info(filename:join([BuildDir, "default", "lib", App])))
+ || {dep, App} <- Apps],
+ [?assertMatch({ok, #file_info{type=directory}}, % somehow symlinks return dirs
+ file:read_file_info(filename:join([BuildDir, "profile", "lib", App])))
+ || {dep, App} <- Apps],
+ %% A second run to another profile also links default to the right spot
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["as", "other", "install_deps"], Expect
+ ),
+ [?assertMatch({ok, #file_info{type=directory}}, % somehow symlinks return dirs
+ file:read_file_info(filename:join([BuildDir, "other", "lib", App])))
+ || {dep, App} <- Apps].
+
+nondefault_profile(Config) ->
+ {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
+ AppDir = ?config(apps, Config),
+ {ok, Apps} = Expect = ?config(expect, Config),
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["as", "nondef", "install_deps"], Expect
+ ),
+ check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)),
+ BuildDir = filename:join([AppDir, "_build"]),
+ [?assertMatch({error, enoent},
+ file:read_file_info(filename:join([BuildDir, "default", "lib", App])))
+ || {dep, App} <- Apps],
+ [?assertMatch({ok, #file_info{type=directory}},
+ file:read_file_info(filename:join([BuildDir, "nondef", "lib", App])))
+ || {dep, App} <- Apps],
+ %% A second run to another profile doesn't link dependencies
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["as", "other", "install_deps"], Expect
+ ),
+ [?assertMatch({error, enoent},
+ file:read_file_info(filename:join([BuildDir, "default", "lib", App])))
+ || {dep, App} <- Apps].
+
+
run(Config) ->
{ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
rebar_test_utils:run_and_check(
diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl
index 6288053..b42df39 100644
--- a/test/rebar_profiles_SUITE.erl
+++ b/test/rebar_profiles_SUITE.erl
@@ -7,10 +7,16 @@
all/0,
profile_new_key/1,
profile_merge_keys/1,
+ explicit_profile_deduplicate_deps/1,
+ implicit_profile_deduplicate_deps/1,
+ all_deps_code_paths/1,
profile_merges/1,
+ same_profile_deduplication/1,
+ stack_deduplication/1,
add_to_profile/1,
add_to_existing_profile/1,
profiles_remain_applied_with_config_present/1,
+ deduplicated_paths/1,
test_profile_applied_at_completion/1,
test_profile_applied_before_compile/1,
test_profile_applied_before_eunit/1,
@@ -21,9 +27,12 @@
-include_lib("kernel/include/file.hrl").
all() ->
- [profile_new_key, profile_merge_keys, profile_merges,
+ [profile_new_key, profile_merge_keys, all_deps_code_paths, profile_merges,
+ explicit_profile_deduplicate_deps, implicit_profile_deduplicate_deps,
+ same_profile_deduplication, stack_deduplication,
add_to_profile, add_to_existing_profile,
profiles_remain_applied_with_config_present,
+ deduplicated_paths,
test_profile_applied_at_completion,
test_profile_applied_before_compile,
test_profile_applied_before_eunit,
@@ -95,6 +104,100 @@ profile_merge_keys(Config) ->
,{dep, "a", "1.0.0"}
,{dep, "b", "2.0.0"}]}).
+explicit_profile_deduplicate_deps(Config) ->
+ AppDir = ?config(apps, Config),
+
+ AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
+ ,{"a", "2.0.0", []}
+ ,{"b", "1.0.0", []}
+ ,{"b", "2.0.0", []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
+
+ Name = rebar_test_utils:create_random_name("explicit_profile_deduplicate_deps_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ FooDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []},
+ {"b", "2.0.0", []}])),
+ BarDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
+
+ RebarConfig = [{profiles,
+ [{foo,
+ [{deps, FooDeps}]},
+ {bar,
+ [{deps, BarDeps}]}]}],
+
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["as", "bar,foo,bar", "compile"], {ok, [{app, Name}
+ ,{dep, "a", "1.0.0"}
+ ,{dep, "b", "1.0.0"}]}).
+
+implicit_profile_deduplicate_deps(Config) ->
+ AppDir = ?config(apps, Config),
+
+ AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
+ ,{"a", "2.0.0", []}
+ ,{"b", "1.0.0", []}
+ ,{"b", "2.0.0", []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
+
+ Name = rebar_test_utils:create_random_name("implicit_profile_deduplicate_deps_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ TestDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []},
+ {"b", "2.0.0", []}])),
+ ProfileDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
+
+ RebarConfig = [{profiles,
+ [{test,
+ [{deps, TestDeps}]},
+ {bar,
+ [{deps, ProfileDeps}]}]}],
+
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["as", "test,bar", "eunit"], {ok, [{app, Name}
+ ,{dep, "a", "1.0.0"}
+ ,{dep, "b", "2.0.0"}]}).
+
+all_deps_code_paths(Config) ->
+ AppDir = ?config(apps, Config),
+
+ AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
+ ,{"b", "2.0.0", []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
+
+ Name = rebar_test_utils:create_random_name("all_deps_code_paths"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ Deps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}])),
+ ProfileDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])),
+
+ RebarConfig = [{deps, Deps},
+ {profiles,
+ [{all_deps_test,
+ [{deps, ProfileDeps}]}]}],
+ os:putenv("REBAR_PROFILE", "all_deps_test"),
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["compile"], {ok, [{app, Name}
+ ,{dep, "a", "1.0.0"}
+ ,{dep, "b", "2.0.0"}]}),
+ os:putenv("REBAR_PROFILE", ""),
+
+ Paths = rebar_state:code_paths(State, all_deps),
+ Path = lists:reverse(["_build", "all_deps_test", "lib", "b", "ebin"]),
+ ?assert(lists:any(fun(X) ->
+ Path =:= lists:sublist(lists:reverse(filename:split(X)), 5)
+ end, Paths)).
+
+
profile_merges(_Config) ->
RebarConfig = [{test1, [{key1, 1, 2}, key2]},
{test2, "hello"},
@@ -127,6 +230,72 @@ profile_merges(_Config) ->
[{key5, false}, {key5, true}] = rebar_state:get(State1, test5),
[{key6, true}, {key6, false}] = rebar_state:get(State1, test6).
+same_profile_deduplication(_Config) ->
+ RebarConfig = [{test1, [{key1, 1, 2}, key2]},
+ {test2, [foo]},
+ {test3, [key3]},
+ {profiles,
+ [{profile1,
+ [{test1, [{key3, 5}, {key2, "hello"}]},
+ {test2, [bar]},
+ {test3, []}
+ ]}]
+ }],
+ State = rebar_state:new(RebarConfig),
+ State1 = rebar_state:apply_profiles(State, [profile1, profile1, profile1]),
+
+ ?assertEqual([default, profile1], rebar_state:current_profiles(State1)),
+ Test1 = rebar_state:get(State1, test1),
+
+ %% Combine lists
+ ?assertEqual(lists:sort([key2, {key1, 1, 2}, {key3, 5}, {key2, "hello"}]),
+ lists:sort(Test1)),
+
+ %% Key2 from profile1 overrides key2 from default profile
+ ?assertEqual("hello", proplists:get_value(key2, Test1)),
+
+ %% Check that a newvalue of []/"" doesn't override non-string oldvalues
+ ?assertEqual([key3], rebar_state:get(State1, test3)),
+ ?assertEqual([bar, foo], rebar_state:get(State1, test2)).
+
+stack_deduplication(_Config) ->
+ RebarConfig = [
+ {test_key, default},
+ {test_list, [ {foo, default} ]},
+ {profiles, [
+ {a, [
+ {test_key, a},
+ {test_list, [ {foo, a} ]}
+ ]},
+ {b, [
+ {test_key, b},
+ {test_list, [ {foo, b} ]}
+ ]},
+ {c, [
+ {test_key, c},
+ {test_list, [ {foo, c} ]}
+ ]},
+ {d, [
+ {test_key, d},
+ {test_list, [ {foo, d} ]}
+ ]},
+ {e, [
+ {test_key, e},
+ {test_list, [ {foo, e} ]}
+ ]}
+ ]}
+ ],
+ State = rebar_state:new(RebarConfig),
+ State1 = rebar_state:apply_profiles(State, [a, b, c, d, e, a, e, b]),
+ ?assertEqual(b, rebar_state:get(State1, test_key)),
+
+ TestList = rebar_state:get(State1, test_list),
+ ?assertEqual(
+ [{foo, b}, {foo, e}, {foo, a}, {foo, d}, {foo, c}, {foo, default} ],
+ TestList
+ ),
+ ?assertEqual(b, proplists:get_value(foo, TestList)).
+
add_to_profile(_Config) ->
RebarConfig = [{foo, true}, {bar, false}],
State = rebar_state:new(RebarConfig),
@@ -163,10 +332,29 @@ profiles_remain_applied_with_config_present(Config) ->
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_patha(Path),
+
Mod = list_to_atom("not_a_real_src_" ++ Name),
true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])).
+deduplicated_paths(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("deduplicated_paths_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig = [],
+ rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["as", "a,b,c,d,e,a,e,b", "compile"],
+ {ok, [{app, Name}]}),
+
+ Path = filename:join([AppDir, "_build", "c+d+a+e+b", "lib", Name, "ebin"]),
+ ?assert(filelib:is_dir(Path)).
+
test_profile_applied_at_completion(Config) ->
AppDir = ?config(apps, Config),
@@ -196,7 +384,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 +400,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..2cdc58b 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
@@ -103,12 +104,12 @@ create_config(AppDir, Contents) ->
%% @doc Util to create a random variation of a given name.
create_random_name(Name) ->
- random:seed(erlang:now()),
+ random:seed(os:timestamp()),
Name ++ erlang:integer_to_list(random:uniform(1000000)).
%% @doc Util to create a random variation of a given version.
create_random_vsn() ->
- random:seed(erlang:now()),
+ random:seed(os:timestamp()),
lists:flatten([erlang:integer_to_list(random:uniform(100)),
".", erlang:integer_to_list(random:uniform(100)),
".", erlang:integer_to_list(random:uniform(100))]).
diff --git a/test/rebar_unlock_SUITE.erl b/test/rebar_unlock_SUITE.erl
new file mode 100644
index 0000000..31dca72
--- /dev/null
+++ b/test/rebar_unlock_SUITE.erl
@@ -0,0 +1,40 @@
+-module(rebar_unlock_SUITE).
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+-compile(export_all).
+
+all() -> [unlock, unlock_all].
+
+init_per_testcase(Case, Config0) ->
+ Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)),
+ Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
+ ec_file:copy(filename:join(?config(data_dir, Config), "rebar.lock"),
+ Lockfile),
+ [{lockfile, Lockfile} | Config].
+
+end_per_testcase(_, Config) ->
+ Config.
+
+unlock(Config) ->
+ Locks = read_locks(Config),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}),
+ Locks = read_locks(Config),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", "uuid"], {ok, []}),
+ ?assertEqual(Locks -- ["uuid"], read_locks(Config)),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", "gproc,itc"], {ok, []}),
+ ?assertEqual(Locks -- ["uuid","gproc","itc"], read_locks(Config)),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", string:join(Locks,",")], {ok, []}),
+ ?assertEqual({error, enoent}, read_locks(Config)),
+ ok.
+
+unlock_all(Config) ->
+ [_|_] = read_locks(Config),
+ rebar_test_utils:run_and_check(Config, [], ["unlock"], {ok, []}),
+ ?assertEqual({error, enoent}, read_locks(Config)),
+ ok.
+
+read_locks(Config) ->
+ case file:consult(?config(lockfile, Config)) of
+ {ok, [Locks]} -> [binary_to_list(element(1,Lock)) || Lock <- Locks];
+ Other -> Other
+ end.
diff --git a/test/rebar_unlock_SUITE_data/rebar.lock b/test/rebar_unlock_SUITE_data/rebar.lock
new file mode 100644
index 0000000..ab68d8e
--- /dev/null
+++ b/test/rebar_unlock_SUITE_data/rebar.lock
@@ -0,0 +1,40 @@
+[{<<"meck">>,
+ {git,"git://github.com/eproxus/meck",
+ {ref,"69664df5d0e01a0ae27efb62831d6eea45cc1cd4"}},
+ 3},
+ {<<"itc">>,
+ {git,"git://github.com/ferd/Interval-Tree-Clocks.git",
+ {ref,"168449da42871892f6047733edddf33936dd660f"}},
+ 2},
+ {<<"bitcask">>,
+ {git,"https://github.com/basho/bitcask.git",
+ {ref,"c3e9cc5e64bcfd6e342a85932a90428cfdc1ee2d"}},
+ 2},
+ {<<"quickrand">>,
+ {git,"https://github.com/okeuday/quickrand.git",
+ {ref,"0395a10b94472ccbe38b62bbfa9d0fc1ddac1dd7"}},
+ 1},
+ {<<"merklet">>,
+ {git,"git://github.com/ferd/merklet.git",
+ {ref,"21b5797a21ab6aa1ddb6740799372d2d4b6a6054"}},
+ 1},
+ {<<"interclock">>,
+ {git,"git://github.com/ferd/interclock.git",
+ {ref,"6a8b7443fa200da16d819f058e4dc8a0a75eca1e"}},
+ 1},
+ {<<"gproc">>,
+ {git,"git://github.com/uwiger/gproc.git",
+ {ref,"7655bddc4397d0cc3f7c4d95e7b96790605946fe"}},
+ 1},
+ {<<"uuid">>,
+ {git,"https://github.com/okeuday/uuid.git",
+ {ref,"f7c141c8359cd690faba0d2684b449a07db8e915"}},
+ 0},
+ {<<"peeranha">>,
+ {git,"https://github.com/ferd/peeranha.git",
+ {ref,"3bdbdadf6e34a1705bf2669eb28acd32a4fc9166"}},
+ 0},
+ {<<"file_monitor">>,
+ {git,"https://github.com/richcarl/file_monitor.git",
+ {ref,"4910b991bf3166377985d7ed961665c4b24e3de6"}},
+ 0}].
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index 14186be..1dc0af2 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -10,7 +10,7 @@ groups() ->
pair_a, pair_b, pair_ab, pair_c, pair_all,
triplet_a, triplet_b, triplet_c,
tree_a, tree_b, tree_c, tree_c2, tree_ac, tree_all,
- delete_d]},
+ delete_d, promote]},
{git, [], [{group, all}]},
{pkg, [], [{group, all}]}].
@@ -351,7 +351,17 @@ upgrades(delete_d) ->
],
["A","B", "C"],
%% upgrade vs. new tree
- {"", [{"A","2"}, "B", "C"]}}.
+ {"", [{"A","2"}, "B", "C"]}};
+upgrades(promote) ->
+ {[{"A", "1", [{"C", "1", []}]},
+ {"B", "1", [{"D", "1", []}]}
+ ],
+ [{"A", "2", [{"C", "2", []}]},
+ {"B", "2", [{"D", "2", []}]},
+ {"C", "3", []}
+ ],
+ ["A","B","C","D"],
+ {"C", [{"A","1"},{"C","3"},{"B","1"},{"D","1"}]}}.
%% TODO: add a test that verifies that unlocking files and then
%% running the upgrade code is enough to properly upgrade things.
@@ -414,6 +424,7 @@ tree_c(Config) -> run(Config).
tree_c2(Config) -> run(Config).
tree_ac(Config) -> run(Config).
tree_all(Config) -> run(Config).
+promote(Config) -> run(Config).
delete_d(Config) ->
meck:new(rebar_log, [no_link, passthrough]),
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)),