25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

309 satır
12 KiB

  1. -module(rebar_src_dirs_SUITE).
  2. -export([suite/0,
  3. init_per_suite/1,
  4. end_per_suite/1,
  5. init_per_testcase/2,
  6. end_per_testcase/2,
  7. all/0,
  8. src_dirs_at_root/1,
  9. extra_src_dirs_at_root/1,
  10. src_dirs_in_erl_opts/1,
  11. extra_src_dirs_in_erl_opts/1,
  12. src_dirs_at_root_and_in_erl_opts/1,
  13. dupe_src_dirs_at_root_and_in_erl_opts/1,
  14. extra_src_dirs_at_root_and_in_erl_opts/1,
  15. build_basic_app/1,
  16. build_multi_apps/1,
  17. src_dir_takes_precedence_over_extra/1,
  18. src_dir_checkout_dep/1]).
  19. -include_lib("common_test/include/ct.hrl").
  20. suite() ->
  21. [].
  22. init_per_suite(Config) ->
  23. Config.
  24. end_per_suite(_Config) ->
  25. ok.
  26. init_per_testcase(_, Config) ->
  27. rebar_test_utils:init_rebar_state(Config).
  28. end_per_testcase(_, _Config) -> ok.
  29. all() ->
  30. [src_dirs_at_root, extra_src_dirs_at_root,
  31. src_dirs_in_erl_opts, extra_src_dirs_in_erl_opts,
  32. src_dirs_at_root_and_in_erl_opts,
  33. dupe_src_dirs_at_root_and_in_erl_opts,
  34. extra_src_dirs_at_root_and_in_erl_opts,
  35. build_basic_app, build_multi_apps, src_dir_takes_precedence_over_extra,
  36. src_dir_checkout_dep].
  37. src_dirs_at_root(Config) ->
  38. AppDir = ?config(apps, Config),
  39. Name = rebar_test_utils:create_random_name("app1_"),
  40. Vsn = rebar_test_utils:create_random_vsn(),
  41. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  42. RebarConfig = [{src_dirs, ["foo", "bar", "baz"]}],
  43. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  44. ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
  45. extra_src_dirs_at_root(Config) ->
  46. AppDir = ?config(apps, Config),
  47. Name = rebar_test_utils:create_random_name("app1_"),
  48. Vsn = rebar_test_utils:create_random_vsn(),
  49. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  50. RebarConfig = [{extra_src_dirs, ["foo", "bar", "baz"]}],
  51. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  52. ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
  53. src_dirs_in_erl_opts(Config) ->
  54. AppDir = ?config(apps, Config),
  55. Name = rebar_test_utils:create_random_name("app1_"),
  56. Vsn = rebar_test_utils:create_random_vsn(),
  57. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  58. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}],
  59. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  60. ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
  61. extra_src_dirs_in_erl_opts(Config) ->
  62. AppDir = ?config(apps, Config),
  63. Name = rebar_test_utils:create_random_name("app1_"),
  64. Vsn = rebar_test_utils:create_random_vsn(),
  65. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  66. RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}],
  67. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  68. ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
  69. src_dirs_at_root_and_in_erl_opts(Config) ->
  70. AppDir = ?config(apps, Config),
  71. Name = rebar_test_utils:create_random_name("src_dirs_root_erlopts_"),
  72. Vsn = rebar_test_utils:create_random_vsn(),
  73. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  74. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}],
  75. %% move the .app.src file to one of the subdirs, out of src/
  76. filelib:ensure_dir(filename:join([AppDir, "qux", "fake"])),
  77. rebar_file_utils:mv(filename:join([AppDir, "src", Name ++ ".app.src"]),
  78. filename:join([AppDir, "qux", Name ++ ".app.src"])),
  79. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  80. ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []),
  81. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  82. {ok, [{app, Name}]}),
  83. ok.
  84. dupe_src_dirs_at_root_and_in_erl_opts(Config) ->
  85. AppDir = ?config(apps, Config),
  86. Name = rebar_test_utils:create_random_name("dupe_src_dirs_root_erlopts_"),
  87. Vsn = rebar_test_utils:create_random_vsn(),
  88. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  89. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}],
  90. %% move the .app.src file to one of the subdirs, out of src/
  91. filelib:ensure_dir(filename:join([AppDir, "qux", "fake"])),
  92. filelib:ensure_dir(filename:join([AppDir, "foo", "fake"])),
  93. Src1 = filename:join([AppDir, "qux", Name ++ ".app.src"]),
  94. Src2 = filename:join([AppDir, "foo", Name ++ ".app.src"]),
  95. rebar_file_utils:mv(filename:join([AppDir, "src", Name ++ ".app.src"]),
  96. Src1),
  97. %% Then copy it over to create a conflict with dupes
  98. file:copy(Src1, Src2),
  99. {error, {rebar_prv_app_discovery, {multiple_app_files, [Src2, Src1]}}} =
  100. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  101. ok.
  102. extra_src_dirs_at_root_and_in_erl_opts(Config) ->
  103. AppDir = ?config(apps, Config),
  104. Name = rebar_test_utils:create_random_name("app1_"),
  105. Vsn = rebar_test_utils:create_random_vsn(),
  106. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  107. RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar"]}]}, {extra_src_dirs, ["baz", "qux"]}],
  108. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  109. ["bar", "baz", "foo", "qux"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
  110. build_basic_app(Config) ->
  111. AppDir = ?config(apps, Config),
  112. Name = rebar_test_utils:create_random_name("app1_"),
  113. Vsn = rebar_test_utils:create_random_vsn(),
  114. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  115. Extra = filename:join([AppDir, "extra", "extra.erl"]),
  116. ok = filelib:ensure_dir(Extra),
  117. Src = io_lib:format("-module(extra).~n-export([x/0]).~nx() -> ok.", []),
  118. ok = ec_file:write(Extra, Src),
  119. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  120. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  121. %% check that `extra.erl` was compiled to the `extra` dir
  122. ExtraOut = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  123. true = filelib:is_file(filename:join([ExtraOut, "extra.beam"])),
  124. %% check that `extra.erl` is not in the `modules` key of the app
  125. {ok, App} = file:consult(filename:join([AppDir,
  126. "_build",
  127. "default",
  128. "lib",
  129. Name,
  130. "ebin",
  131. Name ++ ".app"])),
  132. [{application, _, KVs}] = App,
  133. Mods = proplists:get_value(modules, KVs),
  134. false = lists:member(extra, Mods).
  135. build_multi_apps(Config) ->
  136. AppDir = ?config(apps, Config),
  137. Name1 = rebar_test_utils:create_random_name("app1_"),
  138. Vsn1 = rebar_test_utils:create_random_vsn(),
  139. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  140. Name2 = rebar_test_utils:create_random_name("app2_"),
  141. Vsn2 = rebar_test_utils:create_random_vsn(),
  142. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  143. Extra1 = filename:join([AppDir, "apps", Name1, "extra", "extra1.erl"]),
  144. ok = filelib:ensure_dir(Extra1),
  145. Src1 = io_lib:format("-module(extra1).~n-export([x/0]).~nx() -> ok.", []),
  146. ok = ec_file:write(Extra1, Src1),
  147. Extra2 = filename:join([AppDir, "apps", Name2, "extra", "extra2.erl"]),
  148. ok = filelib:ensure_dir(Extra2),
  149. Src2 = io_lib:format("-module(extra2).~n-export([x/0]).~nx() -> ok.", []),
  150. ok = ec_file:write(Extra2, Src2),
  151. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  152. rebar_test_utils:run_and_check(
  153. Config, RebarConfig, ["compile"],
  154. {ok, [{app, Name1}, {app, Name2}]}
  155. ),
  156. %% check that `extraX.erl` was compiled to the `ebin` dir
  157. ExtraOut1 = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  158. true = filelib:is_file(filename:join([ExtraOut1, "extra1.beam"])),
  159. ExtraOut2 = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  160. true = filelib:is_file(filename:join([ExtraOut2, "extra2.beam"])),
  161. %% check that `extraX.erl` is not in the `modules` key of the app
  162. {ok, App1} = file:consult(filename:join([AppDir,
  163. "_build",
  164. "default",
  165. "lib",
  166. Name1,
  167. "ebin",
  168. Name1 ++ ".app"])),
  169. [{application, _, KVs1}] = App1,
  170. Mods1 = proplists:get_value(modules, KVs1),
  171. false = lists:member(extra1, Mods1),
  172. {ok, App2} = file:consult(filename:join([AppDir,
  173. "_build",
  174. "default",
  175. "lib",
  176. Name2,
  177. "ebin",
  178. Name2 ++ ".app"])),
  179. [{application, _, KVs2}] = App2,
  180. Mods2 = proplists:get_value(modules, KVs2),
  181. false = lists:member(extra2, Mods2).
  182. src_dir_takes_precedence_over_extra(Config) ->
  183. AppDir = ?config(apps, Config),
  184. Name = rebar_test_utils:create_random_name("app1_"),
  185. Vsn = rebar_test_utils:create_random_vsn(),
  186. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  187. Extra = filename:join([AppDir, "extra", "extra.erl"]),
  188. ok = filelib:ensure_dir(Extra),
  189. Src = io_lib:format("-module(extra).~n-export([x/0]).~nx() -> ok.", []),
  190. ok = ec_file:write(Extra, Src),
  191. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}, {extra_src_dirs, ["extra"]}]}],
  192. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  193. %% check that `extra.erl` was compiled to the `extra` dir
  194. ExtraOut = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  195. true = filelib:is_file(filename:join([ExtraOut, "extra.beam"])),
  196. %% check that `extra.erl` is in the `modules` key of the app
  197. {ok, App} = file:consult(filename:join([AppDir,
  198. "_build",
  199. "default",
  200. "lib",
  201. Name,
  202. "ebin",
  203. Name ++ ".app"])),
  204. [{application, _, KVs}] = App,
  205. Mods = proplists:get_value(modules, KVs),
  206. true = lists:member(extra, Mods).
  207. src_dir_checkout_dep(Config) ->
  208. AppDir = ?config(apps, Config),
  209. AppName = rebar_test_utils:create_random_name("src_dir_checkout_app"),
  210. DepName = rebar_test_utils:create_random_name("src_dir_checkout_dep"),
  211. AtomDep = list_to_atom(DepName),
  212. Vsn = rebar_test_utils:create_random_vsn(),
  213. rebar_test_utils:create_app(AppDir, AppName, Vsn, [kernel, stdlib]),
  214. RebarConfig = [{deps, [AtomDep]}],
  215. DepDir = filename:join([?config(checkouts, Config), DepName]),
  216. ct:pal("checkouts dir: ~p", [DepDir]),
  217. rebar_test_utils:create_app(DepDir, DepName, Vsn, [kernel, stdlib]),
  218. %% move the .app.src file to one of the subdirs, out of src/
  219. rebar_file_utils:mv(filename:join([DepDir, "src"]),
  220. filename:join([DepDir, "qux"])),
  221. DepRebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]},
  222. {src_dirs, ["baz", "qux"]}],
  223. file:write_file(filename:join([DepDir, "rebar.config"]),
  224. io_lib:format("~p.~n~p.~n", DepRebarConfig)),
  225. rebar_test_utils:run_and_check(
  226. Config, RebarConfig, ["compile"],
  227. {ok, [{checkout, DepName}, {app, AppName}]}
  228. ),
  229. % {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  230. % ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []),
  231. % rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  232. % {ok, [{app, Name}]}),
  233. ok.