You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
9.2 KiB

пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
  1. -module(rebar_dir_SUITE).
  2. -export([all/0, init_per_testcase/2, end_per_testcase/2]).
  3. -export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]).
  4. -export([src_dirs/1, extra_src_dirs/1, all_src_dirs/1]).
  5. -export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]).
  6. -export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]).
  7. -export([global_cache_dir/1, default_global_cache_dir/1, overwrite_default_global_cache_dir/1]).
  8. -include_lib("common_test/include/ct.hrl").
  9. -include_lib("eunit/include/eunit.hrl").
  10. -include_lib("kernel/include/file.hrl").
  11. all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
  12. src_dirs, extra_src_dirs, all_src_dirs,
  13. profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs,
  14. retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir,
  15. default_global_cache_dir, overwrite_default_global_cache_dir].
  16. init_per_testcase(default_global_cache_dir, Config) ->
  17. [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
  18. NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
  19. ,{root_dir, AppsDir}]),
  20. [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
  21. init_per_testcase(overwrite_default_global_cache_dir, Config) ->
  22. os:putenv("REBAR_CACHE_DIR", ?config(priv_dir, Config)),
  23. [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
  24. NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
  25. ,{root_dir, AppsDir}]),
  26. [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
  27. init_per_testcase(_, Config) ->
  28. C = rebar_test_utils:init_rebar_state(Config),
  29. AppDir = ?config(apps, C),
  30. Name1 = rebar_test_utils:create_random_name("app1_"),
  31. Vsn1 = rebar_test_utils:create_random_vsn(),
  32. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  33. Name2 = rebar_test_utils:create_random_name("app2_"),
  34. Vsn2 = rebar_test_utils:create_random_vsn(),
  35. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  36. [{app_one, Name1}, {app_two, Name2}] ++ C.
  37. end_per_testcase(_, _Config) -> ok.
  38. default_src_dirs(Config) ->
  39. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  40. [] = rebar_dir:src_dirs(rebar_state:opts(State)),
  41. ["src"] = rebar_dir:src_dirs(rebar_state:opts(State), ["src"]).
  42. default_extra_src_dirs(Config) ->
  43. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  44. [] = rebar_dir:extra_src_dirs(rebar_state:opts(State)),
  45. ["src"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), ["src"]).
  46. default_all_src_dirs(Config) ->
  47. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  48. [] = rebar_dir:all_src_dirs(rebar_state:opts(State)),
  49. ["src", "test"] = rebar_dir:all_src_dirs(rebar_state:opts(State), ["src"], ["test"]).
  50. src_dirs(Config) ->
  51. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}],
  52. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  53. ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)).
  54. extra_src_dirs(Config) ->
  55. RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}],
  56. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  57. ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State)).
  58. all_src_dirs(Config) ->
  59. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}, {extra_src_dirs, ["baz", "qux"]}]}],
  60. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  61. ["bar", "baz", "foo", "qux"] = rebar_dir:all_src_dirs(rebar_state:opts(State)).
  62. profile_src_dirs(Config) ->
  63. RebarConfig = [
  64. {erl_opts, [{src_dirs, ["foo", "bar"]}]},
  65. {profiles, [
  66. {more, [{erl_opts, [{src_dirs, ["baz", "qux"]}]}]}
  67. ]}
  68. ],
  69. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return),
  70. R = lists:sort(["foo", "bar", "baz", "qux"]),
  71. R = rebar_dir:src_dirs(rebar_state:opts(State)).
  72. profile_extra_src_dirs(Config) ->
  73. RebarConfig = [
  74. {erl_opts, [{extra_src_dirs, ["foo", "bar"]}]},
  75. {profiles, [
  76. {more, [{erl_opts, [{extra_src_dirs, ["baz", "qux"]}]}]}
  77. ]}
  78. ],
  79. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return),
  80. R = lists:sort(["foo", "bar", "baz", "qux"]),
  81. R = rebar_dir:extra_src_dirs(rebar_state:opts(State)).
  82. profile_all_src_dirs(Config) ->
  83. RebarConfig = [
  84. {erl_opts, [{src_dirs, ["foo"]}, {extra_src_dirs, ["bar"]}]},
  85. {profiles, [
  86. {more, [{erl_opts, [{src_dirs, ["baz"]}, {extra_src_dirs, ["qux"]}]}]}
  87. ]}
  88. ],
  89. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return),
  90. R = lists:sort(["foo", "bar", "baz", "qux"]),
  91. R = rebar_dir:all_src_dirs(rebar_state:opts(State)).
  92. retarget_path(Config) ->
  93. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  94. BaseDir = rebar_dir:base_dir(State),
  95. Name1 = ?config(app_one, Config),
  96. Name2 = ?config(app_two, Config),
  97. ?assertEqual(filename:join([BaseDir, "lib", Name1, "test"]),
  98. rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name1, "test"]))),
  99. ?assertEqual(filename:join([BaseDir, "lib", Name2, "test"]),
  100. rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name2, "test"]))),
  101. ?assertEqual(filename:join([BaseDir, "lib", Name1, "more_test"]),
  102. rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name1, "more_test"]))),
  103. ?assertEqual(filename:join([BaseDir, "test"]),
  104. rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "test"]))),
  105. ?assertEqual(filename:join([BaseDir, "some_other_dir"]),
  106. rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "some_other_dir"]))),
  107. ?assertEqual("/somewhere/outside/the/project",
  108. rebar_dir:retarget_path(State, "/somewhere/outside/the/project")).
  109. alt_base_dir_abs(Config) ->
  110. AltName = lists:flatten(io_lib:format("~p", [os:timestamp()])),
  111. AltBaseDir = filename:join(?config(priv_dir, Config), AltName),
  112. RebarConfig = [{base_dir, AltBaseDir}],
  113. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  114. BaseDir = rebar_dir:base_dir(State),
  115. ?assertEqual(filename:join(AltBaseDir, "default"), BaseDir),
  116. Name1 = ?config(app_one, Config),
  117. Name2 = ?config(app_two, Config),
  118. ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name1, "ebin"]))),
  119. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".app"]))),
  120. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".beam"]))),
  121. ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
  122. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
  123. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
  124. alt_base_dir_rel(Config) ->
  125. AltName = lists:flatten(io_lib:format("~p", [os:timestamp()])),
  126. AltBaseDir = filename:join("..", AltName),
  127. RebarConfig = [{base_dir, AltBaseDir}],
  128. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  129. BaseDir = rebar_dir:base_dir(State),
  130. Name1 = ?config(app_one, Config),
  131. Name2 = ?config(app_two, Config),
  132. ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name1, "ebin"]))),
  133. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".app"]))),
  134. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".beam"]))),
  135. ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
  136. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
  137. ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
  138. global_cache_dir(Config) ->
  139. RebarConfig = [{erl_opts, []}],
  140. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  141. DataDir = ?config(priv_dir, Config),
  142. Expected = filename:join([DataDir, "cache"]),
  143. ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
  144. default_global_cache_dir(Config) ->
  145. RebarConfig = [{erl_opts, []}],
  146. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  147. Expected = filename:join([rebar_dir:home_dir(), ".cache", "rebar3"]),
  148. ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
  149. overwrite_default_global_cache_dir(Config) ->
  150. RebarConfig = [{erl_opts, []}],
  151. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  152. Expected = ?config(priv_dir, Config),
  153. ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).