Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

201 строка
7.6 KiB

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