No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

203 líneas
7.6 KiB

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