Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

366 rindas
14 KiB

pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
  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_opts_change/1,
  14. dont_recompile_when_opts_dont_change/1,
  15. dont_recompile_yrl_or_xrl/1,
  16. deps_in_path/1,
  17. checkout_priority/1,
  18. compile_plugins/1]).
  19. -include_lib("common_test/include/ct.hrl").
  20. -include_lib("eunit/include/eunit.hrl").
  21. -include_lib("kernel/include/file.hrl").
  22. suite() ->
  23. [].
  24. init_per_suite(Config) ->
  25. Config.
  26. end_per_suite(_Config) ->
  27. ok.
  28. init_per_testcase(_, Config) ->
  29. rebar_test_utils:init_rebar_state(Config).
  30. end_per_testcase(_, _Config) ->
  31. catch meck:unload().
  32. all() ->
  33. [build_basic_app, build_release_apps,
  34. build_checkout_apps, build_checkout_deps,
  35. build_all_srcdirs,
  36. recompile_when_opts_change, dont_recompile_when_opts_dont_change,
  37. dont_recompile_yrl_or_xrl, deps_in_path, checkout_priority, compile_plugins].
  38. build_basic_app(Config) ->
  39. AppDir = ?config(apps, Config),
  40. Name = rebar_test_utils:create_random_name("app1_"),
  41. Vsn = rebar_test_utils:create_random_vsn(),
  42. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  43. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  44. build_release_apps(Config) ->
  45. AppDir = ?config(apps, Config),
  46. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  47. Vsn1 = rebar_test_utils:create_random_vsn(),
  48. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  49. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  50. Vsn2 = rebar_test_utils:create_random_vsn(),
  51. rebar_test_utils:create_app(filename:join([AppDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  52. rebar_test_utils:run_and_check(
  53. Config, [], ["compile"],
  54. {ok, [{app, Name1}, {app, Name2}]}
  55. ).
  56. build_checkout_apps(Config) ->
  57. AppDir = ?config(apps, Config),
  58. CheckoutsDir = ?config(checkouts, Config),
  59. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  60. Vsn1 = rebar_test_utils:create_random_vsn(),
  61. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  62. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  63. Vsn2 = rebar_test_utils:create_random_vsn(),
  64. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  65. rebar_test_utils:run_and_check(
  66. Config, [], ["compile"],
  67. {ok, [{app, Name1}, {checkout, Name2}]}
  68. ).
  69. build_checkout_deps(Config) ->
  70. AppDir = ?config(apps, Config),
  71. CheckoutsDir = ?config(checkouts, Config),
  72. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  73. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  74. Vsn1 = rebar_test_utils:create_random_vsn(),
  75. rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
  76. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  77. Vsn2 = rebar_test_utils:create_random_vsn(),
  78. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  79. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  80. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  81. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  82. rebar_test_utils:run_and_check(
  83. Config, RebarConfig, ["compile"],
  84. {ok, [{app, Name1}, {checkout, Name2}]}
  85. ),
  86. ok = application:load(list_to_atom(Name2)),
  87. Loaded = application:loaded_applications(),
  88. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  89. build_all_srcdirs(Config) ->
  90. AppDir = ?config(apps, Config),
  91. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  92. Name = rebar_test_utils:create_random_name("app1_"),
  93. Vsn = rebar_test_utils:create_random_vsn(),
  94. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  95. ExtraSrc = <<"-module(extra_src).\n"
  96. "-export([ok/0]).\n"
  97. "ok() -> ok.\n">>,
  98. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  99. ok = file:write_file(filename:join([AppDir, "extra", "extra_src.erl"]), ExtraSrc),
  100. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  101. %% check a beam corresponding to the src in the extra src_dir exists in ebin
  102. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  103. true = filelib:is_file(filename:join([EbinDir, "extra_src.beam"])),
  104. %% check the extra src_dir was linked into the _build dir
  105. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "extra"])).
  106. recompile_when_opts_change(Config) ->
  107. AppDir = ?config(apps, Config),
  108. Name = rebar_test_utils:create_random_name("app1_"),
  109. Vsn = rebar_test_utils:create_random_vsn(),
  110. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  111. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  112. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  113. {ok, Files} = file:list_dir(EbinDir),
  114. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  115. || F <- Files, filename:extension(F) == ".beam"],
  116. timer:sleep(1000),
  117. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  118. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  119. {ok, NewFiles} = file:list_dir(EbinDir),
  120. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  121. || F <- NewFiles, filename:extension(F) == ".beam"],
  122. ?assert(ModTime =/= NewModTime).
  123. dont_recompile_when_opts_dont_change(Config) ->
  124. AppDir = ?config(apps, Config),
  125. Name = rebar_test_utils:create_random_name("app1_"),
  126. Vsn = rebar_test_utils:create_random_vsn(),
  127. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  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. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  135. {ok, NewFiles} = file:list_dir(EbinDir),
  136. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  137. || F <- NewFiles, filename:extension(F) == ".beam"],
  138. ?assert(ModTime == NewModTime).
  139. dont_recompile_yrl_or_xrl(Config) ->
  140. AppDir = ?config(apps, Config),
  141. Name = rebar_test_utils:create_random_name("app1_"),
  142. Vsn = rebar_test_utils:create_random_vsn(),
  143. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  144. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  145. ok = filelib:ensure_dir(Xrl),
  146. XrlBody =
  147. "Definitions."
  148. "\n\n"
  149. "D = [0-9]"
  150. "\n\n"
  151. "Rules."
  152. "\n\n"
  153. "{D}+ :"
  154. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  155. "\n\n"
  156. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  157. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  158. "\n\n"
  159. "Erlang code.",
  160. ok = ec_file:write(Xrl, XrlBody),
  161. XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]),
  162. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  163. ModTime = filelib:last_modified(XrlBeam),
  164. timer:sleep(1000),
  165. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  166. NewModTime = filelib:last_modified(XrlBeam),
  167. ?assert(ModTime == NewModTime).
  168. deps_in_path(Config) ->
  169. AppDir = ?config(apps, Config),
  170. StartPaths = code:get_path(),
  171. Name = rebar_test_utils:create_random_name("app1_"),
  172. Vsn = rebar_test_utils:create_random_vsn(),
  173. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  174. DepName = rebar_test_utils:create_random_name("dep1_"),
  175. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  176. mock_git_resource:mock([]),
  177. mock_pkg_resource:mock([
  178. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  179. ]),
  180. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  181. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  182. {list_to_atom(PkgName), Vsn}
  183. ]}]),
  184. {ok, RConf} = file:consult(RConfFile),
  185. %% Make sure apps we look for are not visible
  186. %% Hope not to find src name
  187. ?assertEqual([], [Path || Path <- code:get_path(),
  188. {match, _} <- [re:run(Path, DepName)]]),
  189. %% Hope not to find pkg name in there
  190. ?assertEqual([], [Path || Path <- code:get_path(),
  191. {match, _} <- [re:run(Path, PkgName)]]),
  192. %% Build things
  193. rebar_test_utils:run_and_check(
  194. Config, RConf, ["compile"],
  195. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  196. ),
  197. %% Find src name in there
  198. ?assertNotEqual([], [Path || Path <- code:get_path(),
  199. {match, _} <- [re:run(Path, DepName)]]),
  200. %% find pkg name in there
  201. ?assertNotEqual([], [Path || Path <- code:get_path(),
  202. {match, _} <- [re:run(Path, PkgName)]]),
  203. code:set_path(StartPaths),
  204. %% Make sure apps we look for are not visible again
  205. %% Hope not to find src name
  206. ?assertEqual([], [Path || Path <- code:get_path(),
  207. {match, _} <- [re:run(Path, DepName)]]),
  208. %% Hope not to find pkg name in there
  209. ?assertEqual([], [Path || Path <- code:get_path(),
  210. {match, _} <- [re:run(Path, PkgName)]]),
  211. %% Rebuild
  212. rebar_test_utils:run_and_check(
  213. Config, RConf, ["compile"],
  214. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  215. ),
  216. %% Find src name in there
  217. ?assertNotEqual([], [Path || Path <- code:get_path(),
  218. {match, _} <- [re:run(Path, DepName)]]),
  219. %% find pkg name in there
  220. ?assertNotEqual([], [Path || Path <- code:get_path(),
  221. {match, _} <- [re:run(Path, PkgName)]]).
  222. checkout_priority(Config) ->
  223. AppDir = ?config(apps, Config),
  224. CheckoutsDir = ?config(checkouts, Config),
  225. StartPaths = code:get_path(),
  226. Name = rebar_test_utils:create_random_name("app1_"),
  227. Vsn = rebar_test_utils:create_random_vsn(),
  228. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  229. DepName = rebar_test_utils:create_random_name("dep1_"),
  230. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  231. mock_git_resource:mock([]),
  232. mock_pkg_resource:mock([
  233. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  234. ]),
  235. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  236. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  237. {list_to_atom(PkgName), Vsn}
  238. ]}]),
  239. {ok, RConf} = file:consult(RConfFile),
  240. %% Build with deps.
  241. rebar_test_utils:run_and_check(
  242. Config, RConf, ["compile"],
  243. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  244. ),
  245. %% Build two checkout apps similar to dependencies to be fetched,
  246. %% but on a different version
  247. Vsn2 = rebar_test_utils:create_random_vsn(),
  248. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  249. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  250. %% Rebuild and make sure the checkout apps are in path
  251. code:set_path(StartPaths),
  252. rebar_test_utils:run_and_check(
  253. Config, RConf, ["compile"],
  254. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  255. ),
  256. [DepPath] = [Path || Path <- code:get_path(),
  257. {match, _} <- [re:run(Path, DepName)]],
  258. [PkgPath] = [Path || Path <- code:get_path(),
  259. {match, _} <- [re:run(Path, PkgName)]],
  260. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  261. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  262. {application, _, DepProps} = DepApp,
  263. {application, _, PkgProps} = PkgApp,
  264. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  265. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  266. %% Tests that compiling a project installs and compiles the plugins of deps
  267. compile_plugins(Config) ->
  268. AppDir = ?config(apps, Config),
  269. PluginsDir = filename:join([?config(base_dir, Config), "default", "plugins"]),
  270. Name = rebar_test_utils:create_random_name("app1_"),
  271. Vsn = rebar_test_utils:create_random_vsn(),
  272. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  273. DepName = rebar_test_utils:create_random_name("dep1_"),
  274. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  275. mock_git_resource:mock([{config, [{plugins, [
  276. {list_to_atom(PluginName), Vsn}
  277. ]}]}]),
  278. mock_pkg_resource:mock([
  279. {pkgdeps, [{{iolist_to_binary(PluginName), iolist_to_binary(Vsn)}, []}]}
  280. ]),
  281. RConfFile =
  282. rebar_test_utils:create_config(AppDir,
  283. [{deps, [
  284. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  285. ]}]),
  286. {ok, RConf} = file:consult(RConfFile),
  287. %% Build with deps.
  288. rebar_test_utils:run_and_check(
  289. Config, RConf, ["compile"],
  290. {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]}
  291. ).