Você não pode selecionar mais de 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.

2169 linhas
84 KiB

10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
  1. -module(rebar_compile_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. init_per_group/2,
  8. end_per_group/2,
  9. all/0,
  10. groups/0,
  11. build_basic_app/1, paths_basic_app/1, clean_basic_app/1,
  12. build_release_apps/1, paths_release_apps/1, clean_release_apps/1,
  13. build_checkout_apps/1, paths_checkout_apps/1,
  14. build_checkout_deps/1, paths_checkout_deps/1,
  15. build_basic_srcdirs/1, paths_basic_srcdirs/1,
  16. build_release_srcdirs/1, paths_release_srcdirs/1,
  17. build_unbalanced_srcdirs/1, paths_unbalanced_srcdirs/1,
  18. build_basic_extra_dirs/1, paths_basic_extra_dirs/1, clean_basic_extra_dirs/1,
  19. build_release_extra_dirs/1, paths_release_extra_dirs/1, clean_release_extra_dirs/1,
  20. build_unbalanced_extra_dirs/1, paths_unbalanced_extra_dirs/1,
  21. build_extra_dirs_in_project_root/1,
  22. paths_extra_dirs_in_project_root/1,
  23. clean_extra_dirs_in_project_root/1,
  24. recompile_when_hrl_changes/1,
  25. recompile_when_included_hrl_changes/1,
  26. recompile_when_opts_included_hrl_changes/1,
  27. recompile_when_opts_change/1,
  28. dont_recompile_when_opts_dont_change/1,
  29. dont_recompile_yrl_or_xrl/1,
  30. deps_in_path/1,
  31. delete_beam_if_source_deleted/1,
  32. checkout_priority/1,
  33. highest_version_of_pkg_dep/1,
  34. parse_transform_test/1,
  35. erl_first_files_test/1,
  36. mib_test/1,
  37. umbrella_mib_first_test/1,
  38. only_default_transitive_deps/1,
  39. clean_all/1,
  40. override_deps/1,
  41. override_add_deps/1,
  42. override_del_deps/1,
  43. override_opts/1,
  44. override_add_opts/1,
  45. override_del_opts/1,
  46. profile_deps/1,
  47. profile_override_deps/1,
  48. profile_override_add_deps/1,
  49. profile_override_del_deps/1,
  50. profile_override_opts/1,
  51. profile_override_add_opts/1,
  52. profile_override_del_opts/1,
  53. deps_build_in_prod/1,
  54. include_file_relative_to_working_directory/1,
  55. include_file_in_src/1,
  56. include_file_relative_to_working_directory_test/1,
  57. include_file_in_src_test/1,
  58. include_file_in_src_test_multiapp/1,
  59. dont_recompile_when_erl_compiler_options_env_does_not_change/1,
  60. recompile_when_erl_compiler_options_env_changes/1,
  61. always_recompile_when_erl_compiler_options_set/1,
  62. recompile_when_parse_transform_inline_changes/1,
  63. recompile_when_parse_transform_as_opt_changes/1,
  64. recursive/1,no_recursive/1,
  65. regex_filter_skip/1, regex_filter_regression/1]).
  66. -include_lib("common_test/include/ct.hrl").
  67. -include_lib("eunit/include/eunit.hrl").
  68. -include_lib("kernel/include/file.hrl").
  69. suite() ->
  70. [].
  71. all() ->
  72. [{group, basic_app}, {group, release_apps},
  73. {group, checkout_apps}, {group, checkout_deps},
  74. {group, basic_srcdirs}, {group, release_srcdirs}, {group, unbalanced_srcdirs},
  75. {group, basic_extras}, {group, release_extras}, {group, unbalanced_extras},
  76. {group, root_extras},
  77. recompile_when_hrl_changes, recompile_when_included_hrl_changes,
  78. recompile_when_opts_included_hrl_changes,
  79. recompile_when_opts_change,
  80. dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl,
  81. delete_beam_if_source_deleted,
  82. deps_in_path, checkout_priority, highest_version_of_pkg_dep,
  83. parse_transform_test, erl_first_files_test, mib_test,
  84. umbrella_mib_first_test, only_default_transitive_deps, clean_all,
  85. profile_deps, deps_build_in_prod,
  86. override_deps, override_add_deps, override_del_deps,
  87. override_opts, override_add_opts, override_del_opts,
  88. profile_override_deps, profile_override_add_deps, profile_override_del_deps,
  89. profile_override_opts, profile_override_add_opts, profile_override_del_opts,
  90. include_file_relative_to_working_directory, include_file_in_src,
  91. include_file_relative_to_working_directory_test, include_file_in_src_test,
  92. include_file_in_src_test_multiapp,
  93. recompile_when_parse_transform_as_opt_changes,
  94. recompile_when_parse_transform_inline_changes,
  95. regex_filter_skip, regex_filter_regression,
  96. recursive, no_recursive,
  97. always_recompile_when_erl_compiler_options_set,
  98. dont_recompile_when_erl_compiler_options_env_does_not_change,
  99. recompile_when_erl_compiler_options_env_changes].
  100. groups() ->
  101. [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
  102. {release_apps, [], [build_release_apps, paths_release_apps, clean_release_apps]},
  103. {checkout_apps, [], [build_checkout_apps, paths_checkout_apps]},
  104. {checkout_deps, [], [build_checkout_deps, paths_checkout_deps]},
  105. {basic_srcdirs, [], [build_basic_srcdirs, paths_basic_srcdirs]},
  106. {release_srcdirs, [], [build_release_srcdirs,
  107. paths_release_srcdirs]},
  108. {unbalanced_srcdirs, [], [build_unbalanced_srcdirs,
  109. paths_unbalanced_srcdirs]},
  110. {basic_extras, [], [build_basic_extra_dirs,
  111. paths_basic_extra_dirs,
  112. clean_basic_extra_dirs]},
  113. {release_extras, [], [build_release_extra_dirs,
  114. paths_release_extra_dirs,
  115. clean_release_extra_dirs]},
  116. {unbalanced_extras, [], [build_unbalanced_extra_dirs,
  117. paths_unbalanced_extra_dirs]},
  118. {root_extras, [], [build_extra_dirs_in_project_root,
  119. paths_extra_dirs_in_project_root,
  120. clean_extra_dirs_in_project_root]}].
  121. init_per_group(basic_app, Config) ->
  122. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  123. AppDir = ?config(apps, NewConfig),
  124. Name = rebar_test_utils:create_random_name("app1"),
  125. Vsn = rebar_test_utils:create_random_vsn(),
  126. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  127. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  128. init_per_group(release_apps, Config) ->
  129. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_apps_"),
  130. AppDir = ?config(apps, NewConfig),
  131. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  132. Vsn1 = rebar_test_utils:create_random_vsn(),
  133. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  134. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  135. Vsn2 = rebar_test_utils:create_random_vsn(),
  136. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  137. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  138. init_per_group(checkout_apps, Config) ->
  139. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_apps_"),
  140. AppDir = ?config(apps, NewConfig),
  141. CheckoutsDir = ?config(checkouts, NewConfig),
  142. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  143. Vsn1 = rebar_test_utils:create_random_vsn(),
  144. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  145. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  146. Vsn2 = rebar_test_utils:create_random_vsn(),
  147. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  148. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  149. init_per_group(checkout_deps, Config) ->
  150. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_deps_"),
  151. AppDir = ?config(apps, NewConfig),
  152. CheckoutsDir = ?config(checkouts, NewConfig),
  153. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  154. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  155. Vsn1 = rebar_test_utils:create_random_vsn(),
  156. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  157. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  158. Vsn2 = rebar_test_utils:create_random_vsn(),
  159. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  160. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  161. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  162. init_per_group(Group, Config) when Group == basic_srcdirs; Group == basic_extras ->
  163. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_srcdirs_"),
  164. AppDir = ?config(apps, NewConfig),
  165. Name = rebar_test_utils:create_random_name("app1_"),
  166. Vsn = rebar_test_utils:create_random_vsn(),
  167. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  168. ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
  169. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  170. ok = file:write_file(filename:join([AppDir, "extra", io_lib:format("~ts_extra.erl", [Name])]),
  171. ExtraSrc),
  172. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  173. init_per_group(Group, Config) when Group == release_srcdirs; Group == release_extras ->
  174. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_srcdirs_"),
  175. AppDir = ?config(apps, NewConfig),
  176. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  177. Vsn1 = rebar_test_utils:create_random_vsn(),
  178. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  179. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  180. Vsn2 = rebar_test_utils:create_random_vsn(),
  181. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  182. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  183. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  184. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  185. io_lib:format("~ts_extra.erl", [Name1])]),
  186. ExtraOne),
  187. ExtraTwo = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name2]),
  188. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "extra", "dummy"])),
  189. ok = file:write_file(filename:join([AppDir, "apps", Name2, "extra",
  190. io_lib:format("~ts_extra.erl", [Name2])]),
  191. ExtraTwo),
  192. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  193. init_per_group(Group, Config) when Group == unbalanced_srcdirs; Group == unbalanced_extras ->
  194. NewConfig = rebar_test_utils:init_rebar_state(Config, "unbalanced_srcdirs_"),
  195. AppDir = ?config(apps, NewConfig),
  196. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  197. Vsn1 = rebar_test_utils:create_random_vsn(),
  198. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  199. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  200. Vsn2 = rebar_test_utils:create_random_vsn(),
  201. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  202. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  203. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  204. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  205. io_lib:format("~ts_extra.erl", [Name1])]),
  206. ExtraOne),
  207. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  208. init_per_group(root_extras, Config) ->
  209. NewConfig = rebar_test_utils:init_rebar_state(Config, "root_extras_"),
  210. AppDir = ?config(apps, NewConfig),
  211. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  212. Vsn1 = rebar_test_utils:create_random_vsn(),
  213. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  214. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  215. Vsn2 = rebar_test_utils:create_random_vsn(),
  216. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  217. Extra = <<"-module(extra).\n-export([ok/0]).\nok() -> ok.\n">>,
  218. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  219. ok = file:write_file(filename:join([AppDir, "extra", "extra.erl"]), Extra),
  220. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig].
  221. end_per_group(_Group, _Config) ->
  222. ok.
  223. init_per_suite(Config) ->
  224. Config.
  225. end_per_suite(_Config) ->
  226. ok.
  227. init_per_testcase(Test, Config) when
  228. Test == dont_recompile_when_erl_compiler_options_env_does_not_change
  229. orelse
  230. Test == recompile_when_erl_compiler_options_env_changes ->
  231. _ = code:ensure_loaded(os),
  232. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  233. _ = code:ensure_loaded(compile),
  234. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  235. case {UnSetEnv, EnvOpts} of
  236. {true, true} -> maybe_init_config(Config);
  237. _ -> {skip, "compile:env_compiler_options/0 unavailable"}
  238. end;
  239. init_per_testcase(always_recompile_when_erl_compiler_options_set, Config) ->
  240. _ = code:ensure_loaded(os),
  241. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  242. _ = code:ensure_loaded(compile),
  243. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  244. case {UnSetEnv, EnvOpts} of
  245. {true, true} -> {skip, "compile:env_compiler_options/0 available"};
  246. {true, false} -> maybe_init_config(Config);
  247. _ -> {skip, "os:unsetenv/1 unavailable"}
  248. end;
  249. init_per_testcase(_, Config) -> maybe_init_config(Config).
  250. maybe_init_config(Config) ->
  251. case ?config(apps, Config) of
  252. undefined -> rebar_test_utils:init_rebar_state(Config);
  253. _ -> Config
  254. end.
  255. end_per_testcase(_, _Config) ->
  256. catch meck:unload().
  257. %% test cases
  258. build_basic_app(Config) ->
  259. [Name] = ?config(app_names, Config),
  260. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  261. build_release_apps(Config) ->
  262. [Name1, Name2] = ?config(app_names, Config),
  263. rebar_test_utils:run_and_check(
  264. Config, [], ["compile"],
  265. {ok, [{app, Name1}, {app, Name2}]}
  266. ).
  267. build_checkout_apps(Config) ->
  268. [Name1, Name2] = ?config(app_names, Config),
  269. rebar_test_utils:run_and_check(
  270. Config, [], ["compile"],
  271. {ok, [{app, Name1}, {checkout, Name2}]}
  272. ).
  273. build_checkout_deps(Config) ->
  274. AppDir = ?config(apps, Config),
  275. [Name1, Name2] = ?config(app_names, Config),
  276. [_, Vsn2] = ?config(vsns, Config),
  277. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  278. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  279. rebar_test_utils:run_and_check(
  280. Config, RebarConfig, ["compile"],
  281. {ok, [{app, Name1}, {checkout, Name2}]}
  282. ).
  283. build_basic_srcdirs(Config) ->
  284. AppDir = ?config(apps, Config),
  285. [Name] = ?config(app_names, Config),
  286. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  287. %% check a beam corresponding to the src in the extra src_dir exists
  288. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  289. io_lib:format("~ts_extra.beam", [Name])]),
  290. %% check the extra src_dir was copied/linked into the _build dir
  291. ExtraDir = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  292. rebar_test_utils:run_and_check(
  293. Config, RebarConfig, ["compile"],
  294. {ok, [{app, Name}, {file, ExtraBeam}, {dir, ExtraDir}]}
  295. ).
  296. build_release_srcdirs(Config) ->
  297. AppDir = ?config(apps, Config),
  298. [Name1, Name2] = ?config(app_names, Config),
  299. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  300. %% check a beam corresponding to the src in the extra src_dir exists
  301. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  302. io_lib:format("~ts_extra.beam", [Name1])]),
  303. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  304. io_lib:format("~ts_extra.beam", [Name2])]),
  305. %% check the extra src_dir was copied/linked into the _build dir
  306. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  307. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  308. rebar_test_utils:run_and_check(
  309. Config, RebarConfig, ["compile"],
  310. {ok, [{app, Name1}, {app, Name2},
  311. {file, Extra1Beam}, {file, Extra2Beam},
  312. {dir, Extra1Dir}, {dir, Extra2Dir}]}
  313. ).
  314. build_unbalanced_srcdirs(Config) ->
  315. AppDir = ?config(apps, Config),
  316. [Name1, Name2] = ?config(app_names, Config),
  317. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  318. %% check a beam corresponding to the src in the extra src_dir exists
  319. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  320. io_lib:format("~ts_extra.beam", [Name1])]),
  321. %% check the extra src_dir was copied/linked into the _build dir
  322. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  323. rebar_test_utils:run_and_check(
  324. Config, RebarConfig, ["compile"],
  325. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {dir, Extra1Dir}]}
  326. ),
  327. %% check no extra src_dir were copied/linked into the _build dir
  328. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  329. false = filelib:is_dir(Extra2Dir),
  330. %% check only expected beams are in the ebin dir
  331. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  332. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  333. Files).
  334. build_basic_extra_dirs(Config) ->
  335. AppDir = ?config(apps, Config),
  336. [Name] = ?config(app_names, Config),
  337. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  338. %% check a beam corresponding to the src in the extra src_dir exists
  339. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  340. io_lib:format("~ts_extra.beam", [Name])]),
  341. rebar_test_utils:run_and_check(
  342. Config, RebarConfig, ["compile"],
  343. {ok, [{app, Name}, {file, ExtraBeam}]}
  344. ).
  345. build_release_extra_dirs(Config) ->
  346. AppDir = ?config(apps, Config),
  347. [Name1, Name2] = ?config(app_names, Config),
  348. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  349. %% check a beam corresponding to the src in the extra src_dir exists
  350. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  351. io_lib:format("~ts_extra.beam", [Name1])]),
  352. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  353. io_lib:format("~ts_extra.beam", [Name2])]),
  354. rebar_test_utils:run_and_check(
  355. Config, RebarConfig, ["compile"],
  356. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {file, Extra2Beam}]}
  357. ).
  358. build_unbalanced_extra_dirs(Config) ->
  359. AppDir = ?config(apps, Config),
  360. [Name1, Name2] = ?config(app_names, Config),
  361. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  362. %% check a beam corresponding to the src in the extra src_dir exists
  363. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  364. io_lib:format("~ts_extra.beam", [Name1])]),
  365. rebar_test_utils:run_and_check(
  366. Config, RebarConfig, ["compile"],
  367. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}]}
  368. ),
  369. %% check no extra src_dir were copied/linked into the _build dir
  370. false = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "extra"])),
  371. %% check only expected beams are in the ebin dir
  372. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  373. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  374. Files).
  375. build_extra_dirs_in_project_root(Config) ->
  376. AppDir = ?config(apps, Config),
  377. [Name1, Name2] = ?config(app_names, Config),
  378. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  379. %% check a beam corresponding to the src in the extra src_dir exists
  380. ExtraBeam = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  381. rebar_test_utils:run_and_check(
  382. Config, RebarConfig, ["compile"],
  383. {ok, [{app, Name1}, {app, Name2}, {file, ExtraBeam}]}
  384. ).
  385. paths_basic_app(Config) ->
  386. [Name] = ?config(app_names, Config),
  387. [Vsn] = ?config(vsns, Config),
  388. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  389. code:add_paths(rebar_state:code_paths(State, all_deps)),
  390. ok = application:load(list_to_atom(Name)),
  391. Loaded = application:loaded_applications(),
  392. {_, _, Vsn} = lists:keyfind(list_to_atom(Name), 1, Loaded).
  393. paths_release_apps(Config) ->
  394. [Name1, Name2] = ?config(app_names, Config),
  395. [Vsn1, Vsn2] = ?config(vsns, Config),
  396. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  397. code:add_paths(rebar_state:code_paths(State, all_deps)),
  398. ok = application:load(list_to_atom(Name1)),
  399. ok = application:load(list_to_atom(Name2)),
  400. Loaded = application:loaded_applications(),
  401. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded),
  402. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  403. paths_checkout_apps(Config) ->
  404. [Name1, _Name2] = ?config(app_names, Config),
  405. [Vsn1, _Vsn2] = ?config(vsns, Config),
  406. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  407. code:add_paths(rebar_state:code_paths(State, all_deps)),
  408. ok = application:load(list_to_atom(Name1)),
  409. Loaded = application:loaded_applications(),
  410. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded).
  411. paths_checkout_deps(Config) ->
  412. AppDir = ?config(apps, Config),
  413. [_Name1, Name2] = ?config(app_names, Config),
  414. [_Vsn1, Vsn2] = ?config(vsns, Config),
  415. %% rebar_test_utils:init_rebar_state/1,2 uses rebar_state:new/3 which
  416. %% maybe incorrectly sets deps to [] (based on `rebar.lock`) instead of
  417. %% to the checkapps
  418. %% until that is sorted out the lock file has to be removed before
  419. %% this test will pass
  420. file:delete(filename:join([AppDir, "rebar.lock"])),
  421. {ok, RebarConfig} = file:consult(filename:join([AppDir, "rebar.config"])),
  422. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  423. code:add_paths(rebar_state:code_paths(State, all_deps)),
  424. ok = application:load(list_to_atom(Name2)),
  425. Loaded = application:loaded_applications(),
  426. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  427. paths_basic_srcdirs(Config) ->
  428. AppDir = ?config(apps, Config),
  429. [Name] = ?config(app_names, Config),
  430. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  431. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  432. code:add_paths(rebar_state:code_paths(State, all_deps)),
  433. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  434. {module, Mod} = code:ensure_loaded(Mod),
  435. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  436. io_lib:format("~ts_extra.beam", [Name])]),
  437. Expect = code:which(Mod).
  438. paths_release_srcdirs(Config) ->
  439. AppDir = ?config(apps, Config),
  440. [Name1, Name2] = ?config(app_names, Config),
  441. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  442. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  443. code:add_paths(rebar_state:code_paths(State, all_deps)),
  444. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  445. {module, Mod1} = code:ensure_loaded(Mod1),
  446. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  447. {module, Mod2} = code:ensure_loaded(Mod2),
  448. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  449. io_lib:format("~ts_extra.beam", [Name1])]),
  450. ExpectOne = code:which(Mod1),
  451. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  452. io_lib:format("~ts_extra.beam", [Name2])]),
  453. ExpectTwo = code:which(Mod2).
  454. paths_unbalanced_srcdirs(Config) ->
  455. AppDir = ?config(apps, Config),
  456. [Name1, Name2] = ?config(app_names, Config),
  457. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  458. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  459. code:add_paths(rebar_state:code_paths(State, all_deps)),
  460. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  461. {module, Mod1} = code:ensure_loaded(Mod1),
  462. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  463. {error, nofile} = code:ensure_loaded(Mod2),
  464. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  465. io_lib:format("~ts_extra.beam", [Name1])]),
  466. ExpectOne = code:which(Mod1).
  467. paths_basic_extra_dirs(Config) ->
  468. AppDir = ?config(apps, Config),
  469. [Name] = ?config(app_names, Config),
  470. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  471. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  472. code:add_paths(rebar_state:code_paths(State, all_deps)),
  473. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  474. {module, Mod} = code:ensure_loaded(Mod),
  475. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  476. io_lib:format("~ts_extra.beam", [Name])]),
  477. Expect = code:which(Mod).
  478. paths_release_extra_dirs(Config) ->
  479. AppDir = ?config(apps, Config),
  480. [Name1, Name2] = ?config(app_names, Config),
  481. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  482. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  483. code:add_paths(rebar_state:code_paths(State, all_deps)),
  484. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  485. {module, Mod1} = code:ensure_loaded(Mod1),
  486. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  487. {module, Mod2} = code:ensure_loaded(Mod2),
  488. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  489. io_lib:format("~ts_extra.beam", [Name1])]),
  490. ExpectOne = code:which(Mod1),
  491. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  492. io_lib:format("~ts_extra.beam", [Name2])]),
  493. ExpectTwo = code:which(Mod2).
  494. paths_unbalanced_extra_dirs(Config) ->
  495. AppDir = ?config(apps, Config),
  496. [Name1, Name2] = ?config(app_names, Config),
  497. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  498. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  499. code:add_paths(rebar_state:code_paths(State, all_deps)),
  500. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  501. {module, Mod1} = code:ensure_loaded(Mod1),
  502. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  503. {error, nofile} = code:ensure_loaded(Mod2),
  504. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  505. io_lib:format("~ts_extra.beam", [Name1])]),
  506. ExpectOne = code:which(Mod1).
  507. paths_extra_dirs_in_project_root(Config) ->
  508. AppDir = ?config(apps, Config),
  509. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  510. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  511. code:add_paths(rebar_state:code_paths(State, all_deps)),
  512. {module, extra} = code:ensure_loaded(extra),
  513. Expect = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  514. Expect = code:which(extra).
  515. clean_basic_app(Config) ->
  516. [Name] = ?config(app_names, Config),
  517. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}).
  518. clean_release_apps(Config) ->
  519. [Name1, Name2] = ?config(app_names, Config),
  520. rebar_test_utils:run_and_check(Config, [], ["clean"],
  521. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}).
  522. clean_basic_extra_dirs(Config) ->
  523. AppDir = ?config(apps, Config),
  524. [Name] = ?config(app_names, Config),
  525. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}),
  526. Beam = lists:flatten(io_lib:format("~ts_extra", [Name])),
  527. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name, "extras", Beam])).
  528. clean_release_extra_dirs(Config) ->
  529. AppDir = ?config(apps, Config),
  530. [Name1, Name2] = ?config(app_names, Config),
  531. rebar_test_utils:run_and_check(Config, [], ["clean"],
  532. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  533. Beam1 = lists:flatten(io_lib:format("~ts_extra", [Name1])),
  534. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name1, "extras", Beam1])),
  535. Beam2 = lists:flatten(io_lib:format("~ts_extra", [Name2])),
  536. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name2, "extras", Beam2])).
  537. clean_extra_dirs_in_project_root(Config) ->
  538. AppDir = ?config(apps, Config),
  539. [Name1, Name2] = ?config(app_names, Config),
  540. rebar_test_utils:run_and_check(Config, [], ["clean"],
  541. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  542. false = ec_file:exists(filename:join([AppDir, "_build", "default", "extras"])).
  543. recompile_when_hrl_changes(Config) ->
  544. AppDir = ?config(apps, Config),
  545. Name = rebar_test_utils:create_random_name("app1_"),
  546. Vsn = rebar_test_utils:create_random_vsn(),
  547. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  548. ExtraSrc = <<"-module(test_header_include).\n"
  549. "-export([main/0]).\n"
  550. "-include(\"test_header_include.hrl\").\n"
  551. "main() -> ?SOME_DEFINE.\n">>,
  552. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  553. HeaderFile = filename:join([AppDir, "src", "test_header_include.hrl"]),
  554. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  555. ok = file:write_file(HeaderFile, ExtraHeader),
  556. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  557. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  558. {ok, Files} = rebar_utils:list_dir(EbinDir),
  559. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  560. || F <- Files, filename:extension(F) == ".beam"],
  561. timer:sleep(1000),
  562. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  563. ok = file:write_file(HeaderFile, NewExtraHeader),
  564. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  565. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  566. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  567. || F <- NewFiles, filename:extension(F) == ".beam"],
  568. ?assert(ModTime =/= NewModTime).
  569. recompile_when_included_hrl_changes(Config) ->
  570. AppDir = ?config(apps, Config),
  571. Name = rebar_test_utils:create_random_name("app1_"),
  572. Vsn = rebar_test_utils:create_random_vsn(),
  573. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  574. ExtraSrc = <<"-module(test_header_include).\n"
  575. "-export([main/0]).\n"
  576. "-include(\"test_header_include.hrl\").\n"
  577. "main() -> ?SOME_DEFINE.\n">>,
  578. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  579. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  580. HeaderFile = filename:join([AppDir, "include", "test_header_include.hrl"]),
  581. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  582. ok = file:write_file(HeaderFile, ExtraHeader),
  583. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  584. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  585. {ok, Files} = rebar_utils:list_dir(EbinDir),
  586. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  587. || F <- Files, filename:extension(F) == ".beam"],
  588. timer:sleep(1000),
  589. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  590. ok = file:write_file(HeaderFile, NewExtraHeader),
  591. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  592. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  593. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  594. || F <- NewFiles, filename:extension(F) == ".beam"],
  595. ?assert(ModTime =/= NewModTime).
  596. recompile_when_opts_included_hrl_changes(Config) ->
  597. AppsDir = ?config(apps, Config),
  598. Name = rebar_test_utils:create_random_name("app1_"),
  599. Vsn = rebar_test_utils:create_random_vsn(),
  600. AppDir = filename:join([AppsDir, "apps", Name]),
  601. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  602. ExtraSrc = <<"-module(test_header_include).\n"
  603. "-export([main/0]).\n"
  604. "-include(\"test_header_include.hrl\").\n"
  605. "main() -> ?SOME_DEFINE.\n">>,
  606. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  607. ok = filelib:ensure_dir(filename:join([AppsDir, "include", "dummy"])),
  608. HeaderFile = filename:join([AppsDir, "include", "test_header_include.hrl"]),
  609. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  610. ok = file:write_file(HeaderFile, ExtraHeader),
  611. %% Using relative path from the project root
  612. RebarConfig = [{erl_opts, [{i, "include/"}]}],
  613. {ok,Cwd} = file:get_cwd(),
  614. ok = file:set_cwd(AppsDir),
  615. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  616. EbinDir = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
  617. {ok, Files} = rebar_utils:list_dir(EbinDir),
  618. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  619. || F <- Files, filename:extension(F) == ".beam"],
  620. timer:sleep(1000),
  621. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  622. ok = file:write_file(HeaderFile, NewExtraHeader),
  623. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  624. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  625. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  626. || F <- NewFiles, filename:extension(F) == ".beam"],
  627. ok = file:set_cwd(Cwd),
  628. ?assert(ModTime =/= NewModTime).
  629. recompile_when_opts_change(Config) ->
  630. AppDir = ?config(apps, Config),
  631. Name = rebar_test_utils:create_random_name("app1_"),
  632. Vsn = rebar_test_utils:create_random_vsn(),
  633. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  634. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  635. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  636. {ok, Files} = rebar_utils:list_dir(EbinDir),
  637. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  638. || F <- Files, filename:extension(F) == ".beam"],
  639. timer:sleep(1000),
  640. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  641. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  642. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  643. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  644. || F <- NewFiles, filename:extension(F) == ".beam"],
  645. ?assert(ModTime =/= NewModTime).
  646. dont_recompile_when_opts_dont_change(Config) ->
  647. AppDir = ?config(apps, Config),
  648. Name = rebar_test_utils:create_random_name("app1_"),
  649. Vsn = rebar_test_utils:create_random_vsn(),
  650. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  651. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  652. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  653. {ok, Files} = rebar_utils:list_dir(EbinDir),
  654. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  655. || F <- Files, filename:extension(F) == ".beam"],
  656. timer:sleep(1000),
  657. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  658. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  659. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  660. || F <- NewFiles, filename:extension(F) == ".beam"],
  661. ?assertEqual(ModTime, NewModTime).
  662. dont_recompile_yrl_or_xrl(Config) ->
  663. AppDir = ?config(apps, Config),
  664. Name = rebar_test_utils:create_random_name("app1_"),
  665. Vsn = rebar_test_utils:create_random_vsn(),
  666. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  667. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  668. ok = filelib:ensure_dir(Xrl),
  669. XrlBody =
  670. "Definitions."
  671. "\n\n"
  672. "D = [0-9]"
  673. "\n\n"
  674. "Rules."
  675. "\n\n"
  676. "{D}+ :"
  677. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  678. "\n\n"
  679. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  680. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  681. "\n\n"
  682. "Erlang code.",
  683. ok = ec_file:write(Xrl, XrlBody),
  684. XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]),
  685. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  686. ModTime = filelib:last_modified(XrlBeam),
  687. timer:sleep(1000),
  688. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  689. NewModTime = filelib:last_modified(XrlBeam),
  690. ?assert(ModTime == NewModTime).
  691. delete_beam_if_source_deleted(Config) ->
  692. AppDir = ?config(apps, Config),
  693. Name = rebar_test_utils:create_random_name("app1_"),
  694. Vsn = rebar_test_utils:create_random_vsn(),
  695. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  696. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  697. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  698. _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]),
  699. ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))),
  700. file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])),
  701. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  702. ?assertNot(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))).
  703. deps_in_path(Config) ->
  704. AppDir = ?config(apps, Config),
  705. StartPaths = code:get_path(),
  706. Name = rebar_test_utils:create_random_name("app1_"),
  707. Vsn = rebar_test_utils:create_random_vsn(),
  708. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  709. DepName = rebar_test_utils:create_random_name("dep1_"),
  710. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  711. mock_git_resource:mock([]),
  712. mock_pkg_resource:mock([
  713. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  714. ]),
  715. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  716. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  717. {list_to_atom(PkgName), Vsn}
  718. ]}]),
  719. {ok, RConf} = file:consult(RConfFile),
  720. %% Make sure apps we look for are not visible
  721. %% Hope not to find src name
  722. ?assertEqual([], [Path || Path <- code:get_path(),
  723. {match, _} <- [re:run(Path, DepName)]]),
  724. %% Hope not to find pkg name in there
  725. ?assertEqual([], [Path || Path <- code:get_path(),
  726. {match, _} <- [re:run(Path, PkgName)]]),
  727. %% Build things
  728. {ok, State} = rebar_test_utils:run_and_check(
  729. Config, RConf, ["compile"],
  730. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  731. ),
  732. code:add_paths(rebar_state:code_paths(State, all_deps)),
  733. %% Find src name in there
  734. ?assertNotEqual([], [Path || Path <- code:get_path(),
  735. {match, _} <- [re:run(Path, DepName)]]),
  736. %% find pkg name in there
  737. ?assertNotEqual([], [Path || Path <- code:get_path(),
  738. {match, _} <- [re:run(Path, PkgName)]]),
  739. true = code:set_path(lists:filter(fun(P) -> ec_file:exists(P) end, StartPaths)),
  740. %% Make sure apps we look for are not visible again
  741. %% Hope not to find src name
  742. ?assertEqual([], [Path || Path <- code:get_path(),
  743. {match, _} <- [re:run(Path, DepName)]]),
  744. %% Hope not to find pkg name in there
  745. ?assertEqual([], [Path || Path <- code:get_path(),
  746. {match, _} <- [re:run(Path, PkgName)]]),
  747. %% Rebuild
  748. {ok, State1} = rebar_test_utils:run_and_check(
  749. Config, RConf, ["compile"],
  750. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  751. ),
  752. %% Find src name in there
  753. code:add_paths(rebar_state:code_paths(State1, all_deps)),
  754. ?assertNotEqual([], [Path || Path <- code:get_path(),
  755. {match, _} <- [re:run(Path, DepName)]]),
  756. %% find pkg name in there
  757. ?assertNotEqual([], [Path || Path <- code:get_path(),
  758. {match, _} <- [re:run(Path, PkgName)]]).
  759. checkout_priority(Config) ->
  760. AppDir = ?config(apps, Config),
  761. CheckoutsDir = ?config(checkouts, Config),
  762. StartPaths = code:get_path(),
  763. Name = rebar_test_utils:create_random_name("app1_"),
  764. Vsn = rebar_test_utils:create_random_vsn(),
  765. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  766. DepName = rebar_test_utils:create_random_name("dep1_"),
  767. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  768. mock_git_resource:mock([]),
  769. mock_pkg_resource:mock([
  770. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  771. ]),
  772. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  773. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  774. {list_to_atom(PkgName), Vsn}
  775. ]}]),
  776. {ok, RConf} = file:consult(RConfFile),
  777. %% Build with deps.
  778. rebar_test_utils:run_and_check(
  779. Config, RConf, ["compile"],
  780. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  781. ),
  782. %% Build two checkout apps similar to dependencies to be fetched,
  783. %% but on a different version
  784. Vsn2 = rebar_test_utils:create_random_vsn(),
  785. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  786. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  787. %% Rebuild and make sure the checkout apps are in path
  788. code:set_path(StartPaths),
  789. {ok, State} = rebar_test_utils:run_and_check(
  790. Config, RConf, ["compile"],
  791. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  792. ),
  793. code:add_paths(rebar_state:code_paths(State, all_deps)),
  794. [DepPath] = [Path || Path <- code:get_path(),
  795. {match, _} <- [re:run(Path, DepName)]],
  796. [PkgPath] = [Path || Path <- code:get_path(),
  797. {match, _} <- [re:run(Path, PkgName)]],
  798. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  799. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  800. {application, _, DepProps} = DepApp,
  801. {application, _, PkgProps} = PkgApp,
  802. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  803. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  804. highest_version_of_pkg_dep(Config) ->
  805. AppDir = ?config(apps, Config),
  806. Name = rebar_test_utils:create_random_name("app1_"),
  807. Vsn = rebar_test_utils:create_random_vsn(),
  808. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  809. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  810. mock_git_resource:mock([]),
  811. mock_pkg_resource:mock([
  812. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  813. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  814. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  815. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  816. ]),
  817. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]),
  818. {ok, RConf} = file:consult(RConfFile),
  819. %% Build with deps.
  820. rebar_test_utils:run_and_check(
  821. Config, RConf, ["compile"],
  822. {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
  823. ).
  824. parse_transform_test(Config) ->
  825. AppDir = ?config(apps, Config),
  826. RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
  827. Name = rebar_test_utils:create_random_name("app1_"),
  828. Vsn = rebar_test_utils:create_random_vsn(),
  829. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  830. ExtraSrc = <<"-module(pascal). "
  831. "-export([parse_transform/2]). "
  832. "parse_transform(Forms, _Options) -> "
  833. "Forms.">>,
  834. ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
  835. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  836. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  837. true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).
  838. erl_first_files_test(Config) ->
  839. AppDir = ?config(apps, Config),
  840. RebarConfig = [{erl_opts, [{parse_transform, mark_time}]},
  841. {erl_first_files, ["src/mark_time.erl",
  842. "src/b.erl",
  843. "src/d.erl",
  844. "src/a.erl"]}],
  845. Name = rebar_test_utils:create_random_name("app1_"),
  846. Vsn = rebar_test_utils:create_random_vsn(),
  847. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  848. rebar_test_utils:write_src_file(AppDir, "a.erl"),
  849. rebar_test_utils:write_src_file(AppDir, "b.erl"),
  850. rebar_test_utils:write_src_file(AppDir, "d.erl"),
  851. rebar_test_utils:write_src_file(AppDir, "e.erl"),
  852. ExtraSrc = <<"-module(mark_time). "
  853. "-export([parse_transform/2]). "
  854. "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> "
  855. " [Form, {attribute,1,number, os:timestamp()} | Forms];"
  856. "parse_transform([Form|Forms], Options) -> "
  857. " [Form | parse_transform(Forms, Options)].">>,
  858. ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc),
  859. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  860. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  861. true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])),
  862. code:load_abs(filename:join([EbinDir, "a"])),
  863. code:load_abs(filename:join([EbinDir, "b"])),
  864. code:load_abs(filename:join([EbinDir, "d"])),
  865. code:load_abs(filename:join([EbinDir, "e"])),
  866. A = proplists:get_value(number, a:module_info(attributes)),
  867. B = proplists:get_value(number, b:module_info(attributes)),
  868. D = proplists:get_value(number, d:module_info(attributes)),
  869. E = proplists:get_value(number, e:module_info(attributes)),
  870. ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])).
  871. mib_test(Config) ->
  872. AppDir = ?config(apps, Config),
  873. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  874. Name = rebar_test_utils:create_random_name("app1_"),
  875. Vsn = rebar_test_utils:create_random_vsn(),
  876. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  877. MibsSrc = <<"-- SIMPLE-MIB.\n"
  878. "-- This is just a simple MIB used for testing!\n"
  879. "--\n"
  880. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  881. "IMPORTS\n"
  882. " MODULE-IDENTITY, enterprises\n"
  883. " FROM SNMPv2-SMI;\n"
  884. "\n"
  885. "ericsson MODULE-IDENTITY\n"
  886. " LAST-UPDATED\n"
  887. " \"201403060000Z\"\n"
  888. " ORGANIZATION\n"
  889. " \"rebar\"\n"
  890. " CONTACT-INFO\n"
  891. " \"rebar <rebar@example.com>\n"
  892. " or\n"
  893. " whoever is currently responsible for the SIMPLE\n"
  894. " enterprise MIB tree branch (enterprises.999).\"\n"
  895. " DESCRIPTION\n"
  896. " \"This very small module is made available\n"
  897. " for mib-compilation testing.\"\n"
  898. " ::= { enterprises 999 }\n"
  899. "END\n">>,
  900. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  901. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  902. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  903. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  904. PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  905. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  906. %% check a hrl corresponding to the mib in the mibs dir exists in include
  907. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  908. %% check the mibs dir was linked into the _build dir
  909. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])).
  910. umbrella_mib_first_test(Config) ->
  911. AppsDir = ?config(apps, Config),
  912. Name = rebar_test_utils:create_random_name("app1_"),
  913. Vsn = rebar_test_utils:create_random_vsn(),
  914. AppDir = filename:join([AppsDir, "apps", Name]),
  915. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  916. MibsSrc = <<"-- SIMPLE-MIB.\n"
  917. "-- This is just a simple MIB used for testing!\n"
  918. "--\n"
  919. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  920. "IMPORTS\n"
  921. " MODULE-IDENTITY, enterprises\n"
  922. " FROM SNMPv2-SMI;\n"
  923. "\n"
  924. "ericsson MODULE-IDENTITY\n"
  925. " LAST-UPDATED\n"
  926. " \"201403060000Z\"\n"
  927. " ORGANIZATION\n"
  928. " \"rebar\"\n"
  929. " CONTACT-INFO\n"
  930. " \"rebar <rebar@example.com>\n"
  931. " or\n"
  932. " whoever is currently responsible for the SIMPLE\n"
  933. " enterprise MIB tree branch (enterprises.999).\"\n"
  934. " DESCRIPTION\n"
  935. " \"This very small module is made available\n"
  936. " for mib-compilation testing.\"\n"
  937. " ::= { enterprises 999 }\n"
  938. "END\n">>,
  939. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  940. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  941. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  942. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  943. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  944. PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  945. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  946. %% check a hrl corresponding to the mib in the mibs dir exists in include
  947. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  948. %% check the mibs dir was linked into the _build dir
  949. true = filelib:is_dir(filename:join([AppsDir, "_build", "default", "lib", Name, "mibs"])).
  950. only_default_transitive_deps(Config) ->
  951. AppDir = ?config(apps, Config),
  952. Name = rebar_test_utils:create_random_name("app1_"),
  953. Vsn = rebar_test_utils:create_random_vsn(),
  954. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  955. GitDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]),
  956. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  957. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  958. mock_git_resource:mock([{deps, SrcDeps},
  959. {config, [{profiles, [{test, [{deps, [list_to_atom(PkgName)]}]}]}]}]),
  960. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  961. Deps = rebar_test_utils:top_level_deps(GitDeps),
  962. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  963. {ok, RConf} = file:consult(RConfFile),
  964. %% Build with deps.
  965. rebar_test_utils:run_and_check(
  966. Config, RConf, ["as", "test", "compile"],
  967. {ok, [{app, Name}, {dep, "a", <<"1.0.0">>}, {dep_not_exist, PkgName}]}
  968. ).
  969. clean_all(Config) ->
  970. AppDir = ?config(apps, Config),
  971. Name = rebar_test_utils:create_random_name("app1_"),
  972. Vsn = rebar_test_utils:create_random_vsn(),
  973. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  974. DepName = rebar_test_utils:create_random_name("dep1_"),
  975. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  976. mock_git_resource:mock([]),
  977. mock_pkg_resource:mock([
  978. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  979. ]),
  980. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  981. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  982. {list_to_atom(PkgName), Vsn}
  983. ]}]),
  984. {ok, RConf} = file:consult(RConfFile),
  985. %% Build things
  986. rebar_test_utils:run_and_check(
  987. Config, RConf, ["compile"],
  988. {ok, [{app, Name}, {app, DepName}, {app, PkgName}]}
  989. ),
  990. %% Clean all
  991. rebar_test_utils:run_and_check(Config, [], ["clean", "--all"],
  992. {ok, [{app, Name, invalid},
  993. {app, DepName, invalid},
  994. {app, PkgName, invalid}]}).
  995. override_deps(Config) ->
  996. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  997. TopDeps = rebar_test_utils:top_level_deps(Deps),
  998. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  999. mock_git_resource:mock([{deps, SrcDeps}]),
  1000. RebarConfig = [
  1001. {deps, TopDeps},
  1002. {overrides, [
  1003. {override, some_dep, [
  1004. {deps, []}
  1005. ]}
  1006. ]}
  1007. ],
  1008. rebar_test_utils:run_and_check(
  1009. Config, RebarConfig, ["compile"],
  1010. {ok, [{dep, "some_dep"},
  1011. {dep_not_exist, "other_dep"}]}
  1012. ).
  1013. override_add_deps(Config) ->
  1014. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1015. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1016. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  1017. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  1018. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  1019. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1020. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  1021. RebarConfig = [
  1022. {deps, TopDeps},
  1023. {overrides, [
  1024. {add, some_dep, [
  1025. {deps, [DepA, DepB]}
  1026. ]},
  1027. {add, [
  1028. {deps, [DepC]}
  1029. ]}
  1030. ]}
  1031. ],
  1032. rebar_test_utils:run_and_check(
  1033. Config, RebarConfig, ["compile"],
  1034. {ok, [{dep, "some_dep"},
  1035. {dep, "other_dep"},
  1036. {dep, "dep_a"},
  1037. {dep, "dep_b"},
  1038. {dep, "dep_c"}]}
  1039. ).
  1040. override_del_deps(Config) ->
  1041. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1042. {"dep_b", "0.0.1", []},
  1043. {"dep_c", "0.0.1", []}]},
  1044. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1045. {"dep_d", "0.0.1", []}]}]),
  1046. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1047. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1048. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1049. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1050. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1051. mock_git_resource:mock([{deps, SrcDeps}]),
  1052. RebarConfig = [
  1053. {deps, TopDeps},
  1054. {overrides, [
  1055. {del, some_dep, [
  1056. {deps, [DepA, DepB]}
  1057. ]},
  1058. {del, [
  1059. {deps, [DepC]}
  1060. ]}
  1061. ]}
  1062. ],
  1063. rebar_test_utils:run_and_check(
  1064. Config, RebarConfig, ["compile"],
  1065. {ok, [{dep, "some_dep"},
  1066. {dep, "other_dep"},
  1067. {dep_not_exist, "dep_a"},
  1068. {dep_not_exist, "dep_b"},
  1069. {dep_not_exist, "dep_c"},
  1070. {dep, "dep_d"}]}
  1071. ).
  1072. override_opts(Config) ->
  1073. AppDir = ?config(apps, Config),
  1074. Name = rebar_test_utils:create_random_name("app1_"),
  1075. Vsn = rebar_test_utils:create_random_vsn(),
  1076. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1077. RebarConfig = [
  1078. {erl_opts, [
  1079. compressed,
  1080. warn_missing_spec
  1081. ]},
  1082. {overrides, [
  1083. {override, [
  1084. {erl_opts, [compressed]}
  1085. ]}
  1086. ]}
  1087. ],
  1088. rebar_test_utils:create_config(AppDir, RebarConfig),
  1089. rebar_test_utils:run_and_check(
  1090. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1091. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1092. code:add_patha(Path),
  1093. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1094. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1095. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1096. override_add_opts(Config) ->
  1097. AppDir = ?config(apps, Config),
  1098. Name = rebar_test_utils:create_random_name("app1_"),
  1099. Vsn = rebar_test_utils:create_random_vsn(),
  1100. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1101. RebarConfig = [
  1102. {erl_opts, [
  1103. warn_missing_spec
  1104. ]},
  1105. {overrides, [
  1106. {add, [
  1107. {erl_opts, [compressed]}
  1108. ]}
  1109. ]}
  1110. ],
  1111. rebar_test_utils:create_config(AppDir, RebarConfig),
  1112. rebar_test_utils:run_and_check(
  1113. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1114. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1115. code:add_patha(Path),
  1116. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1117. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1118. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1119. override_del_opts(Config) ->
  1120. AppDir = ?config(apps, Config),
  1121. Name = rebar_test_utils:create_random_name("app1_"),
  1122. Vsn = rebar_test_utils:create_random_vsn(),
  1123. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1124. RebarConfig = [
  1125. {erl_opts, [
  1126. compressed,
  1127. warn_missing_spec
  1128. ]},
  1129. {overrides, [
  1130. {del, [
  1131. {erl_opts, [warn_missing_spec]}
  1132. ]}
  1133. ]}
  1134. ],
  1135. rebar_test_utils:create_config(AppDir, RebarConfig),
  1136. rebar_test_utils:run_and_check(
  1137. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1138. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1139. code:add_patha(Path),
  1140. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1141. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1142. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1143. profile_override_deps(Config) ->
  1144. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1145. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1146. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1147. mock_git_resource:mock([{deps, SrcDeps}]),
  1148. RebarConfig = [
  1149. {deps, TopDeps},
  1150. {profiles, [
  1151. {a, [
  1152. {overrides, [
  1153. {override, some_dep, [
  1154. {deps, []}
  1155. ]}
  1156. ]}
  1157. ]}
  1158. ]}],
  1159. rebar_test_utils:run_and_check(
  1160. Config, RebarConfig, ["as", "a", "compile"],
  1161. {ok, [{dep, "some_dep"},
  1162. {dep_not_exist, "other_dep"}]}
  1163. ).
  1164. profile_override_add_deps(Config) ->
  1165. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1166. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1167. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  1168. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  1169. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  1170. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1171. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  1172. RebarConfig = [
  1173. {deps, TopDeps},
  1174. {profiles, [
  1175. {a, [
  1176. {overrides, [
  1177. {add, some_dep, [
  1178. {deps, [DepA, DepB]}
  1179. ]},
  1180. {add, [
  1181. {deps, [DepC]}
  1182. ]}
  1183. ]}
  1184. ]}
  1185. ]}
  1186. ],
  1187. rebar_test_utils:run_and_check(
  1188. Config, RebarConfig, ["as", "a", "compile"],
  1189. {ok, [{dep, "some_dep"},
  1190. {dep, "other_dep"},
  1191. {dep, "dep_a"},
  1192. {dep, "dep_b"},
  1193. {dep, "dep_c"}]}
  1194. ).
  1195. profile_override_del_deps(Config) ->
  1196. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1197. {"dep_b", "0.0.1", []},
  1198. {"dep_c", "0.0.1", []}]},
  1199. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1200. {"dep_d", "0.0.1", []}]}]),
  1201. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1202. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1203. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1204. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1205. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1206. mock_git_resource:mock([{deps, SrcDeps}]),
  1207. RebarConfig = [
  1208. {deps, TopDeps},
  1209. {profiles, [
  1210. {a, [
  1211. {overrides, [
  1212. {del, some_dep, [
  1213. {deps, [DepA, DepB]}
  1214. ]},
  1215. {del, [
  1216. {deps, [DepC]}
  1217. ]}
  1218. ]}
  1219. ]}
  1220. ]}
  1221. ],
  1222. rebar_test_utils:run_and_check(
  1223. Config, RebarConfig, ["as", "a", "compile"],
  1224. {ok, [{dep, "some_dep"},
  1225. {dep, "other_dep"},
  1226. {dep_not_exist, "dep_a"},
  1227. {dep_not_exist, "dep_b"},
  1228. {dep_not_exist, "dep_c"},
  1229. {dep, "dep_d"}]}
  1230. ).
  1231. profile_override_opts(Config) ->
  1232. AppDir = ?config(apps, Config),
  1233. Name = rebar_test_utils:create_random_name("app1_"),
  1234. Vsn = rebar_test_utils:create_random_vsn(),
  1235. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1236. RebarConfig = [
  1237. {erl_opts, [
  1238. compressed,
  1239. warn_missing_spec
  1240. ]},
  1241. {profiles, [
  1242. {a, [
  1243. {overrides, [
  1244. {override, [
  1245. {erl_opts, [compressed]}
  1246. ]}
  1247. ]}
  1248. ]}
  1249. ]}
  1250. ],
  1251. rebar_test_utils:create_config(AppDir, RebarConfig),
  1252. rebar_test_utils:run_and_check(
  1253. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1254. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1255. code:add_patha(Path),
  1256. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1257. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1258. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1259. profile_override_add_opts(Config) ->
  1260. AppDir = ?config(apps, Config),
  1261. Name = rebar_test_utils:create_random_name("app1_"),
  1262. Vsn = rebar_test_utils:create_random_vsn(),
  1263. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1264. RebarConfig = [
  1265. {erl_opts, [
  1266. warn_missing_spec
  1267. ]},
  1268. {profiles, [
  1269. {a, [
  1270. {overrides, [
  1271. {add, [
  1272. {erl_opts, [compressed]}
  1273. ]}
  1274. ]}
  1275. ]}
  1276. ]}
  1277. ],
  1278. rebar_test_utils:create_config(AppDir, RebarConfig),
  1279. rebar_test_utils:run_and_check(
  1280. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1281. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1282. code:add_patha(Path),
  1283. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1284. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1285. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1286. profile_override_del_opts(Config) ->
  1287. AppDir = ?config(apps, Config),
  1288. Name = rebar_test_utils:create_random_name("app1_"),
  1289. Vsn = rebar_test_utils:create_random_vsn(),
  1290. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1291. RebarConfig = [
  1292. {erl_opts, [
  1293. compressed,
  1294. warn_missing_spec
  1295. ]},
  1296. {profiles, [
  1297. {a, [
  1298. {overrides, [
  1299. {del, [
  1300. {erl_opts, [warn_missing_spec]}
  1301. ]}
  1302. ]}
  1303. ]}
  1304. ]}
  1305. ],
  1306. rebar_test_utils:create_config(AppDir, RebarConfig),
  1307. rebar_test_utils:run_and_check(
  1308. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1309. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1310. code:add_patha(Path),
  1311. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1312. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1313. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1314. profile_deps(Config) ->
  1315. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1316. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1317. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1318. mock_git_resource:mock([{deps, SrcDeps}]),
  1319. RebarConfig = [
  1320. {deps, TopDeps},
  1321. {profiles, [{a, []}]}],
  1322. rebar_test_utils:run_and_check(
  1323. Config, RebarConfig, ["as", "a", "compile"],
  1324. {ok, [{dep, "some_dep"},{dep, "other_dep"}]}
  1325. ).
  1326. %% verify a deps prod profile is used
  1327. %% tested by checking prod hooks run and outputs to default profile dir for dep
  1328. %% and prod deps are installed for dep
  1329. deps_build_in_prod(Config) ->
  1330. AppDir = ?config(apps, Config),
  1331. Name = rebar_test_utils:create_random_name("app1_"),
  1332. Vsn = rebar_test_utils:create_random_vsn(),
  1333. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1334. GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]),
  1335. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  1336. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  1337. mock_git_resource:mock([{deps, SrcDeps},
  1338. {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]},
  1339. {deps, [list_to_atom(PkgName)]}]}]}]}]),
  1340. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  1341. Deps = rebar_test_utils:top_level_deps(GitDeps),
  1342. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  1343. {ok, RConf} = file:consult(RConfFile),
  1344. %% Build with deps.
  1345. rebar_test_utils:run_and_check(
  1346. Config, RConf, ["compile"],
  1347. {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName},
  1348. {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]}
  1349. ).
  1350. %% verify that the proper include path is defined
  1351. %% according the erlang doc which states:
  1352. %% If the filename File is absolute (possibly after variable substitution),
  1353. %% the include file with that name is included. Otherwise, the specified file
  1354. %% is searched for in the following directories, and in this order:
  1355. %% * The current working directory
  1356. %% * The directory where the module is being compiled
  1357. %% * The directories given by the include option
  1358. include_file_relative_to_working_directory(Config) ->
  1359. AppDir = ?config(apps, Config),
  1360. Name = rebar_test_utils:create_random_name("app1_"),
  1361. Vsn = rebar_test_utils:create_random_vsn(),
  1362. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1363. Src = <<"-module(test).\n"
  1364. "\n"
  1365. "-include(\"include/test.hrl\").\n"
  1366. "\n"
  1367. "test() -> ?TEST_MACRO.\n"
  1368. "\n">>,
  1369. Include = <<"-define(TEST_MACRO, test).\n">>,
  1370. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1371. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1372. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1373. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1374. RebarConfig = [],
  1375. rebar_test_utils:run_and_check(Config, RebarConfig,
  1376. ["compile"],
  1377. {ok, [{app, Name}]}).
  1378. include_file_in_src(Config) ->
  1379. AppDir = ?config(apps, Config),
  1380. Name = rebar_test_utils:create_random_name("app1_"),
  1381. Vsn = rebar_test_utils:create_random_vsn(),
  1382. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1383. Src = <<"-module(test).\n"
  1384. "\n"
  1385. "-include(\"test.hrl\").\n"
  1386. "\n"
  1387. "test() -> ?TEST_MACRO.\n"
  1388. "\n">>,
  1389. Include = <<"-define(TEST_MACRO, test).\n">>,
  1390. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1391. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1392. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1393. RebarConfig = [],
  1394. rebar_test_utils:run_and_check(Config, RebarConfig,
  1395. ["compile"],
  1396. {ok, [{app, Name}]}).
  1397. %% verify that the proper include path is defined
  1398. %% according the erlang doc which states:
  1399. %% If the filename File is absolute (possibly after variable substitution),
  1400. %% the include file with that name is included. Otherwise, the specified file
  1401. %% is searched for in the following directories, and in this order:
  1402. %% * The current working directory
  1403. %% * The directory where the module is being compiled
  1404. %% * The directories given by the include option
  1405. %%
  1406. %% This test ensures that things keep working when additional directories
  1407. %% are used for apps, such as the test/ directory within the test profile.
  1408. include_file_relative_to_working_directory_test(Config) ->
  1409. AppDir = ?config(apps, Config),
  1410. Name = rebar_test_utils:create_random_name("app1_"),
  1411. Vsn = rebar_test_utils:create_random_vsn(),
  1412. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1413. Src = <<"-module(test).\n"
  1414. "\n"
  1415. "-include(\"include/test.hrl\").\n"
  1416. "\n"
  1417. "test() -> ?TEST_MACRO.\n"
  1418. "\n">>,
  1419. Include = <<"-define(TEST_MACRO, test).\n">>,
  1420. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1421. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1422. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1423. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1424. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1425. RebarConfig = [],
  1426. rebar_test_utils:run_and_check(Config, RebarConfig,
  1427. ["as", "test", "compile"],
  1428. {ok, [{app, Name}]}).
  1429. %% Same as `include_file_in_src/1' but using the `test/' directory
  1430. %% within the test profile.
  1431. include_file_in_src_test(Config) ->
  1432. AppDir = ?config(apps, Config),
  1433. Name = rebar_test_utils:create_random_name("app1_"),
  1434. Vsn = rebar_test_utils:create_random_vsn(),
  1435. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1436. Src = <<"-module(test).\n"
  1437. "\n"
  1438. "-include(\"test.hrl\").\n"
  1439. "\n"
  1440. "test() -> ?TEST_MACRO.\n"
  1441. "\n">>,
  1442. Include = <<"-define(TEST_MACRO, test).\n">>,
  1443. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1444. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1445. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1446. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1447. RebarConfig = [],
  1448. rebar_test_utils:run_and_check(Config, RebarConfig,
  1449. ["as", "test", "compile"],
  1450. {ok, [{app, Name}]}).
  1451. %% Same as `include_file_in_src_test/1' but using multiple top-level
  1452. %% apps as dependencies.
  1453. include_file_in_src_test_multiapp(Config) ->
  1454. Name1 = rebar_test_utils:create_random_name("app2_"),
  1455. Name2 = rebar_test_utils:create_random_name("app1_"),
  1456. AppDir1 = filename:join([?config(apps, Config), "lib", Name1]),
  1457. AppDir2 = filename:join([?config(apps, Config), "lib", Name2]),
  1458. Vsn = rebar_test_utils:create_random_vsn(),
  1459. rebar_test_utils:create_app(AppDir1, Name1, Vsn, [kernel, stdlib]),
  1460. rebar_test_utils:create_app(AppDir2, Name2, Vsn, [kernel, stdlib]),
  1461. Src = "-module(test).\n"
  1462. "\n"
  1463. "-include_lib(\"" ++ Name2 ++ "/include/test.hrl\").\n"
  1464. "\n"
  1465. "test() -> ?TEST_MACRO.\n"
  1466. "\n",
  1467. Include = <<"-define(TEST_MACRO, test).\n">>,
  1468. ok = filelib:ensure_dir(filename:join([AppDir1, "src", "dummy"])),
  1469. ok = filelib:ensure_dir(filename:join([AppDir1, "test", "dummy"])),
  1470. ok = filelib:ensure_dir(filename:join([AppDir2, "src", "dummy"])),
  1471. ok = filelib:ensure_dir(filename:join([AppDir2, "include", "dummy"])),
  1472. ok = file:write_file(filename:join([AppDir1, "test", "test.erl"]), Src),
  1473. ok = file:write_file(filename:join([AppDir2, "include", "test.hrl"]), Include),
  1474. RebarConfig = [],
  1475. rebar_test_utils:run_and_check(Config, RebarConfig,
  1476. ["as", "test", "compile"],
  1477. {ok, [{app, Name1}]}).
  1478. %% this test sets the env var, compiles, records the file last modified timestamp,
  1479. %% recompiles and compares the file last modified timestamp to ensure it hasn't
  1480. %% changed. this test should run on 19.x+
  1481. dont_recompile_when_erl_compiler_options_env_does_not_change(Config) ->
  1482. %% save existing env to restore after test
  1483. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1484. AppDir = ?config(apps, Config),
  1485. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1486. Vsn = rebar_test_utils:create_random_vsn(),
  1487. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1488. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1489. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1490. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1491. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1492. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1493. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1494. || F <- Files, filename:extension(F) == ".beam"],
  1495. timer:sleep(1000),
  1496. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1497. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1498. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1499. || F <- NewFiles, filename:extension(F) == ".beam"],
  1500. ?assert(ModTime == NewModTime),
  1501. %% restore existing env
  1502. case ExistingEnv of
  1503. false -> ok;
  1504. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1505. end.
  1506. %% this test compiles, records the file last modified timestamp, sets the env
  1507. %% var, recompiles and compares the file last modified timestamp to ensure it
  1508. %% has changed. this test should run on 19.x+
  1509. recompile_when_erl_compiler_options_env_changes(Config) ->
  1510. %% save existing env to restore after test
  1511. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1512. AppDir = ?config(apps, Config),
  1513. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1514. Vsn = rebar_test_utils:create_random_vsn(),
  1515. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1516. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1517. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1518. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1519. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1520. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1521. || F <- Files, filename:extension(F) == ".beam"],
  1522. timer:sleep(1000),
  1523. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1524. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1525. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1526. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1527. || F <- NewFiles, filename:extension(F) == ".beam"],
  1528. ?assert(ModTime =/= NewModTime),
  1529. %% restore existing env
  1530. case ExistingEnv of
  1531. false -> ok;
  1532. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1533. end.
  1534. %% this test sets the env var, compiles, records the file last modified
  1535. %% timestamp, recompiles and compares the file last modified timestamp to
  1536. %% ensure it has changed. this test should run on 18.x
  1537. always_recompile_when_erl_compiler_options_set(Config) ->
  1538. %% save existing env to restore after test
  1539. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1540. AppDir = ?config(apps, Config),
  1541. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1542. Vsn = rebar_test_utils:create_random_vsn(),
  1543. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1544. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1545. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1546. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1547. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1548. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1549. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1550. || F <- Files, filename:extension(F) == ".beam"],
  1551. timer:sleep(1000),
  1552. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1553. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1554. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1555. || F <- NewFiles, filename:extension(F) == ".beam"],
  1556. ?assert(ModTime =/= NewModTime),
  1557. %% restore existing env
  1558. case ExistingEnv of
  1559. false -> ok;
  1560. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1561. end.
  1562. recompile_when_parse_transform_inline_changes(Config) ->
  1563. AppDir = ?config(apps, Config),
  1564. Name = rebar_test_utils:create_random_name("parse_transform_inline_"),
  1565. Vsn = rebar_test_utils:create_random_vsn(),
  1566. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1567. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1568. ModSrc = <<"-module(example).\n"
  1569. "-export([foo/2]).\n"
  1570. "-compile([{parse_transform, example_parse_transform}]).\n"
  1571. "foo(_, _) -> ok.">>,
  1572. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1573. ModSrc),
  1574. ParseTransform = <<"-module(example_parse_transform).\n"
  1575. "-export([parse_transform/2]).\n"
  1576. "parse_transform(AST, _) -> AST.\n">>,
  1577. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1578. ParseTransform),
  1579. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1580. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1581. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1582. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1583. || F <- Files, filename:basename(F, ".beam") == "example"],
  1584. timer:sleep(1000),
  1585. NewParseTransform = <<"-module(example_parse_transform).\n"
  1586. "-export([parse_transform/2]).\n"
  1587. "parse_transform(AST, _) -> identity(AST).\n"
  1588. "identity(AST) -> AST.\n">>,
  1589. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1590. NewParseTransform),
  1591. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1592. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1593. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1594. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1595. ?assert(ModTime =/= NewModTime).
  1596. recompile_when_parse_transform_as_opt_changes(Config) ->
  1597. AppDir = ?config(apps, Config),
  1598. Name = rebar_test_utils:create_random_name("parse_transform_opt_"),
  1599. Vsn = rebar_test_utils:create_random_vsn(),
  1600. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1601. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1602. ModSrc = <<"-module(example).\n"
  1603. "-export([foo/2]).\n"
  1604. "foo(_, _) -> ok.">>,
  1605. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1606. ModSrc),
  1607. ParseTransform = <<"-module(example_parse_transform).\n"
  1608. "-export([parse_transform/2]).\n"
  1609. "parse_transform(AST, _) -> AST.">>,
  1610. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1611. ParseTransform),
  1612. RebarConfig = [{erl_opts, [{parse_transform, example_parse_transform}]}],
  1613. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1614. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1615. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1616. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1617. || F <- Files, filename:basename(F, ".beam") == "example"],
  1618. timer:sleep(1000),
  1619. NewParseTransform = <<"-module(example_parse_transform).\n"
  1620. "-export([parse_transform/2]).\n"
  1621. "parse_transform(AST, _) -> identity(AST).\n"
  1622. "identity(AST) -> AST.">>,
  1623. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1624. NewParseTransform),
  1625. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1626. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1627. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1628. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1629. ?assert(ModTime =/= NewModTime).
  1630. recursive(Config) ->
  1631. AppDir = ?config(apps, Config),
  1632. Name = rebar_test_utils:create_random_name("app1_"),
  1633. Vsn = rebar_test_utils:create_random_vsn(),
  1634. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1635. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1636. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1637. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1638. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1639. ?assert(lists:member("rec.beam",Files)).
  1640. no_recursive(Config) ->
  1641. AppDir = ?config(apps, Config),
  1642. Name = rebar_test_utils:create_random_name("app1_"),
  1643. Vsn = rebar_test_utils:create_random_vsn(),
  1644. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1645. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1646. RebarConfig1 = [{erlc_compiler,[{recursive,false}]}],
  1647. rebar_test_utils:run_and_check(Config, RebarConfig1, ["compile"],
  1648. {ok, [{app, Name}]}),
  1649. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1650. {ok, Files1} = rebar_utils:list_dir(EbinDir),
  1651. ?assert(false==lists:member("rec.beam",Files1)),
  1652. RebarConfig2 = [{src_dirs,[{"src",[{recursive,false}]}]}],
  1653. rebar_test_utils:run_and_check(Config, RebarConfig2, ["compile"],
  1654. {ok, [{app, Name}]}),
  1655. {ok, Files2} = rebar_utils:list_dir(EbinDir),
  1656. ?assert(false==lists:member("rec.beam",Files2)),
  1657. ok.
  1658. regex_filter_skip(Config) ->
  1659. AppDir = ?config(apps, Config),
  1660. Name = rebar_test_utils:create_random_name("regex_skip"),
  1661. Vsn = rebar_test_utils:create_random_vsn(),
  1662. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1663. rebar_test_utils:write_src_file(filename:join(AppDir,src),"._rec.erl"),
  1664. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","._rec.beam"]),
  1665. RebarConfig = [],
  1666. try
  1667. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1668. {ok, [{file, Expected}]}),
  1669. throw(should_not_be_found)
  1670. catch
  1671. %% the file was not found, as desired!
  1672. error:{assertion_failed,_} -> %% OTP =< 17
  1673. ok;
  1674. error:{assert,_} -> %% OTP >= 18
  1675. ok
  1676. end.
  1677. regex_filter_regression(Config) ->
  1678. AppDir = ?config(apps, Config),
  1679. Name = rebar_test_utils:create_random_name("regex_regression"),
  1680. Vsn = rebar_test_utils:create_random_vsn(),
  1681. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1682. rebar_test_utils:write_src_file(filename:join(AppDir,src),"r_f.erl"),
  1683. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","r_f.beam"]),
  1684. RebarConfig = [],
  1685. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1686. {ok, [{file, Expected}]}),
  1687. ok.