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

1205 lines
49 KiB

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 9 години
преди 9 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
  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_opts_change/1,
  26. dont_recompile_when_opts_dont_change/1,
  27. dont_recompile_yrl_or_xrl/1,
  28. deps_in_path/1,
  29. delete_beam_if_source_deleted/1,
  30. checkout_priority/1,
  31. highest_version_of_pkg_dep/1,
  32. parse_transform_test/1,
  33. erl_first_files_test/1,
  34. mib_test/1,
  35. umbrella_mib_first_test/1,
  36. only_default_transitive_deps/1,
  37. clean_all/1,
  38. override_deps/1,
  39. profile_override_deps/1,
  40. deps_build_in_prod/1]).
  41. -include_lib("common_test/include/ct.hrl").
  42. -include_lib("eunit/include/eunit.hrl").
  43. -include_lib("kernel/include/file.hrl").
  44. suite() ->
  45. [].
  46. all() ->
  47. [{group, basic_app}, {group, release_apps},
  48. {group, checkout_apps}, {group, checkout_deps},
  49. {group, basic_srcdirs}, {group, release_srcdirs}, {group, unbalanced_srcdirs},
  50. {group, basic_extras}, {group, release_extras}, {group, unbalanced_extras},
  51. {group, root_extras},
  52. recompile_when_hrl_changes, recompile_when_opts_change,
  53. dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl,
  54. delete_beam_if_source_deleted,
  55. deps_in_path, checkout_priority, highest_version_of_pkg_dep,
  56. parse_transform_test, erl_first_files_test, mib_test,
  57. umbrella_mib_first_test, only_default_transitive_deps,
  58. clean_all, override_deps, profile_override_deps, deps_build_in_prod].
  59. groups() ->
  60. [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
  61. {release_apps, [], [build_release_apps, paths_release_apps, clean_release_apps]},
  62. {checkout_apps, [], [build_checkout_apps, paths_checkout_apps]},
  63. {checkout_deps, [], [build_checkout_deps, paths_checkout_deps]},
  64. {basic_srcdirs, [], [build_basic_srcdirs, paths_basic_srcdirs]},
  65. {release_srcdirs, [], [build_release_srcdirs,
  66. paths_release_srcdirs]},
  67. {unbalanced_srcdirs, [], [build_unbalanced_srcdirs,
  68. paths_unbalanced_srcdirs]},
  69. {basic_extras, [], [build_basic_extra_dirs,
  70. paths_basic_extra_dirs,
  71. clean_basic_extra_dirs]},
  72. {release_extras, [], [build_release_extra_dirs,
  73. paths_release_extra_dirs,
  74. clean_release_extra_dirs]},
  75. {unbalanced_extras, [], [build_unbalanced_extra_dirs,
  76. paths_unbalanced_extra_dirs]},
  77. {root_extras, [], [build_extra_dirs_in_project_root,
  78. paths_extra_dirs_in_project_root,
  79. clean_extra_dirs_in_project_root]}].
  80. init_per_group(basic_app, Config) ->
  81. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  82. AppDir = ?config(apps, NewConfig),
  83. Name = rebar_test_utils:create_random_name("app1"),
  84. Vsn = rebar_test_utils:create_random_vsn(),
  85. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  86. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  87. init_per_group(release_apps, Config) ->
  88. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_apps_"),
  89. AppDir = ?config(apps, NewConfig),
  90. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  91. Vsn1 = rebar_test_utils:create_random_vsn(),
  92. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  93. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  94. Vsn2 = rebar_test_utils:create_random_vsn(),
  95. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  96. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  97. init_per_group(checkout_apps, Config) ->
  98. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_apps_"),
  99. AppDir = ?config(apps, NewConfig),
  100. CheckoutsDir = ?config(checkouts, NewConfig),
  101. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  102. Vsn1 = rebar_test_utils:create_random_vsn(),
  103. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  104. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  105. Vsn2 = rebar_test_utils:create_random_vsn(),
  106. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  107. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  108. init_per_group(checkout_deps, Config) ->
  109. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_deps_"),
  110. AppDir = ?config(apps, NewConfig),
  111. CheckoutsDir = ?config(checkouts, NewConfig),
  112. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  113. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  114. Vsn1 = rebar_test_utils:create_random_vsn(),
  115. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  116. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  117. Vsn2 = rebar_test_utils:create_random_vsn(),
  118. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  119. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  120. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  121. init_per_group(Group, Config) when Group == basic_srcdirs; Group == basic_extras ->
  122. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_srcdirs_"),
  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. ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
  128. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  129. ok = file:write_file(filename:join([AppDir, "extra", io_lib:format("~ts_extra.erl", [Name])]),
  130. ExtraSrc),
  131. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  132. init_per_group(Group, Config) when Group == release_srcdirs; Group == release_extras ->
  133. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_srcdirs_"),
  134. AppDir = ?config(apps, NewConfig),
  135. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  136. Vsn1 = rebar_test_utils:create_random_vsn(),
  137. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  138. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  139. Vsn2 = rebar_test_utils:create_random_vsn(),
  140. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  141. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  142. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  143. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  144. io_lib:format("~ts_extra.erl", [Name1])]),
  145. ExtraOne),
  146. ExtraTwo = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name2]),
  147. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "extra", "dummy"])),
  148. ok = file:write_file(filename:join([AppDir, "apps", Name2, "extra",
  149. io_lib:format("~ts_extra.erl", [Name2])]),
  150. ExtraTwo),
  151. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  152. init_per_group(Group, Config) when Group == unbalanced_srcdirs; Group == unbalanced_extras ->
  153. NewConfig = rebar_test_utils:init_rebar_state(Config, "unbalanced_srcdirs_"),
  154. AppDir = ?config(apps, NewConfig),
  155. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  156. Vsn1 = rebar_test_utils:create_random_vsn(),
  157. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  158. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  159. Vsn2 = rebar_test_utils:create_random_vsn(),
  160. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  161. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  162. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  163. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  164. io_lib:format("~ts_extra.erl", [Name1])]),
  165. ExtraOne),
  166. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  167. init_per_group(root_extras, Config) ->
  168. NewConfig = rebar_test_utils:init_rebar_state(Config, "root_extras_"),
  169. AppDir = ?config(apps, NewConfig),
  170. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  171. Vsn1 = rebar_test_utils:create_random_vsn(),
  172. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  173. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  174. Vsn2 = rebar_test_utils:create_random_vsn(),
  175. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  176. Extra = <<"-module(extra).\n-export([ok/0]).\nok() -> ok.\n">>,
  177. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  178. ok = file:write_file(filename:join([AppDir, "extra", "extra.erl"]), Extra),
  179. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig].
  180. end_per_group(_Group, _Config) ->
  181. ok.
  182. init_per_suite(Config) ->
  183. Config.
  184. end_per_suite(_Config) ->
  185. ok.
  186. init_per_testcase(_, Config) ->
  187. case ?config(apps, Config) of
  188. undefined -> rebar_test_utils:init_rebar_state(Config);
  189. _ -> Config
  190. end.
  191. end_per_testcase(_, _Config) ->
  192. catch meck:unload().
  193. %% test cases
  194. build_basic_app(Config) ->
  195. [Name] = ?config(app_names, Config),
  196. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  197. build_release_apps(Config) ->
  198. [Name1, Name2] = ?config(app_names, Config),
  199. rebar_test_utils:run_and_check(
  200. Config, [], ["compile"],
  201. {ok, [{app, Name1}, {app, Name2}]}
  202. ).
  203. build_checkout_apps(Config) ->
  204. [Name1, Name2] = ?config(app_names, Config),
  205. rebar_test_utils:run_and_check(
  206. Config, [], ["compile"],
  207. {ok, [{app, Name1}, {checkout, Name2}]}
  208. ).
  209. build_checkout_deps(Config) ->
  210. AppDir = ?config(apps, Config),
  211. [Name1, Name2] = ?config(app_names, Config),
  212. [_, Vsn2] = ?config(vsns, Config),
  213. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  214. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  215. rebar_test_utils:run_and_check(
  216. Config, RebarConfig, ["compile"],
  217. {ok, [{app, Name1}, {checkout, Name2}]}
  218. ).
  219. build_basic_srcdirs(Config) ->
  220. AppDir = ?config(apps, Config),
  221. [Name] = ?config(app_names, Config),
  222. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  223. %% check a beam corresponding to the src in the extra src_dir exists
  224. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  225. io_lib:format("~ts_extra.beam", [Name])]),
  226. %% check the extra src_dir was copied/linked into the _build dir
  227. ExtraDir = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  228. rebar_test_utils:run_and_check(
  229. Config, RebarConfig, ["compile"],
  230. {ok, [{app, Name}, {file, ExtraBeam}, {dir, ExtraDir}]}
  231. ).
  232. build_release_srcdirs(Config) ->
  233. AppDir = ?config(apps, Config),
  234. [Name1, Name2] = ?config(app_names, Config),
  235. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  236. %% check a beam corresponding to the src in the extra src_dir exists
  237. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  238. io_lib:format("~ts_extra.beam", [Name1])]),
  239. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  240. io_lib:format("~ts_extra.beam", [Name2])]),
  241. %% check the extra src_dir was copied/linked into the _build dir
  242. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  243. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  244. rebar_test_utils:run_and_check(
  245. Config, RebarConfig, ["compile"],
  246. {ok, [{app, Name1}, {app, Name2},
  247. {file, Extra1Beam}, {file, Extra2Beam},
  248. {dir, Extra1Dir}, {dir, Extra2Dir}]}
  249. ).
  250. build_unbalanced_srcdirs(Config) ->
  251. AppDir = ?config(apps, Config),
  252. [Name1, Name2] = ?config(app_names, Config),
  253. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  254. %% check a beam corresponding to the src in the extra src_dir exists
  255. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  256. io_lib:format("~ts_extra.beam", [Name1])]),
  257. %% check the extra src_dir was copied/linked into the _build dir
  258. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  259. rebar_test_utils:run_and_check(
  260. Config, RebarConfig, ["compile"],
  261. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {dir, Extra1Dir}]}
  262. ),
  263. %% check no extra src_dir were copied/linked into the _build dir
  264. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  265. false = filelib:is_dir(Extra2Dir),
  266. %% check only expected beams are in the ebin dir
  267. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  268. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  269. Files).
  270. build_basic_extra_dirs(Config) ->
  271. AppDir = ?config(apps, Config),
  272. [Name] = ?config(app_names, Config),
  273. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  274. %% check a beam corresponding to the src in the extra src_dir exists
  275. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  276. io_lib:format("~ts_extra.beam", [Name])]),
  277. rebar_test_utils:run_and_check(
  278. Config, RebarConfig, ["compile"],
  279. {ok, [{app, Name}, {file, ExtraBeam}]}
  280. ).
  281. build_release_extra_dirs(Config) ->
  282. AppDir = ?config(apps, Config),
  283. [Name1, Name2] = ?config(app_names, Config),
  284. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  285. %% check a beam corresponding to the src in the extra src_dir exists
  286. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  287. io_lib:format("~ts_extra.beam", [Name1])]),
  288. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  289. io_lib:format("~ts_extra.beam", [Name2])]),
  290. rebar_test_utils:run_and_check(
  291. Config, RebarConfig, ["compile"],
  292. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {file, Extra2Beam}]}
  293. ).
  294. build_unbalanced_extra_dirs(Config) ->
  295. AppDir = ?config(apps, Config),
  296. [Name1, Name2] = ?config(app_names, Config),
  297. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  298. %% check a beam corresponding to the src in the extra src_dir exists
  299. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  300. io_lib:format("~ts_extra.beam", [Name1])]),
  301. rebar_test_utils:run_and_check(
  302. Config, RebarConfig, ["compile"],
  303. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}]}
  304. ),
  305. %% check no extra src_dir were copied/linked into the _build dir
  306. false = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "extra"])),
  307. %% check only expected beams are in the ebin dir
  308. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  309. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  310. Files).
  311. build_extra_dirs_in_project_root(Config) ->
  312. AppDir = ?config(apps, Config),
  313. [Name1, Name2] = ?config(app_names, Config),
  314. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  315. %% check a beam corresponding to the src in the extra src_dir exists
  316. ExtraBeam = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  317. rebar_test_utils:run_and_check(
  318. Config, RebarConfig, ["compile"],
  319. {ok, [{app, Name1}, {app, Name2}, {file, ExtraBeam}]}
  320. ).
  321. paths_basic_app(Config) ->
  322. [Name] = ?config(app_names, Config),
  323. [Vsn] = ?config(vsns, Config),
  324. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  325. code:add_paths(rebar_state:code_paths(State, all_deps)),
  326. ok = application:load(list_to_atom(Name)),
  327. Loaded = application:loaded_applications(),
  328. {_, _, Vsn} = lists:keyfind(list_to_atom(Name), 1, Loaded).
  329. paths_release_apps(Config) ->
  330. [Name1, Name2] = ?config(app_names, Config),
  331. [Vsn1, Vsn2] = ?config(vsns, Config),
  332. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  333. code:add_paths(rebar_state:code_paths(State, all_deps)),
  334. ok = application:load(list_to_atom(Name1)),
  335. ok = application:load(list_to_atom(Name2)),
  336. Loaded = application:loaded_applications(),
  337. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded),
  338. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  339. paths_checkout_apps(Config) ->
  340. [Name1, _Name2] = ?config(app_names, Config),
  341. [Vsn1, _Vsn2] = ?config(vsns, Config),
  342. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  343. code:add_paths(rebar_state:code_paths(State, all_deps)),
  344. ok = application:load(list_to_atom(Name1)),
  345. Loaded = application:loaded_applications(),
  346. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded).
  347. paths_checkout_deps(Config) ->
  348. AppDir = ?config(apps, Config),
  349. [_Name1, Name2] = ?config(app_names, Config),
  350. [_Vsn1, Vsn2] = ?config(vsns, Config),
  351. %% rebar_test_utils:init_rebar_state/1,2 uses rebar_state:new/3 which
  352. %% maybe incorrectly sets deps to [] (based on `rebar.lock`) instead of
  353. %% to the checkapps
  354. %% until that is sorted out the lock file has to be removed before
  355. %% this test will pass
  356. file:delete(filename:join([AppDir, "rebar.lock"])),
  357. {ok, RebarConfig} = file:consult(filename:join([AppDir, "rebar.config"])),
  358. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  359. code:add_paths(rebar_state:code_paths(State, all_deps)),
  360. ok = application:load(list_to_atom(Name2)),
  361. Loaded = application:loaded_applications(),
  362. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  363. paths_basic_srcdirs(Config) ->
  364. AppDir = ?config(apps, Config),
  365. [Name] = ?config(app_names, Config),
  366. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  367. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  368. code:add_paths(rebar_state:code_paths(State, all_deps)),
  369. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  370. {module, Mod} = code:ensure_loaded(Mod),
  371. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  372. io_lib:format("~ts_extra.beam", [Name])]),
  373. Expect = code:which(Mod).
  374. paths_release_srcdirs(Config) ->
  375. AppDir = ?config(apps, Config),
  376. [Name1, Name2] = ?config(app_names, Config),
  377. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  378. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  379. code:add_paths(rebar_state:code_paths(State, all_deps)),
  380. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  381. {module, Mod1} = code:ensure_loaded(Mod1),
  382. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  383. {module, Mod2} = code:ensure_loaded(Mod2),
  384. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  385. io_lib:format("~ts_extra.beam", [Name1])]),
  386. ExpectOne = code:which(Mod1),
  387. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  388. io_lib:format("~ts_extra.beam", [Name2])]),
  389. ExpectTwo = code:which(Mod2).
  390. paths_unbalanced_srcdirs(Config) ->
  391. AppDir = ?config(apps, Config),
  392. [Name1, Name2] = ?config(app_names, Config),
  393. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  394. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  395. code:add_paths(rebar_state:code_paths(State, all_deps)),
  396. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  397. {module, Mod1} = code:ensure_loaded(Mod1),
  398. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  399. {error, nofile} = code:ensure_loaded(Mod2),
  400. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  401. io_lib:format("~ts_extra.beam", [Name1])]),
  402. ExpectOne = code:which(Mod1).
  403. paths_basic_extra_dirs(Config) ->
  404. AppDir = ?config(apps, Config),
  405. [Name] = ?config(app_names, Config),
  406. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  407. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  408. code:add_paths(rebar_state:code_paths(State, all_deps)),
  409. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  410. {module, Mod} = code:ensure_loaded(Mod),
  411. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  412. io_lib:format("~ts_extra.beam", [Name])]),
  413. Expect = code:which(Mod).
  414. paths_release_extra_dirs(Config) ->
  415. AppDir = ?config(apps, Config),
  416. [Name1, Name2] = ?config(app_names, Config),
  417. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  418. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  419. code:add_paths(rebar_state:code_paths(State, all_deps)),
  420. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  421. {module, Mod1} = code:ensure_loaded(Mod1),
  422. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  423. {module, Mod2} = code:ensure_loaded(Mod2),
  424. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  425. io_lib:format("~ts_extra.beam", [Name1])]),
  426. ExpectOne = code:which(Mod1),
  427. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  428. io_lib:format("~ts_extra.beam", [Name2])]),
  429. ExpectTwo = code:which(Mod2).
  430. paths_unbalanced_extra_dirs(Config) ->
  431. AppDir = ?config(apps, Config),
  432. [Name1, Name2] = ?config(app_names, Config),
  433. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  434. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  435. code:add_paths(rebar_state:code_paths(State, all_deps)),
  436. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  437. {module, Mod1} = code:ensure_loaded(Mod1),
  438. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  439. {error, nofile} = code:ensure_loaded(Mod2),
  440. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  441. io_lib:format("~ts_extra.beam", [Name1])]),
  442. ExpectOne = code:which(Mod1).
  443. paths_extra_dirs_in_project_root(Config) ->
  444. AppDir = ?config(apps, Config),
  445. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  446. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  447. code:add_paths(rebar_state:code_paths(State, all_deps)),
  448. {module, extra} = code:ensure_loaded(extra),
  449. Expect = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  450. Expect = code:which(extra).
  451. clean_basic_app(Config) ->
  452. [Name] = ?config(app_names, Config),
  453. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}).
  454. clean_release_apps(Config) ->
  455. [Name1, Name2] = ?config(app_names, Config),
  456. rebar_test_utils:run_and_check(Config, [], ["clean"],
  457. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}).
  458. clean_basic_extra_dirs(Config) ->
  459. AppDir = ?config(apps, Config),
  460. [Name] = ?config(app_names, Config),
  461. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}),
  462. Beam = lists:flatten(io_lib:format("~ts_extra", [Name])),
  463. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name, "extras", Beam])).
  464. clean_release_extra_dirs(Config) ->
  465. AppDir = ?config(apps, Config),
  466. [Name1, Name2] = ?config(app_names, Config),
  467. rebar_test_utils:run_and_check(Config, [], ["clean"],
  468. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  469. Beam1 = lists:flatten(io_lib:format("~ts_extra", [Name1])),
  470. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name1, "extras", Beam1])),
  471. Beam2 = lists:flatten(io_lib:format("~ts_extra", [Name2])),
  472. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name2, "extras", Beam2])).
  473. clean_extra_dirs_in_project_root(Config) ->
  474. AppDir = ?config(apps, Config),
  475. [Name1, Name2] = ?config(app_names, Config),
  476. rebar_test_utils:run_and_check(Config, [], ["clean"],
  477. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  478. false = ec_file:exists(filename:join([AppDir, "_build", "default", "extras"])).
  479. recompile_when_hrl_changes(Config) ->
  480. AppDir = ?config(apps, Config),
  481. Name = rebar_test_utils:create_random_name("app1_"),
  482. Vsn = rebar_test_utils:create_random_vsn(),
  483. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  484. ExtraSrc = <<"-module(test_header_include).\n"
  485. "-export([main/0]).\n"
  486. "-include(\"test_header_include.hrl\").\n"
  487. "main() -> ?SOME_DEFINE.\n">>,
  488. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  489. HeaderFile = filename:join([AppDir, "src", "test_header_include.hrl"]),
  490. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  491. ok = file:write_file(HeaderFile, ExtraHeader),
  492. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  493. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  494. {ok, Files} = rebar_utils:list_dir(EbinDir),
  495. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  496. || F <- Files, filename:extension(F) == ".beam"],
  497. timer:sleep(1000),
  498. rebar_file_utils:touch(HeaderFile),
  499. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  500. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  501. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  502. || F <- NewFiles, filename:extension(F) == ".beam"],
  503. ?assert(ModTime =/= NewModTime).
  504. recompile_when_opts_change(Config) ->
  505. AppDir = ?config(apps, Config),
  506. Name = rebar_test_utils:create_random_name("app1_"),
  507. Vsn = rebar_test_utils:create_random_vsn(),
  508. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  509. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  510. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  511. {ok, Files} = rebar_utils:list_dir(EbinDir),
  512. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  513. || F <- Files, filename:extension(F) == ".beam"],
  514. timer:sleep(1000),
  515. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  516. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  517. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  518. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  519. || F <- NewFiles, filename:extension(F) == ".beam"],
  520. ?assert(ModTime =/= NewModTime).
  521. dont_recompile_when_opts_dont_change(Config) ->
  522. AppDir = ?config(apps, Config),
  523. Name = rebar_test_utils:create_random_name("app1_"),
  524. Vsn = rebar_test_utils:create_random_vsn(),
  525. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  526. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  527. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  528. {ok, Files} = rebar_utils:list_dir(EbinDir),
  529. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  530. || F <- Files, filename:extension(F) == ".beam"],
  531. timer:sleep(1000),
  532. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  533. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  534. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  535. || F <- NewFiles, filename:extension(F) == ".beam"],
  536. ?assert(ModTime == NewModTime).
  537. dont_recompile_yrl_or_xrl(Config) ->
  538. AppDir = ?config(apps, Config),
  539. Name = rebar_test_utils:create_random_name("app1_"),
  540. Vsn = rebar_test_utils:create_random_vsn(),
  541. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  542. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  543. ok = filelib:ensure_dir(Xrl),
  544. XrlBody =
  545. "Definitions."
  546. "\n\n"
  547. "D = [0-9]"
  548. "\n\n"
  549. "Rules."
  550. "\n\n"
  551. "{D}+ :"
  552. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  553. "\n\n"
  554. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  555. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  556. "\n\n"
  557. "Erlang code.",
  558. ok = ec_file:write(Xrl, XrlBody),
  559. XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]),
  560. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  561. ModTime = filelib:last_modified(XrlBeam),
  562. timer:sleep(1000),
  563. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  564. NewModTime = filelib:last_modified(XrlBeam),
  565. ?assert(ModTime == NewModTime).
  566. delete_beam_if_source_deleted(Config) ->
  567. AppDir = ?config(apps, Config),
  568. Name = rebar_test_utils:create_random_name("app1_"),
  569. Vsn = rebar_test_utils:create_random_vsn(),
  570. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  571. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  572. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  573. _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]),
  574. ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))),
  575. file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])),
  576. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  577. ?assertNot(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))).
  578. deps_in_path(Config) ->
  579. AppDir = ?config(apps, Config),
  580. StartPaths = code:get_path(),
  581. Name = rebar_test_utils:create_random_name("app1_"),
  582. Vsn = rebar_test_utils:create_random_vsn(),
  583. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  584. DepName = rebar_test_utils:create_random_name("dep1_"),
  585. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  586. mock_git_resource:mock([]),
  587. mock_pkg_resource:mock([
  588. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  589. ]),
  590. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  591. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  592. {list_to_atom(PkgName), Vsn}
  593. ]}]),
  594. {ok, RConf} = file:consult(RConfFile),
  595. %% Make sure apps we look for are not visible
  596. %% Hope not to find src name
  597. ?assertEqual([], [Path || Path <- code:get_path(),
  598. {match, _} <- [re:run(Path, DepName)]]),
  599. %% Hope not to find pkg name in there
  600. ?assertEqual([], [Path || Path <- code:get_path(),
  601. {match, _} <- [re:run(Path, PkgName)]]),
  602. %% Build things
  603. {ok, State} = rebar_test_utils:run_and_check(
  604. Config, RConf, ["compile"],
  605. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  606. ),
  607. code:add_paths(rebar_state:code_paths(State, all_deps)),
  608. %% Find src name in there
  609. ?assertNotEqual([], [Path || Path <- code:get_path(),
  610. {match, _} <- [re:run(Path, DepName)]]),
  611. %% find pkg name in there
  612. ?assertNotEqual([], [Path || Path <- code:get_path(),
  613. {match, _} <- [re:run(Path, PkgName)]]),
  614. true = code:set_path(lists:filter(fun(P) -> ec_file:exists(P) end, StartPaths)),
  615. %% Make sure apps we look for are not visible again
  616. %% Hope not to find src name
  617. ?assertEqual([], [Path || Path <- code:get_path(),
  618. {match, _} <- [re:run(Path, DepName)]]),
  619. %% Hope not to find pkg name in there
  620. ?assertEqual([], [Path || Path <- code:get_path(),
  621. {match, _} <- [re:run(Path, PkgName)]]),
  622. %% Rebuild
  623. {ok, State1} = rebar_test_utils:run_and_check(
  624. Config, RConf, ["compile"],
  625. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  626. ),
  627. %% Find src name in there
  628. code:add_paths(rebar_state:code_paths(State1, all_deps)),
  629. ?assertNotEqual([], [Path || Path <- code:get_path(),
  630. {match, _} <- [re:run(Path, DepName)]]),
  631. %% find pkg name in there
  632. ?assertNotEqual([], [Path || Path <- code:get_path(),
  633. {match, _} <- [re:run(Path, PkgName)]]).
  634. checkout_priority(Config) ->
  635. AppDir = ?config(apps, Config),
  636. CheckoutsDir = ?config(checkouts, Config),
  637. StartPaths = code:get_path(),
  638. Name = rebar_test_utils:create_random_name("app1_"),
  639. Vsn = rebar_test_utils:create_random_vsn(),
  640. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  641. DepName = rebar_test_utils:create_random_name("dep1_"),
  642. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  643. mock_git_resource:mock([]),
  644. mock_pkg_resource:mock([
  645. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  646. ]),
  647. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  648. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  649. {list_to_atom(PkgName), Vsn}
  650. ]}]),
  651. {ok, RConf} = file:consult(RConfFile),
  652. %% Build with deps.
  653. rebar_test_utils:run_and_check(
  654. Config, RConf, ["compile"],
  655. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  656. ),
  657. %% Build two checkout apps similar to dependencies to be fetched,
  658. %% but on a different version
  659. Vsn2 = rebar_test_utils:create_random_vsn(),
  660. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  661. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  662. %% Rebuild and make sure the checkout apps are in path
  663. code:set_path(StartPaths),
  664. {ok, State} = rebar_test_utils:run_and_check(
  665. Config, RConf, ["compile"],
  666. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  667. ),
  668. code:add_paths(rebar_state:code_paths(State, all_deps)),
  669. [DepPath] = [Path || Path <- code:get_path(),
  670. {match, _} <- [re:run(Path, DepName)]],
  671. [PkgPath] = [Path || Path <- code:get_path(),
  672. {match, _} <- [re:run(Path, PkgName)]],
  673. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  674. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  675. {application, _, DepProps} = DepApp,
  676. {application, _, PkgProps} = PkgApp,
  677. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  678. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  679. highest_version_of_pkg_dep(Config) ->
  680. AppDir = ?config(apps, Config),
  681. Name = rebar_test_utils:create_random_name("app1_"),
  682. Vsn = rebar_test_utils:create_random_vsn(),
  683. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  684. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  685. mock_git_resource:mock([]),
  686. mock_pkg_resource:mock([
  687. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  688. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  689. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  690. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  691. ]),
  692. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]),
  693. {ok, RConf} = file:consult(RConfFile),
  694. %% Build with deps.
  695. rebar_test_utils:run_and_check(
  696. Config, RConf, ["compile"],
  697. {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
  698. ).
  699. parse_transform_test(Config) ->
  700. AppDir = ?config(apps, Config),
  701. RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
  702. Name = rebar_test_utils:create_random_name("app1_"),
  703. Vsn = rebar_test_utils:create_random_vsn(),
  704. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  705. ExtraSrc = <<"-module(pascal). "
  706. "-export([parse_transform/2]). "
  707. "parse_transform(Forms, _Options) -> "
  708. "Forms.">>,
  709. ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
  710. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  711. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  712. true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).
  713. erl_first_files_test(Config) ->
  714. AppDir = ?config(apps, Config),
  715. RebarConfig = [{erl_opts, [{parse_transform, mark_time}]},
  716. {erl_first_files, ["src/mark_time.erl",
  717. "src/b.erl",
  718. "src/d.erl",
  719. "src/a.erl"]}],
  720. Name = rebar_test_utils:create_random_name("app1_"),
  721. Vsn = rebar_test_utils:create_random_vsn(),
  722. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  723. rebar_test_utils:write_src_file(AppDir, "a.erl"),
  724. rebar_test_utils:write_src_file(AppDir, "b.erl"),
  725. rebar_test_utils:write_src_file(AppDir, "d.erl"),
  726. rebar_test_utils:write_src_file(AppDir, "e.erl"),
  727. ExtraSrc = <<"-module(mark_time). "
  728. "-export([parse_transform/2]). "
  729. "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> "
  730. " [Form, {attribute,1,number, os:timestamp()} | Forms];"
  731. "parse_transform([Form|Forms], Options) -> "
  732. " [Form | parse_transform(Forms, Options)].">>,
  733. ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc),
  734. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  735. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  736. true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])),
  737. code:load_abs(filename:join([EbinDir, "a"])),
  738. code:load_abs(filename:join([EbinDir, "b"])),
  739. code:load_abs(filename:join([EbinDir, "d"])),
  740. code:load_abs(filename:join([EbinDir, "e"])),
  741. A = proplists:get_value(number, a:module_info(attributes)),
  742. B = proplists:get_value(number, b:module_info(attributes)),
  743. D = proplists:get_value(number, d:module_info(attributes)),
  744. E = proplists:get_value(number, e:module_info(attributes)),
  745. ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])).
  746. mib_test(Config) ->
  747. AppDir = ?config(apps, Config),
  748. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  749. Name = rebar_test_utils:create_random_name("app1_"),
  750. Vsn = rebar_test_utils:create_random_vsn(),
  751. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  752. MibsSrc = <<"-- SIMPLE-MIB.\n"
  753. "-- This is just a simple MIB used for testing!\n"
  754. "--\n"
  755. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  756. "IMPORTS\n"
  757. " MODULE-IDENTITY, enterprises\n"
  758. " FROM SNMPv2-SMI;\n"
  759. "\n"
  760. "ericsson MODULE-IDENTITY\n"
  761. " LAST-UPDATED\n"
  762. " \"201403060000Z\"\n"
  763. " ORGANIZATION\n"
  764. " \"rebar\"\n"
  765. " CONTACT-INFO\n"
  766. " \"rebar <rebar@example.com>\n"
  767. " or\n"
  768. " whoever is currently responsible for the SIMPLE\n"
  769. " enterprise MIB tree branch (enterprises.999).\"\n"
  770. " DESCRIPTION\n"
  771. " \"This very small module is made available\n"
  772. " for mib-compilation testing.\"\n"
  773. " ::= { enterprises 999 }\n"
  774. "END\n">>,
  775. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  776. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  777. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  778. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  779. PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  780. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  781. %% check a hrl corresponding to the mib in the mibs dir exists in include
  782. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  783. %% check the mibs dir was linked into the _build dir
  784. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])).
  785. umbrella_mib_first_test(Config) ->
  786. AppsDir = ?config(apps, Config),
  787. Name = rebar_test_utils:create_random_name("app1_"),
  788. Vsn = rebar_test_utils:create_random_vsn(),
  789. AppDir = filename:join([AppsDir, "apps", Name]),
  790. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  791. MibsSrc = <<"-- SIMPLE-MIB.\n"
  792. "-- This is just a simple MIB used for testing!\n"
  793. "--\n"
  794. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  795. "IMPORTS\n"
  796. " MODULE-IDENTITY, enterprises\n"
  797. " FROM SNMPv2-SMI;\n"
  798. "\n"
  799. "ericsson MODULE-IDENTITY\n"
  800. " LAST-UPDATED\n"
  801. " \"201403060000Z\"\n"
  802. " ORGANIZATION\n"
  803. " \"rebar\"\n"
  804. " CONTACT-INFO\n"
  805. " \"rebar <rebar@example.com>\n"
  806. " or\n"
  807. " whoever is currently responsible for the SIMPLE\n"
  808. " enterprise MIB tree branch (enterprises.999).\"\n"
  809. " DESCRIPTION\n"
  810. " \"This very small module is made available\n"
  811. " for mib-compilation testing.\"\n"
  812. " ::= { enterprises 999 }\n"
  813. "END\n">>,
  814. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  815. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  816. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  817. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  818. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  819. PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  820. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  821. %% check a hrl corresponding to the mib in the mibs dir exists in include
  822. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  823. %% check the mibs dir was linked into the _build dir
  824. true = filelib:is_dir(filename:join([AppsDir, "_build", "default", "lib", Name, "mibs"])).
  825. only_default_transitive_deps(Config) ->
  826. AppDir = ?config(apps, Config),
  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. GitDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]),
  831. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  832. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  833. mock_git_resource:mock([{deps, SrcDeps},
  834. {config, [{profiles, [{test, [{deps, [list_to_atom(PkgName)]}]}]}]}]),
  835. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  836. Deps = rebar_test_utils:top_level_deps(GitDeps),
  837. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  838. {ok, RConf} = file:consult(RConfFile),
  839. %% Build with deps.
  840. rebar_test_utils:run_and_check(
  841. Config, RConf, ["as", "test", "compile"],
  842. {ok, [{app, Name}, {dep, "a", <<"1.0.0">>}, {dep_not_exist, PkgName}]}
  843. ).
  844. clean_all(Config) ->
  845. AppDir = ?config(apps, Config),
  846. Name = rebar_test_utils:create_random_name("app1_"),
  847. Vsn = rebar_test_utils:create_random_vsn(),
  848. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  849. DepName = rebar_test_utils:create_random_name("dep1_"),
  850. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  851. mock_git_resource:mock([]),
  852. mock_pkg_resource:mock([
  853. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  854. ]),
  855. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  856. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  857. {list_to_atom(PkgName), Vsn}
  858. ]}]),
  859. {ok, RConf} = file:consult(RConfFile),
  860. %% Build things
  861. rebar_test_utils:run_and_check(
  862. Config, RConf, ["compile"],
  863. {ok, [{app, Name}, {app, DepName}, {app, PkgName}]}
  864. ),
  865. %% Clean all
  866. rebar_test_utils:run_and_check(Config, [], ["clean", "--all"],
  867. {ok, [{app, Name, invalid},
  868. {app, DepName, invalid},
  869. {app, PkgName, invalid}]}).
  870. override_deps(Config) ->
  871. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"},{other_dep, "0.0.1"}]}]),
  872. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  873. TopDeps = rebar_test_utils:top_level_deps(Deps),
  874. RebarConfig = [
  875. {deps, TopDeps},
  876. {overrides, [
  877. {override, some_dep, [
  878. {deps, []}
  879. ]}
  880. ]}
  881. ],
  882. rebar_test_utils:run_and_check(
  883. Config, RebarConfig, ["compile"],
  884. {ok, [{dep, "some_dep"},{dep_not_exist, "other_dep"}]}
  885. ).
  886. profile_override_deps(Config) ->
  887. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"},{other_dep, "0.0.1"}]}]),
  888. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  889. TopDeps = rebar_test_utils:top_level_deps(Deps),
  890. RebarConfig = [
  891. {deps, TopDeps},
  892. {profiles, [{a,
  893. [{overrides, [
  894. {override, some_dep, [
  895. {deps, []}
  896. ]}
  897. ]}
  898. ]}
  899. ]}],
  900. rebar_test_utils:run_and_check(
  901. Config, RebarConfig, ["as", "a", "compile"],
  902. {ok, [{dep, "some_dep"},{dep_not_exist, "other_dep"}]}
  903. ).
  904. %% verify a deps prod profile is used
  905. %% tested by checking prod hooks run and outputs to default profile dir for dep
  906. %% and prod deps are installed for dep
  907. deps_build_in_prod(Config) ->
  908. AppDir = ?config(apps, Config),
  909. Name = rebar_test_utils:create_random_name("app1_"),
  910. Vsn = rebar_test_utils:create_random_vsn(),
  911. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  912. GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]),
  913. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  914. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  915. mock_git_resource:mock([{deps, SrcDeps},
  916. {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]},
  917. {deps, [list_to_atom(PkgName)]}]}]}]}]),
  918. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  919. Deps = rebar_test_utils:top_level_deps(GitDeps),
  920. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  921. {ok, RConf} = file:consult(RConfFile),
  922. %% Build with deps.
  923. rebar_test_utils:run_and_check(
  924. Config, RConf, ["compile"],
  925. {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName},
  926. {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]}
  927. ).