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.

574 regels
23 KiB

10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
  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. all/0,
  8. build_basic_app/1,
  9. build_release_apps/1,
  10. build_checkout_apps/1,
  11. build_checkout_deps/1,
  12. build_all_srcdirs/1,
  13. recompile_when_hrl_changes/1,
  14. recompile_when_opts_change/1,
  15. dont_recompile_when_opts_dont_change/1,
  16. dont_recompile_yrl_or_xrl/1,
  17. deps_in_path/1,
  18. delete_beam_if_source_deleted/1,
  19. checkout_priority/1,
  20. compile_plugins/1,
  21. compile_global_plugins/1,
  22. complex_plugins/1,
  23. highest_version_of_pkg_dep/1,
  24. parse_transform_test/1]).
  25. -include_lib("common_test/include/ct.hrl").
  26. -include_lib("eunit/include/eunit.hrl").
  27. -include_lib("kernel/include/file.hrl").
  28. suite() ->
  29. [].
  30. init_per_suite(Config) ->
  31. Config.
  32. end_per_suite(_Config) ->
  33. ok.
  34. init_per_testcase(_, Config) ->
  35. rebar_test_utils:init_rebar_state(Config).
  36. end_per_testcase(_, _Config) ->
  37. catch meck:unload().
  38. all() ->
  39. [build_basic_app, build_release_apps,
  40. build_checkout_apps, build_checkout_deps,
  41. build_all_srcdirs, recompile_when_hrl_changes,
  42. recompile_when_opts_change, dont_recompile_when_opts_dont_change,
  43. dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted,
  44. deps_in_path, checkout_priority, compile_plugins, compile_global_plugins,
  45. complex_plugins, highest_version_of_pkg_dep, parse_transform_test].
  46. build_basic_app(Config) ->
  47. AppDir = ?config(apps, Config),
  48. Name = rebar_test_utils:create_random_name("app1_"),
  49. Vsn = rebar_test_utils:create_random_vsn(),
  50. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  51. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  52. build_release_apps(Config) ->
  53. AppDir = ?config(apps, Config),
  54. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  55. Vsn1 = rebar_test_utils:create_random_vsn(),
  56. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  57. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  58. Vsn2 = rebar_test_utils:create_random_vsn(),
  59. rebar_test_utils:create_app(filename:join([AppDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  60. rebar_test_utils:run_and_check(
  61. Config, [], ["compile"],
  62. {ok, [{app, Name1}, {app, Name2}]}
  63. ).
  64. build_checkout_apps(Config) ->
  65. AppDir = ?config(apps, Config),
  66. CheckoutsDir = ?config(checkouts, Config),
  67. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  68. Vsn1 = rebar_test_utils:create_random_vsn(),
  69. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  70. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  71. Vsn2 = rebar_test_utils:create_random_vsn(),
  72. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  73. rebar_test_utils:run_and_check(
  74. Config, [], ["compile"],
  75. {ok, [{app, Name1}, {checkout, Name2}]}
  76. ).
  77. build_checkout_deps(Config) ->
  78. AppDir = ?config(apps, Config),
  79. CheckoutsDir = ?config(checkouts, Config),
  80. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  81. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  82. Vsn1 = rebar_test_utils:create_random_vsn(),
  83. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  84. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  85. Vsn2 = rebar_test_utils:create_random_vsn(),
  86. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  87. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  88. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  89. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  90. {ok, State} = rebar_test_utils:run_and_check(
  91. Config, RebarConfig, ["compile"],
  92. {ok, [{app, Name1}, {checkout, Name2}]}
  93. ),
  94. code:add_paths(rebar_state:code_paths(State, all_deps)),
  95. ok = application:load(list_to_atom(Name2)),
  96. Loaded = application:loaded_applications(),
  97. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  98. build_all_srcdirs(Config) ->
  99. AppDir = ?config(apps, Config),
  100. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  101. Name = rebar_test_utils:create_random_name("app1_"),
  102. Vsn = rebar_test_utils:create_random_vsn(),
  103. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  104. ExtraSrc = <<"-module(extra_src).\n"
  105. "-export([ok/0]).\n"
  106. "ok() -> ok.\n">>,
  107. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  108. ok = file:write_file(filename:join([AppDir, "extra", "extra_src.erl"]), ExtraSrc),
  109. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  110. %% check a beam corresponding to the src in the extra src_dir exists in ebin
  111. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  112. true = filelib:is_file(filename:join([EbinDir, "extra_src.beam"])),
  113. %% check the extra src_dir was linked into the _build dir
  114. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "extra"])).
  115. recompile_when_hrl_changes(Config) ->
  116. AppDir = ?config(apps, Config),
  117. Name = rebar_test_utils:create_random_name("app1_"),
  118. Vsn = rebar_test_utils:create_random_vsn(),
  119. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  120. ExtraSrc = <<"-module(test_header_include).\n"
  121. "-export([main/0]).\n"
  122. "-include(\"test_header_include.hrl\").\n"
  123. "main() -> ?SOME_DEFINE.\n">>,
  124. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  125. HeaderFile = filename:join([AppDir, "src", "test_header_include.hrl"]),
  126. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  127. ok = file:write_file(HeaderFile, ExtraHeader),
  128. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  129. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  130. {ok, Files} = file:list_dir(EbinDir),
  131. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  132. || F <- Files, filename:extension(F) == ".beam"],
  133. timer:sleep(1000),
  134. os:cmd("touch " ++ HeaderFile),
  135. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  136. {ok, NewFiles} = file:list_dir(EbinDir),
  137. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  138. || F <- NewFiles, filename:extension(F) == ".beam"],
  139. ?assert(ModTime =/= NewModTime).
  140. recompile_when_opts_change(Config) ->
  141. AppDir = ?config(apps, Config),
  142. Name = rebar_test_utils:create_random_name("app1_"),
  143. Vsn = rebar_test_utils:create_random_vsn(),
  144. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  145. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  146. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  147. {ok, Files} = file:list_dir(EbinDir),
  148. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  149. || F <- Files, filename:extension(F) == ".beam"],
  150. timer:sleep(1000),
  151. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  152. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  153. {ok, NewFiles} = file:list_dir(EbinDir),
  154. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  155. || F <- NewFiles, filename:extension(F) == ".beam"],
  156. ?assert(ModTime =/= NewModTime).
  157. dont_recompile_when_opts_dont_change(Config) ->
  158. AppDir = ?config(apps, Config),
  159. Name = rebar_test_utils:create_random_name("app1_"),
  160. Vsn = rebar_test_utils:create_random_vsn(),
  161. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  162. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  163. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  164. {ok, Files} = file:list_dir(EbinDir),
  165. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  166. || F <- Files, filename:extension(F) == ".beam"],
  167. timer:sleep(1000),
  168. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  169. {ok, NewFiles} = file:list_dir(EbinDir),
  170. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  171. || F <- NewFiles, filename:extension(F) == ".beam"],
  172. ?assert(ModTime == NewModTime).
  173. dont_recompile_yrl_or_xrl(Config) ->
  174. AppDir = ?config(apps, Config),
  175. Name = rebar_test_utils:create_random_name("app1_"),
  176. Vsn = rebar_test_utils:create_random_vsn(),
  177. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  178. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  179. ok = filelib:ensure_dir(Xrl),
  180. XrlBody =
  181. "Definitions."
  182. "\n\n"
  183. "D = [0-9]"
  184. "\n\n"
  185. "Rules."
  186. "\n\n"
  187. "{D}+ :"
  188. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  189. "\n\n"
  190. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  191. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  192. "\n\n"
  193. "Erlang code.",
  194. ok = ec_file:write(Xrl, XrlBody),
  195. XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]),
  196. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  197. ModTime = filelib:last_modified(XrlBeam),
  198. timer:sleep(1000),
  199. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  200. NewModTime = filelib:last_modified(XrlBeam),
  201. ?assert(ModTime == NewModTime).
  202. delete_beam_if_source_deleted(Config) ->
  203. AppDir = ?config(apps, Config),
  204. Name = rebar_test_utils:create_random_name("app1_"),
  205. Vsn = rebar_test_utils:create_random_vsn(),
  206. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  207. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  208. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  209. SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]),
  210. ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))),
  211. file:delete(filename:join(SrcDir, "not_a_real_src_" ++ Name ++ ".erl")),
  212. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  213. ?assertNot(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))).
  214. deps_in_path(Config) ->
  215. AppDir = ?config(apps, Config),
  216. StartPaths = code:get_path(),
  217. Name = rebar_test_utils:create_random_name("app1_"),
  218. Vsn = rebar_test_utils:create_random_vsn(),
  219. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  220. DepName = rebar_test_utils:create_random_name("dep1_"),
  221. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  222. mock_git_resource:mock([]),
  223. mock_pkg_resource:mock([
  224. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  225. ]),
  226. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  227. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  228. {list_to_atom(PkgName), Vsn}
  229. ]}]),
  230. {ok, RConf} = file:consult(RConfFile),
  231. %% Make sure apps we look for are not visible
  232. %% Hope not to find src name
  233. ?assertEqual([], [Path || Path <- code:get_path(),
  234. {match, _} <- [re:run(Path, DepName)]]),
  235. %% Hope not to find pkg name in there
  236. ?assertEqual([], [Path || Path <- code:get_path(),
  237. {match, _} <- [re:run(Path, PkgName)]]),
  238. %% Build things
  239. {ok, State} = rebar_test_utils:run_and_check(
  240. Config, RConf, ["compile"],
  241. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  242. ),
  243. code:add_paths(rebar_state:code_paths(State, all_deps)),
  244. %% Find src name in there
  245. ?assertNotEqual([], [Path || Path <- code:get_path(),
  246. {match, _} <- [re:run(Path, DepName)]]),
  247. %% find pkg name in there
  248. ?assertNotEqual([], [Path || Path <- code:get_path(),
  249. {match, _} <- [re:run(Path, PkgName)]]),
  250. code:set_path(StartPaths),
  251. %% Make sure apps we look for are not visible again
  252. %% Hope not to find src name
  253. ?assertEqual([], [Path || Path <- code:get_path(),
  254. {match, _} <- [re:run(Path, DepName)]]),
  255. %% Hope not to find pkg name in there
  256. ?assertEqual([], [Path || Path <- code:get_path(),
  257. {match, _} <- [re:run(Path, PkgName)]]),
  258. %% Rebuild
  259. {ok, State1} = rebar_test_utils:run_and_check(
  260. Config, RConf, ["compile"],
  261. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  262. ),
  263. %% Find src name in there
  264. code:add_paths(rebar_state:code_paths(State1, all_deps)),
  265. ?assertNotEqual([], [Path || Path <- code:get_path(),
  266. {match, _} <- [re:run(Path, DepName)]]),
  267. %% find pkg name in there
  268. ?assertNotEqual([], [Path || Path <- code:get_path(),
  269. {match, _} <- [re:run(Path, PkgName)]]).
  270. checkout_priority(Config) ->
  271. AppDir = ?config(apps, Config),
  272. CheckoutsDir = ?config(checkouts, Config),
  273. StartPaths = code:get_path(),
  274. Name = rebar_test_utils:create_random_name("app1_"),
  275. Vsn = rebar_test_utils:create_random_vsn(),
  276. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  277. DepName = rebar_test_utils:create_random_name("dep1_"),
  278. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  279. mock_git_resource:mock([]),
  280. mock_pkg_resource:mock([
  281. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  282. ]),
  283. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  284. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  285. {list_to_atom(PkgName), Vsn}
  286. ]}]),
  287. {ok, RConf} = file:consult(RConfFile),
  288. %% Build with deps.
  289. rebar_test_utils:run_and_check(
  290. Config, RConf, ["compile"],
  291. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  292. ),
  293. %% Build two checkout apps similar to dependencies to be fetched,
  294. %% but on a different version
  295. Vsn2 = rebar_test_utils:create_random_vsn(),
  296. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  297. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  298. %% Rebuild and make sure the checkout apps are in path
  299. code:set_path(StartPaths),
  300. {ok, State} = rebar_test_utils:run_and_check(
  301. Config, RConf, ["compile"],
  302. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  303. ),
  304. code:add_paths(rebar_state:code_paths(State, all_deps)),
  305. [DepPath] = [Path || Path <- code:get_path(),
  306. {match, _} <- [re:run(Path, DepName)]],
  307. [PkgPath] = [Path || Path <- code:get_path(),
  308. {match, _} <- [re:run(Path, PkgName)]],
  309. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  310. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  311. {application, _, DepProps} = DepApp,
  312. {application, _, PkgProps} = PkgApp,
  313. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  314. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  315. %% Tests that compiling a project installs and compiles the plugins of deps
  316. compile_plugins(Config) ->
  317. AppDir = ?config(apps, Config),
  318. Name = rebar_test_utils:create_random_name("app1_"),
  319. Vsn = rebar_test_utils:create_random_vsn(),
  320. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  321. DepName = rebar_test_utils:create_random_name("dep1_"),
  322. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  323. Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}]),
  324. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Plugins)}]),
  325. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
  326. {config, [{plugins, [
  327. {list_to_atom(PluginName),
  328. {git, "http://site.com/user/"++PluginName++".git",
  329. {tag, Vsn}}}]}]}]),
  330. RConfFile =
  331. rebar_test_utils:create_config(AppDir,
  332. [{deps, [
  333. list_to_atom(DepName)
  334. ]}]),
  335. {ok, RConf} = file:consult(RConfFile),
  336. %% Build with deps.
  337. rebar_test_utils:run_and_check(
  338. Config, RConf, ["compile"],
  339. {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]}
  340. ).
  341. %% Tests that compiling a project installs and compiles the global plugins
  342. compile_global_plugins(Config) ->
  343. AppDir = ?config(apps, Config),
  344. GlobalDir = filename:join(AppDir, "global"),
  345. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  346. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  347. meck:new(rebar_dir, [passthrough]),
  348. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  349. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  350. Name = rebar_test_utils:create_random_name("app1_"),
  351. Vsn = rebar_test_utils:create_random_vsn(),
  352. Vsn2 = rebar_test_utils:create_random_vsn(),
  353. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  354. DepName = rebar_test_utils:create_random_name("dep1_"),
  355. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  356. mock_git_resource:mock([{deps, [{list_to_atom(PluginName), Vsn},
  357. {list_to_atom(PluginName), Vsn2},
  358. {{iolist_to_binary(DepName), iolist_to_binary(Vsn)}, []}]}]),
  359. rebar_test_utils:create_config(GlobalConfigDir,
  360. [{plugins, [
  361. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn}}}
  362. ]}]),
  363. RConfFile =
  364. rebar_test_utils:create_config(AppDir,
  365. [{deps, [
  366. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  367. ]},
  368. {plugins, [
  369. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
  370. ]}]),
  371. {ok, RConf} = file:consult(RConfFile),
  372. %% Runs global plugin install
  373. rebar3:init_config(),
  374. %% Build with deps.
  375. rebar_test_utils:run_and_check(
  376. Config, RConf, ["compile"],
  377. {ok, [{app, Name},
  378. {global_plugin, PluginName, Vsn},
  379. {plugin, PluginName, Vsn2},
  380. {dep, DepName}]}
  381. ),
  382. meck:unload(rebar_dir).
  383. %% Tests installing of plugin with transitive deps
  384. complex_plugins(Config) ->
  385. AppDir = ?config(apps, Config),
  386. meck:new(rebar_dir, [passthrough]),
  387. Name = rebar_test_utils:create_random_name("app1_"),
  388. Vsn = rebar_test_utils:create_random_vsn(),
  389. Vsn2 = rebar_test_utils:create_random_vsn(),
  390. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  391. DepName = rebar_test_utils:create_random_name("dep1_"),
  392. DepName2 = rebar_test_utils:create_random_name("dep2_"),
  393. DepName3 = rebar_test_utils:create_random_name("dep3_"),
  394. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  395. Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn2, [{DepName2, Vsn,
  396. [{DepName3, Vsn, []}]}]}
  397. ,{DepName, Vsn, []}]),
  398. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]),
  399. RConfFile =
  400. rebar_test_utils:create_config(AppDir,
  401. [{deps, [
  402. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  403. ]},
  404. {plugins, [
  405. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
  406. ]}]),
  407. {ok, RConf} = file:consult(RConfFile),
  408. %% Build with deps.
  409. rebar_test_utils:run_and_check(
  410. Config, RConf, ["compile"],
  411. {ok, [{app, Name},
  412. {plugin, PluginName, Vsn2},
  413. {plugin, DepName2},
  414. {plugin, DepName3},
  415. {dep, DepName}]}
  416. ),
  417. meck:unload(rebar_dir).
  418. highest_version_of_pkg_dep(Config) ->
  419. AppDir = ?config(apps, Config),
  420. Name = rebar_test_utils:create_random_name("app1_"),
  421. Vsn = rebar_test_utils:create_random_vsn(),
  422. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  423. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  424. mock_git_resource:mock([]),
  425. mock_pkg_resource:mock([
  426. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  427. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  428. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  429. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  430. ]),
  431. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]),
  432. {ok, RConf} = file:consult(RConfFile),
  433. %% Build with deps.
  434. rebar_test_utils:run_and_check(
  435. Config, RConf, ["compile"],
  436. {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
  437. ).
  438. parse_transform_test(Config) ->
  439. AppDir = ?config(apps, Config),
  440. RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
  441. Name = rebar_test_utils:create_random_name("app1_"),
  442. Vsn = rebar_test_utils:create_random_vsn(),
  443. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  444. ExtraSrc = <<"-module(pascal). "
  445. "-export([parse_transform/2]). "
  446. "parse_transform(Forms, _Options) -> "
  447. "Forms.">>,
  448. ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
  449. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  450. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  451. true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).