您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

592 行
23 KiB

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