Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1175 Zeilen
47 KiB

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