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.

242 lines
9.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  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. sub_app_plugins/1]).
  14. -include_lib("common_test/include/ct.hrl").
  15. -include_lib("eunit/include/eunit.hrl").
  16. -include_lib("kernel/include/file.hrl").
  17. suite() ->
  18. [].
  19. init_per_suite(Config) ->
  20. Config.
  21. end_per_suite(_Config) ->
  22. ok.
  23. init_per_testcase(_, Config) ->
  24. rebar_test_utils:init_rebar_state(Config).
  25. end_per_testcase(_, _Config) ->
  26. catch meck:unload().
  27. all() ->
  28. [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins].
  29. %% Tests that compiling a project installs and compiles the plugins of deps
  30. compile_plugins(Config) ->
  31. AppDir = ?config(apps, Config),
  32. Name = rebar_test_utils:create_random_name("app1_"),
  33. Vsn = rebar_test_utils:create_random_vsn(),
  34. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  35. DepName = rebar_test_utils:create_random_name("dep1_"),
  36. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  37. Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}]),
  38. {SrcDeps, _} = rebar_test_utils:flat_deps(Plugins),
  39. mock_git_resource:mock([{deps, SrcDeps}]),
  40. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
  41. {config, [{plugins, [
  42. {list_to_atom(PluginName),
  43. {git, "http://site.com/user/"++PluginName++".git",
  44. {tag, Vsn}}}]}]}]),
  45. RConfFile =
  46. rebar_test_utils:create_config(AppDir,
  47. [{deps, [
  48. list_to_atom(DepName)
  49. ]}]),
  50. {ok, RConf} = file:consult(RConfFile),
  51. %% Build with deps.
  52. rebar_test_utils:run_and_check(
  53. Config, RConf, ["compile"],
  54. {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]}
  55. ).
  56. %% Tests that compiling a project installs and compiles the global plugins
  57. compile_global_plugins(Config) ->
  58. AppDir = ?config(apps, Config),
  59. GlobalDir = filename:join(AppDir, "global"),
  60. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  61. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  62. meck:new(rebar_dir, [passthrough]),
  63. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  64. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  65. Name = rebar_test_utils:create_random_name("app1_"),
  66. Vsn = rebar_test_utils:create_random_vsn(),
  67. Vsn2 = rebar_test_utils:create_random_vsn(),
  68. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  69. DepName = rebar_test_utils:create_random_name("dep1_"),
  70. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  71. mock_git_resource:mock([{deps, [{list_to_atom(PluginName), Vsn},
  72. {list_to_atom(PluginName), Vsn2},
  73. {{iolist_to_binary(DepName), iolist_to_binary(Vsn)}, []}]}]),
  74. rebar_test_utils:create_config(GlobalConfigDir,
  75. [{plugins, [
  76. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn}}}
  77. ]}]),
  78. RConfFile =
  79. rebar_test_utils:create_config(AppDir,
  80. [{deps, [
  81. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  82. ]},
  83. {plugins, [
  84. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
  85. ]}]),
  86. {ok, RConf} = file:consult(RConfFile),
  87. %% Runs global plugin install
  88. rebar3:init_config(),
  89. %% Build with deps.
  90. rebar_test_utils:run_and_check(
  91. Config, RConf, ["compile"],
  92. {ok, [{app, Name},
  93. {global_plugin, PluginName, Vsn},
  94. {plugin, PluginName, Vsn2},
  95. {dep, DepName}]}
  96. ),
  97. meck:unload(rebar_dir).
  98. %% Tests installing of plugin with transitive deps
  99. complex_plugins(Config) ->
  100. AppDir = ?config(apps, Config),
  101. meck:new(rebar_dir, [passthrough]),
  102. Name = rebar_test_utils:create_random_name("app1_"),
  103. Vsn = rebar_test_utils:create_random_vsn(),
  104. Vsn2 = rebar_test_utils:create_random_vsn(),
  105. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  106. DepName = rebar_test_utils:create_random_name("dep1_"),
  107. DepName2 = rebar_test_utils:create_random_name("dep2_"),
  108. DepName3 = rebar_test_utils:create_random_name("dep3_"),
  109. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  110. Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn2, [{DepName2, Vsn,
  111. [{DepName3, Vsn, []}]}]}
  112. ,{DepName, Vsn, []}]),
  113. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  114. mock_git_resource:mock([{deps, SrcDeps}]),
  115. RConfFile =
  116. rebar_test_utils:create_config(AppDir,
  117. [{deps, [
  118. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
  119. ]},
  120. {plugins, [
  121. {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
  122. ]}]),
  123. {ok, RConf} = file:consult(RConfFile),
  124. %% Build with deps.
  125. rebar_test_utils:run_and_check(
  126. Config, RConf, ["compile"],
  127. {ok, [{app, Name},
  128. {plugin, PluginName, Vsn2},
  129. {plugin, DepName2},
  130. {plugin, DepName3},
  131. {dep, DepName}]}
  132. ),
  133. meck:unload(rebar_dir).
  134. list(Config) ->
  135. rebar_test_utils:run_and_check(
  136. Config, [], ["plugins", "list"],
  137. {ok, []}
  138. ).
  139. upgrade(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. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  145. mock_git_resource:mock([]),
  146. mock_pkg_resource:mock([
  147. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  148. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  149. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  150. ]),
  151. RConfFile = rebar_test_utils:create_config(AppDir, [{plugins, [list_to_atom(PkgName)]}]),
  152. {ok, RConf} = file:consult(RConfFile),
  153. %% Build with deps.
  154. rebar_test_utils:run_and_check(
  155. Config, RConf, ["compile"],
  156. {ok, [{app, Name}, {plugin, PkgName, <<"0.1.1">>}]}
  157. ),
  158. catch mock_pkg_resource:unmock(),
  159. mock_pkg_resource:mock([
  160. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  161. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  162. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  163. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]},
  164. {upgrade, [PkgName]}
  165. ]),
  166. %% Build with deps.
  167. rebar_test_utils:run_and_check(
  168. Config, RConf, ["plugins", "upgrade", PkgName],
  169. {ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]}
  170. ).
  171. sub_app_plugins(Config) ->
  172. AppDir = ?config(apps, Config),
  173. Name = rebar_test_utils:create_random_name("sub_app1_"),
  174. Vsn = rebar_test_utils:create_random_vsn(),
  175. DepName = rebar_test_utils:create_random_name("dep1_"),
  176. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  177. mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []},
  178. {{list_to_binary(PluginName), list_to_binary(Vsn)}, []}]}]),
  179. SubAppsDir = filename:join([AppDir, "apps", Name]),
  180. rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
  181. rebar_test_utils:create_config(SubAppsDir, [{deps, [{list_to_binary(DepName), list_to_binary(Vsn)}]},
  182. {plugins, [list_to_atom(PluginName)]}]),
  183. RConfFile =
  184. rebar_test_utils:create_config(AppDir,
  185. [{deps, [
  186. list_to_atom(DepName)
  187. ]}]),
  188. {ok, RConf} = file:consult(RConfFile),
  189. %% Build with deps.
  190. rebar_test_utils:run_and_check(
  191. Config, RConf, ["compile"],
  192. {ok, [{app, Name}, {dep, DepName}, {plugin, PluginName}]}
  193. ).