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.

400 Zeilen
16 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
  1. -module(rebar_plugins_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. compile_plugins/1,
  9. compile_global_plugins/1,
  10. complex_plugins/1,
  11. list/1,
  12. upgrade/1,
  13. upgrade_project_plugin/1,
  14. sub_app_plugins/1,
  15. sub_app_plugin_overrides/1,
  16. project_plugins/1,
  17. use_checkout_plugins/1]).
  18. -include_lib("common_test/include/ct.hrl").
  19. -include_lib("eunit/include/eunit.hrl").
  20. -include_lib("kernel/include/file.hrl").
  21. suite() ->
  22. [].
  23. init_per_suite(Config) ->
  24. Config.
  25. end_per_suite(_Config) ->
  26. ok.
  27. init_per_testcase(_, Config) ->
  28. rebar_test_utils:init_rebar_state(Config).
  29. end_per_testcase(_, _Config) ->
  30. catch meck:unload().
  31. all() ->
  32. [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, upgrade_project_plugin,
  33. sub_app_plugins, sub_app_plugin_overrides, project_plugins, use_checkout_plugins].
  34. %% Tests that compiling a project installs and compiles the plugins of deps
  35. compile_plugins(Config) ->
  36. AppDir = ?config(apps, Config),
  37. Name = rebar_test_utils:create_random_name("app1_"),
  38. Vsn = rebar_test_utils:create_random_vsn(),
  39. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  40. DepName = rebar_test_utils:create_random_name("dep1_"),
  41. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  42. Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}]),
  43. {SrcDeps, _} = rebar_test_utils:flat_deps(Plugins),
  44. mock_git_resource:mock([{deps, SrcDeps}]),
  45. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
  46. {config, [{plugins, [
  47. {list_to_atom(PluginName),
  48. {git, "http://site.com/user/"++PluginName++".git",
  49. {tag, Vsn}}}]}]}]),
  50. RConfFile =
  51. rebar_test_utils:create_config(AppDir,
  52. [{deps, [
  53. list_to_atom(DepName)
  54. ]}]),
  55. {ok, RConf} = file:consult(RConfFile),
  56. %% Build with deps.
  57. rebar_test_utils:run_and_check(
  58. Config, RConf, ["compile"],
  59. {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]}
  60. ).
  61. %% Tests that compiling a project installs and compiles the global plugins
  62. compile_global_plugins(Config) ->
  63. AppDir = ?config(apps, Config),
  64. GlobalDir = filename:join(AppDir, "global"),
  65. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  66. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  67. meck:new(rebar_dir, [passthrough]),
  68. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  69. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  70. Name = rebar_test_utils:create_random_name("app1_"),
  71. Vsn = rebar_test_utils:create_random_vsn(),
  72. Vsn2 = rebar_test_utils:create_random_vsn(),
  73. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  74. DepName = rebar_test_utils:create_random_name("dep1_"),
  75. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  76. mock_git_resource:mock([{deps, [{list_to_atom(PluginName), Vsn},
  77. {list_to_atom(PluginName), Vsn2},
  78. {{iolist_to_binary(DepName), iolist_to_binary(Vsn)}, []}]}]),
  79. rebar_test_utils:create_config(GlobalConfigDir,
  80. [{plugins, [
  81. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn}}}
  82. ]}]),
  83. RConfFile =
  84. rebar_test_utils:create_config(AppDir,
  85. [{deps, [
  86. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  87. ]},
  88. {plugins, [
  89. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
  90. ]}]),
  91. {ok, RConf} = file:consult(RConfFile),
  92. %% Runs global plugin install
  93. rebar3:init_config(),
  94. %% Build with deps.
  95. rebar_test_utils:run_and_check(
  96. Config, RConf, ["compile"],
  97. {ok, [{app, Name},
  98. {global_plugin, PluginName, Vsn},
  99. {plugin, PluginName, Vsn2},
  100. {dep, DepName}]}
  101. ),
  102. meck:unload(rebar_dir).
  103. %% Tests installing of plugin with transitive deps
  104. complex_plugins(Config) ->
  105. AppDir = ?config(apps, Config),
  106. meck:new(rebar_dir, [passthrough]),
  107. Name = rebar_test_utils:create_random_name("app1_"),
  108. Vsn = rebar_test_utils:create_random_vsn(),
  109. Vsn2 = rebar_test_utils:create_random_vsn(),
  110. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  111. DepName = rebar_test_utils:create_random_name("dep1_"),
  112. DepName2 = rebar_test_utils:create_random_name("dep2_"),
  113. DepName3 = rebar_test_utils:create_random_name("dep3_"),
  114. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  115. Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn2, [{DepName2, Vsn,
  116. [{DepName3, Vsn, []}]}]}
  117. ,{DepName, Vsn, []}]),
  118. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  119. mock_git_resource:mock([{deps, SrcDeps}]),
  120. RConfFile =
  121. rebar_test_utils:create_config(AppDir,
  122. [{deps, [
  123. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  124. ]},
  125. {plugins, [
  126. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
  127. ]}]),
  128. {ok, RConf} = file:consult(RConfFile),
  129. %% Build with deps.
  130. rebar_test_utils:run_and_check(
  131. Config, RConf, ["compile"],
  132. {ok, [{app, Name},
  133. {plugin, PluginName, Vsn2},
  134. {plugin, DepName2},
  135. {plugin, DepName3},
  136. {dep, DepName}]}
  137. ),
  138. meck:unload(rebar_dir).
  139. list(Config) ->
  140. rebar_test_utils:run_and_check(
  141. Config, [], ["plugins", "list"],
  142. {ok, []}
  143. ).
  144. upgrade(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. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  150. mock_git_resource:mock([]),
  151. mock_pkg_resource:mock([
  152. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  153. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  154. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  155. ]),
  156. %% beam file to verify plugin is acutally compiled
  157. PluginBeam = filename:join([AppDir, "_build", "default", "plugins",
  158. PkgName, "ebin", [PkgName, ".beam"]]),
  159. RConfFile = rebar_test_utils:create_config(AppDir, [{plugins, [list_to_atom(PkgName)]}]),
  160. {ok, RConf} = file:consult(RConfFile),
  161. %% Build with deps.
  162. rebar_test_utils:run_and_check(
  163. Config, RConf, ["compile"],
  164. {ok, [{app, Name, valid}, {file, PluginBeam}, {plugin, PkgName, <<"0.1.1">>}]}
  165. ),
  166. catch mock_pkg_resource:unmock(),
  167. mock_pkg_resource:mock([
  168. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  169. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  170. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  171. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]},
  172. {upgrade, [PkgName]}
  173. ]),
  174. %% Build with deps.
  175. rebar_test_utils:run_and_check(
  176. Config, RConf, ["plugins", "upgrade", PkgName],
  177. {ok, [{app, Name, valid}, {file, PluginBeam}, {plugin, PkgName, <<"0.1.3">>}]}
  178. ).
  179. upgrade_project_plugin(Config) ->
  180. AppDir = ?config(apps, Config),
  181. Name = rebar_test_utils:create_random_name("app1_"),
  182. Vsn = rebar_test_utils:create_random_vsn(),
  183. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  184. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  185. mock_git_resource:mock([]),
  186. mock_pkg_resource:mock([
  187. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  188. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  189. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  190. ]),
  191. RConfFile = rebar_test_utils:create_config(AppDir, [{project_plugins, [list_to_atom(PkgName)]}]),
  192. {ok, RConf} = file:consult(RConfFile),
  193. %% Build with deps.
  194. rebar_test_utils:run_and_check(
  195. Config, RConf, ["compile"],
  196. {ok, [{app, Name}, {plugin, PkgName, <<"0.1.1">>}]}
  197. ),
  198. catch mock_pkg_resource:unmock(),
  199. mock_pkg_resource:mock([
  200. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  201. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  202. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  203. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]},
  204. {upgrade, [PkgName]}
  205. ]),
  206. %% Build with deps.
  207. rebar_test_utils:run_and_check(
  208. Config, RConf, ["plugins", "upgrade", PkgName],
  209. {ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]}
  210. ).
  211. sub_app_plugins(Config) ->
  212. AppDir = ?config(apps, Config),
  213. Name = rebar_test_utils:create_random_name("sub_app1_"),
  214. Vsn = rebar_test_utils:create_random_vsn(),
  215. DepName = rebar_test_utils:create_random_name("dep1_"),
  216. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  217. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []},
  218. {{list_to_binary(PluginName), list_to_binary(Vsn)}, []}]}]),
  219. SubAppsDir = filename:join([AppDir, "apps", Name]),
  220. rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
  221. rebar_test_utils:create_config(SubAppsDir, [{deps, [{list_to_binary(DepName), list_to_binary(Vsn)}]},
  222. {plugins, [list_to_atom(PluginName)]}]),
  223. RConfFile =
  224. rebar_test_utils:create_config(AppDir,
  225. [{deps, [
  226. list_to_atom(DepName)
  227. ]}]),
  228. {ok, RConf} = file:consult(RConfFile),
  229. %% Build with deps.
  230. rebar_test_utils:run_and_check(
  231. Config, RConf, ["compile"],
  232. {ok, [{app, Name}, {dep, DepName}, {plugin, PluginName}]}
  233. ).
  234. %% Tests that overrides in a dep that includes a plugin are applied to plugin fetching
  235. sub_app_plugin_overrides(Config) ->
  236. AppDir = ?config(apps, Config),
  237. Name = rebar_test_utils:create_random_name("sub_app1_"),
  238. Vsn = rebar_test_utils:create_random_vsn(),
  239. Dep2Name = rebar_test_utils:create_random_name("dep2_"),
  240. DepName = rebar_test_utils:create_random_name("dep1_"),
  241. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  242. Vsn2 = rebar_test_utils:create_random_vsn(),
  243. Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, [{DepName, Vsn, []}]},
  244. {DepName, Vsn, []}]),
  245. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  246. mock_git_resource:mock([{deps, SrcDeps}]),
  247. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(Dep2Name), list_to_binary(Vsn)}, []}]},
  248. {config, [{plugins, [{list_to_atom(PluginName),
  249. {git, "http://site.com/user/"++PluginName++".git",
  250. {tag, Vsn}}}]},
  251. %% Dep2 overrides the plugin's deps to have vsn2 of dep1
  252. {overrides, [{override, list_to_atom(PluginName),
  253. [{deps, [{list_to_atom(DepName),
  254. {git, "http://site.com/user/"++DepName++".git",
  255. {tag, Vsn2}}}]}]}]}]}]),
  256. SubAppsDir = filename:join([AppDir, "apps", Name]),
  257. rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
  258. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [{list_to_binary(Dep2Name), list_to_binary(Vsn)}]}]),
  259. {ok, RConf} = file:consult(RConfFile),
  260. %% Build with deps.
  261. rebar_test_utils:run_and_check(
  262. Config, RConf, ["compile"],
  263. {ok, [{app, Name}, {dep, Dep2Name, Vsn}, {plugin, DepName, Vsn2}, {plugin, PluginName}]}
  264. ).
  265. %% Check that project plugins are first in providers even if they override defaults but that
  266. %% normal plugins do not
  267. project_plugins(Config) ->
  268. AppDir = ?config(apps, Config),
  269. Name = rebar_test_utils:create_random_name("app1_"),
  270. Vsn = rebar_test_utils:create_random_vsn(),
  271. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  272. DepName = rebar_test_utils:create_random_name("dep1_"),
  273. PluginName = "compile_plugin",
  274. PluginName2 = "release",
  275. Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}, {PluginName2, Vsn, []}]),
  276. {SrcDeps, _} = rebar_test_utils:flat_deps(Plugins),
  277. mock_git_resource:mock([{deps, SrcDeps}], create_plugin),
  278. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
  279. {config, [{plugins, [
  280. {list_to_atom(PluginName),
  281. {git, "http://site.com/user/"++PluginName++".git",
  282. {tag, Vsn}}}]}]}]),
  283. RConfFile =
  284. rebar_test_utils:create_config(AppDir,
  285. [{deps, [
  286. list_to_atom(DepName)
  287. ]},
  288. {project_plugins, [
  289. {list_to_atom(PluginName2),
  290. {git, "http://site.com/user/"++PluginName2++".git",
  291. {tag, Vsn}}}]}]),
  292. {ok, RConf} = file:consult(RConfFile),
  293. %% Build with deps.
  294. {ok, State} = rebar_test_utils:run_and_check(
  295. Config, RConf, ["compile"],
  296. {ok, [{app, Name}, {plugin, PluginName}, {plugin, PluginName2}, {dep, DepName}]}
  297. ),
  298. %% Should have 2 release providers but only 1 compile provider
  299. Release = [P || P <- rebar_state:providers(State), providers:impl(P) =:= release, providers:namespace(P) =:= default],
  300. Compile = [P || P <- rebar_state:providers(State), providers:impl(P) =:= compile, providers:namespace(P) =:= default],
  301. ?assertEqual(length(Release), 2),
  302. ?assertEqual(length(Compile), 1).
  303. use_checkout_plugins(Config) ->
  304. AppDir = ?config(apps, Config),
  305. Name = rebar_test_utils:create_random_name("app1_"),
  306. Vsn = rebar_test_utils:create_random_vsn(),
  307. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  308. PluginName = "checkedout",
  309. CheckoutsDir = filename:join(AppDir, "_checkouts/checkedout"),
  310. rebar_test_utils:create_plugin(CheckoutsDir, PluginName, "1.0.0", []),
  311. RConfFile =
  312. rebar_test_utils:create_config(AppDir,
  313. [{deps, []},
  314. {plugins, [list_to_atom(PluginName)]}]),
  315. {ok, RConf} = file:consult(RConfFile),
  316. %% Verify we can run the plugin
  317. ?assertMatch({ok, _}, rebar_test_utils:run_and_check(
  318. Config, RConf, ["checkedout"],
  319. {ok, []}
  320. )).