Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

210 rader
7.8 KiB

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