summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-02-24 18:41:07 -0500
committerGitHub <noreply@github.com>2017-02-24 18:41:07 -0500
commit7918be19c36a7a81721a0e88f7f32df4cea81a3f (patch)
tree4ca77dcd8bb2529ce4ea9a12651b3c0db7c5fa8b /test
parent4725d363c5b5583c9910f078da38c5b3a1d97aab (diff)
parentab1f93d6fa712c3b85bce30cab09edb5ddf7f3d9 (diff)
Merge pull request #1486 from ferd/src_dir-is-respected
Add respect for src_dirs option in app_discover and app_info
Diffstat (limited to 'test')
-rw-r--r--test/rebar_src_dirs_SUITE.erl98
1 files changed, 93 insertions, 5 deletions
diff --git a/test/rebar_src_dirs_SUITE.erl b/test/rebar_src_dirs_SUITE.erl
index f854a94..bc22160 100644
--- a/test/rebar_src_dirs_SUITE.erl
+++ b/test/rebar_src_dirs_SUITE.erl
@@ -11,12 +11,16 @@
src_dirs_in_erl_opts/1,
extra_src_dirs_in_erl_opts/1,
src_dirs_at_root_and_in_erl_opts/1,
+ dupe_src_dirs_at_root_and_in_erl_opts/1,
extra_src_dirs_at_root_and_in_erl_opts/1,
build_basic_app/1,
build_multi_apps/1,
- src_dir_takes_precedence_over_extra/1]).
+ src_dir_takes_precedence_over_extra/1,
+ src_dir_checkout_dep/1,
+ app_src_info/1]).
-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
suite() ->
[].
@@ -35,8 +39,11 @@ end_per_testcase(_, _Config) -> ok.
all() ->
[src_dirs_at_root, extra_src_dirs_at_root,
src_dirs_in_erl_opts, extra_src_dirs_in_erl_opts,
- src_dirs_at_root_and_in_erl_opts, extra_src_dirs_at_root_and_in_erl_opts,
- build_basic_app, build_multi_apps, src_dir_takes_precedence_over_extra].
+ src_dirs_at_root_and_in_erl_opts,
+ dupe_src_dirs_at_root_and_in_erl_opts,
+ extra_src_dirs_at_root_and_in_erl_opts,
+ build_basic_app, build_multi_apps, src_dir_takes_precedence_over_extra,
+ src_dir_checkout_dep, app_src_info].
src_dirs_at_root(Config) ->
AppDir = ?config(apps, Config),
@@ -93,15 +100,47 @@ extra_src_dirs_in_erl_opts(Config) ->
src_dirs_at_root_and_in_erl_opts(Config) ->
AppDir = ?config(apps, Config),
- Name = rebar_test_utils:create_random_name("app1_"),
+ Name = rebar_test_utils:create_random_name("src_dirs_root_erlopts_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}],
+ %% move the .app.src file to one of the subdirs, out of src/
+ filelib:ensure_dir(filename:join([AppDir, "qux", "fake"])),
+ rebar_file_utils:mv(filename:join([AppDir, "src", Name ++ ".app.src"]),
+ filename:join([AppDir, "qux", Name ++ ".app.src"])),
+
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
- ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
+ ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []),
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
+ {ok, [{app, Name}]}),
+ ok.
+
+dupe_src_dirs_at_root_and_in_erl_opts(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("dupe_src_dirs_root_erlopts_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}],
+
+ %% move the .app.src file to one of the subdirs, out of src/
+ filelib:ensure_dir(filename:join([AppDir, "qux", "fake"])),
+ filelib:ensure_dir(filename:join([AppDir, "foo", "fake"])),
+ Src1 = filename:join([AppDir, "qux", Name ++ ".app.src"]),
+ Src2 = filename:join([AppDir, "foo", Name ++ ".app.src"]),
+ rebar_file_utils:mv(filename:join([AppDir, "src", Name ++ ".app.src"]),
+ Src1),
+ %% Then copy it over to create a conflict with dupes
+ file:copy(Src1, Src2),
+
+ {error, {rebar_prv_app_discovery, {multiple_app_files, [Src2, Src1]}}} =
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ok.
extra_src_dirs_at_root_and_in_erl_opts(Config) ->
AppDir = ?config(apps, Config),
@@ -236,3 +275,52 @@ src_dir_takes_precedence_over_extra(Config) ->
[{application, _, KVs}] = App,
Mods = proplists:get_value(modules, KVs),
true = lists:member(extra, Mods).
+
+src_dir_checkout_dep(Config) ->
+ AppDir = ?config(apps, Config),
+ AppName = rebar_test_utils:create_random_name("src_dir_checkout_app"),
+ DepName = rebar_test_utils:create_random_name("src_dir_checkout_dep"),
+ AtomDep = list_to_atom(DepName),
+
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, AppName, Vsn, [kernel, stdlib]),
+ RebarConfig = [{deps, [AtomDep]}],
+
+ DepDir = filename:join([?config(checkouts, Config), DepName]),
+ ct:pal("checkouts dir: ~p", [DepDir]),
+ rebar_test_utils:create_app(DepDir, DepName, Vsn, [kernel, stdlib]),
+
+
+ %% move the .app.src file to one of the subdirs, out of src/
+ rebar_file_utils:mv(filename:join([DepDir, "src"]),
+ filename:join([DepDir, "qux"])),
+ DepRebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]},
+ {src_dirs, ["baz", "qux"]}],
+ file:write_file(filename:join([DepDir, "rebar.config"]),
+ io_lib:format("~p.~n~p.~n", DepRebarConfig)),
+
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["compile"],
+ {ok, [{checkout, DepName}, {app, AppName}]}
+ ),
+ ok.
+
+app_src_info(Config) ->
+ PrivDir = ?config(priv_dir, Config),
+ AppName1 = rebar_test_utils:create_random_name("app_src_info"),
+ AppDir1 = filename:join(PrivDir, AppName1),
+ {ok, Info1} = rebar_app_info:new(AppName1, "1.0.0", AppDir1),
+ AppSrc1 = filename:join([AppDir1, "src", AppName1 ++ ".app.src"]),
+ ok = filelib:ensure_dir(AppSrc1),
+ ok = file:write_file(AppSrc1, "[]."),
+ ?assertEqual(AppSrc1, rebar_app_info:app_file_src(Info1)),
+
+ AppName2 = rebar_test_utils:create_random_name("app_src_info"),
+ AppDir2 = filename:join(PrivDir, AppName2),
+ {ok, Info2Tmp} = rebar_app_info:new(AppName2, "1.0.0", AppDir2),
+ Info2 = rebar_app_info:set(Info2Tmp, src_dirs, ["foo", "bar", "baz"]),
+ AppSrc2 = filename:join([AppDir2, "bar", AppName2 ++ ".app.src"]),
+ ok = filelib:ensure_dir(AppSrc2),
+ ok = file:write_file(AppSrc2, "[]."),
+ ?assertEqual(AppSrc2, rebar_app_info:app_file_src(Info2)),
+ ok.