Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

151 linhas
5.9 KiB

  1. -module(rebar_extra_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. build_basic_app/1,
  9. build_multi_apps/1,
  10. src_dir_takes_precedence/1]).
  11. -include_lib("common_test/include/ct.hrl").
  12. suite() ->
  13. [].
  14. init_per_suite(Config) ->
  15. Config.
  16. end_per_suite(_Config) ->
  17. ok.
  18. init_per_testcase(_, Config) ->
  19. rebar_test_utils:init_rebar_state(Config).
  20. end_per_testcase(_, _Config) -> ok.
  21. all() ->
  22. [build_basic_app, build_multi_apps, src_dir_takes_precedence].
  23. build_basic_app(Config) ->
  24. AppDir = ?config(apps, Config),
  25. Name = rebar_test_utils:create_random_name("app1_"),
  26. Vsn = rebar_test_utils:create_random_vsn(),
  27. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  28. Extra = filename:join([AppDir, "extra", "extra.erl"]),
  29. ok = filelib:ensure_dir(Extra),
  30. Src = io_lib:format("-module(extra).~n-export([x/0]).~nx() -> ok.", []),
  31. ok = ec_file:write(Extra, Src),
  32. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  33. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  34. %% check that `extra.erl` was compiled to the `ebin` dir
  35. Ebin = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  36. true = filelib:is_file(filename:join([Ebin, "extra.beam"])),
  37. %% check that `extra.erl` is not in the `modules` key of the app
  38. {ok, App} = file:consult(filename:join([AppDir,
  39. "_build",
  40. "default",
  41. "lib",
  42. Name,
  43. "ebin",
  44. Name ++ ".app"])),
  45. [{application, _, KVs}] = App,
  46. Mods = proplists:get_value(modules, KVs),
  47. false = lists:member(extra, Mods).
  48. build_multi_apps(Config) ->
  49. AppDir = ?config(apps, Config),
  50. Name1 = rebar_test_utils:create_random_name("app1_"),
  51. Vsn1 = rebar_test_utils:create_random_vsn(),
  52. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  53. Name2 = rebar_test_utils:create_random_name("app2_"),
  54. Vsn2 = rebar_test_utils:create_random_vsn(),
  55. rebar_test_utils:create_app(filename:join([AppDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  56. Extra1 = filename:join([AppDir, Name1, "extra", "extra1.erl"]),
  57. ok = filelib:ensure_dir(Extra1),
  58. Src1 = io_lib:format("-module(extra1).~n-export([x/0]).~nx() -> ok.", []),
  59. ok = ec_file:write(Extra1, Src1),
  60. Extra2 = filename:join([AppDir, Name2, "extra", "extra2.erl"]),
  61. ok = filelib:ensure_dir(Extra2),
  62. Src2 = io_lib:format("-module(extra2).~n-export([x/0]).~nx() -> ok.", []),
  63. ok = ec_file:write(Extra2, Src2),
  64. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  65. rebar_test_utils:run_and_check(
  66. Config, RebarConfig, ["compile"],
  67. {ok, [{app, Name1}, {app, Name2}]}
  68. ),
  69. %% check that `extraX.erl` was compiled to the `ebin` dir
  70. Ebin1 = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin"]),
  71. true = filelib:is_file(filename:join([Ebin1, "extra1.beam"])),
  72. Ebin2 = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"]),
  73. true = filelib:is_file(filename:join([Ebin2, "extra2.beam"])),
  74. %% check that `extraX.erl` is not in the `modules` key of the app
  75. {ok, App1} = file:consult(filename:join([AppDir,
  76. "_build",
  77. "default",
  78. "lib",
  79. Name1,
  80. "ebin",
  81. Name1 ++ ".app"])),
  82. [{application, _, KVs1}] = App1,
  83. Mods1 = proplists:get_value(modules, KVs1),
  84. false = lists:member(extra1, Mods1),
  85. {ok, App2} = file:consult(filename:join([AppDir,
  86. "_build",
  87. "default",
  88. "lib",
  89. Name2,
  90. "ebin",
  91. Name2 ++ ".app"])),
  92. [{application, _, KVs2}] = App2,
  93. Mods2 = proplists:get_value(modules, KVs2),
  94. false = lists:member(extra2, Mods2).
  95. src_dir_takes_precedence(Config) ->
  96. AppDir = ?config(apps, Config),
  97. Name = rebar_test_utils:create_random_name("app1_"),
  98. Vsn = rebar_test_utils:create_random_vsn(),
  99. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  100. Extra = filename:join([AppDir, "extra", "extra.erl"]),
  101. ok = filelib:ensure_dir(Extra),
  102. Src = io_lib:format("-module(extra).~n-export([x/0]).~nx() -> ok.", []),
  103. ok = ec_file:write(Extra, Src),
  104. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}, {extra_src_dirs, ["extra"]}]}],
  105. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  106. %% check that `extra.erl` was compiled to the `ebin` dir
  107. %% check that `extraX.erl` was compiled to the `ebin` dir
  108. Ebin = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  109. true = filelib:is_file(filename:join([Ebin, "extra.beam"])),
  110. %% check that `extra.erl` is in the `modules` key of the app
  111. {ok, App} = file:consult(filename:join([AppDir,
  112. "_build",
  113. "default",
  114. "lib",
  115. Name,
  116. "ebin",
  117. Name ++ ".app"])),
  118. [{application, _, KVs}] = App,
  119. Mods = proplists:get_value(modules, KVs),
  120. true = lists:member(extra, Mods).