您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

238 行
9.3 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. extra_src_dirs_at_root_and_in_erl_opts/1,
  14. build_basic_app/1,
  15. build_multi_apps/1,
  16. src_dir_takes_precedence_over_extra/1]).
  17. -include_lib("common_test/include/ct.hrl").
  18. suite() ->
  19. [].
  20. init_per_suite(Config) ->
  21. Config.
  22. end_per_suite(_Config) ->
  23. ok.
  24. init_per_testcase(_, Config) ->
  25. rebar_test_utils:init_rebar_state(Config).
  26. end_per_testcase(_, _Config) -> ok.
  27. all() ->
  28. [src_dirs_at_root, extra_src_dirs_at_root,
  29. src_dirs_in_erl_opts, extra_src_dirs_in_erl_opts,
  30. src_dirs_at_root_and_in_erl_opts, extra_src_dirs_at_root_and_in_erl_opts,
  31. build_basic_app, build_multi_apps, src_dir_takes_precedence_over_extra].
  32. src_dirs_at_root(Config) ->
  33. AppDir = ?config(apps, Config),
  34. Name = rebar_test_utils:create_random_name("app1_"),
  35. Vsn = rebar_test_utils:create_random_vsn(),
  36. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  37. RebarConfig = [{src_dirs, ["foo", "bar", "baz"]}],
  38. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  39. ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
  40. extra_src_dirs_at_root(Config) ->
  41. AppDir = ?config(apps, Config),
  42. Name = rebar_test_utils:create_random_name("app1_"),
  43. Vsn = rebar_test_utils:create_random_vsn(),
  44. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  45. RebarConfig = [{extra_src_dirs, ["foo", "bar", "baz"]}],
  46. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  47. ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
  48. src_dirs_in_erl_opts(Config) ->
  49. AppDir = ?config(apps, Config),
  50. Name = rebar_test_utils:create_random_name("app1_"),
  51. Vsn = rebar_test_utils:create_random_vsn(),
  52. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  53. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}],
  54. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  55. ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
  56. extra_src_dirs_in_erl_opts(Config) ->
  57. AppDir = ?config(apps, Config),
  58. Name = rebar_test_utils:create_random_name("app1_"),
  59. Vsn = rebar_test_utils:create_random_vsn(),
  60. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  61. RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}],
  62. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  63. ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
  64. src_dirs_at_root_and_in_erl_opts(Config) ->
  65. AppDir = ?config(apps, Config),
  66. Name = rebar_test_utils:create_random_name("app1_"),
  67. Vsn = rebar_test_utils:create_random_vsn(),
  68. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  69. RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}],
  70. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  71. ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
  72. extra_src_dirs_at_root_and_in_erl_opts(Config) ->
  73. AppDir = ?config(apps, Config),
  74. Name = rebar_test_utils:create_random_name("app1_"),
  75. Vsn = rebar_test_utils:create_random_vsn(),
  76. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  77. RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar"]}]}, {extra_src_dirs, ["baz", "qux"]}],
  78. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  79. ["bar", "baz", "foo", "qux"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
  80. build_basic_app(Config) ->
  81. AppDir = ?config(apps, Config),
  82. Name = rebar_test_utils:create_random_name("app1_"),
  83. Vsn = rebar_test_utils:create_random_vsn(),
  84. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  85. Extra = filename:join([AppDir, "extra", "extra.erl"]),
  86. ok = filelib:ensure_dir(Extra),
  87. Src = io_lib:format("-module(extra).~n-export([x/0]).~nx() -> ok.", []),
  88. ok = ec_file:write(Extra, Src),
  89. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  90. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  91. %% check that `extra.erl` was compiled to the `extra` dir
  92. ExtraOut = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  93. true = filelib:is_file(filename:join([ExtraOut, "extra.beam"])),
  94. %% check that `extra.erl` is not in the `modules` key of the app
  95. {ok, App} = file:consult(filename:join([AppDir,
  96. "_build",
  97. "default",
  98. "lib",
  99. Name,
  100. "ebin",
  101. Name ++ ".app"])),
  102. [{application, _, KVs}] = App,
  103. Mods = proplists:get_value(modules, KVs),
  104. false = lists:member(extra, Mods).
  105. build_multi_apps(Config) ->
  106. AppDir = ?config(apps, Config),
  107. Name1 = rebar_test_utils:create_random_name("app1_"),
  108. Vsn1 = rebar_test_utils:create_random_vsn(),
  109. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  110. Name2 = rebar_test_utils:create_random_name("app2_"),
  111. Vsn2 = rebar_test_utils:create_random_vsn(),
  112. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  113. Extra1 = filename:join([AppDir, "apps", Name1, "extra", "extra1.erl"]),
  114. ok = filelib:ensure_dir(Extra1),
  115. Src1 = io_lib:format("-module(extra1).~n-export([x/0]).~nx() -> ok.", []),
  116. ok = ec_file:write(Extra1, Src1),
  117. Extra2 = filename:join([AppDir, "apps", Name2, "extra", "extra2.erl"]),
  118. ok = filelib:ensure_dir(Extra2),
  119. Src2 = io_lib:format("-module(extra2).~n-export([x/0]).~nx() -> ok.", []),
  120. ok = ec_file:write(Extra2, Src2),
  121. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  122. rebar_test_utils:run_and_check(
  123. Config, RebarConfig, ["compile"],
  124. {ok, [{app, Name1}, {app, Name2}]}
  125. ),
  126. %% check that `extraX.erl` was compiled to the `ebin` dir
  127. ExtraOut1 = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  128. true = filelib:is_file(filename:join([ExtraOut1, "extra1.beam"])),
  129. ExtraOut2 = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  130. true = filelib:is_file(filename:join([ExtraOut2, "extra2.beam"])),
  131. %% check that `extraX.erl` is not in the `modules` key of the app
  132. {ok, App1} = file:consult(filename:join([AppDir,
  133. "_build",
  134. "default",
  135. "lib",
  136. Name1,
  137. "ebin",
  138. Name1 ++ ".app"])),
  139. [{application, _, KVs1}] = App1,
  140. Mods1 = proplists:get_value(modules, KVs1),
  141. false = lists:member(extra1, Mods1),
  142. {ok, App2} = file:consult(filename:join([AppDir,
  143. "_build",
  144. "default",
  145. "lib",
  146. Name2,
  147. "ebin",
  148. Name2 ++ ".app"])),
  149. [{application, _, KVs2}] = App2,
  150. Mods2 = proplists:get_value(modules, KVs2),
  151. false = lists:member(extra2, Mods2).
  152. src_dir_takes_precedence_over_extra(Config) ->
  153. AppDir = ?config(apps, Config),
  154. Name = rebar_test_utils:create_random_name("app1_"),
  155. Vsn = rebar_test_utils:create_random_vsn(),
  156. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  157. Extra = filename:join([AppDir, "extra", "extra.erl"]),
  158. ok = filelib:ensure_dir(Extra),
  159. Src = io_lib:format("-module(extra).~n-export([x/0]).~nx() -> ok.", []),
  160. ok = ec_file:write(Extra, Src),
  161. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}, {extra_src_dirs, ["extra"]}]}],
  162. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  163. %% check that `extra.erl` was compiled to the `extra` dir
  164. ExtraOut = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  165. true = filelib:is_file(filename:join([ExtraOut, "extra.beam"])),
  166. %% check that `extra.erl` is in the `modules` key of the app
  167. {ok, App} = file:consult(filename:join([AppDir,
  168. "_build",
  169. "default",
  170. "lib",
  171. Name,
  172. "ebin",
  173. Name ++ ".app"])),
  174. [{application, _, KVs}] = App,
  175. Mods = proplists:get_value(modules, KVs),
  176. true = lists:member(extra, Mods).