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.

633 lines
24 KiB

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