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.

129 lines
4.7 KiB

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
  1. -module(rebar_hooks_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. build_and_clean_app/1,
  9. escriptize_artifacts/1,
  10. run_hooks_once/1,
  11. run_hooks_for_plugins/1,
  12. deps_hook_namespace/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. meck:unload().
  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. [build_and_clean_app, run_hooks_once, escriptize_artifacts,
  28. run_hooks_for_plugins, deps_hook_namespace].
  29. %% Test post provider hook cleans compiled project app, leaving it invalid
  30. build_and_clean_app(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. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name, valid}]}),
  36. rebar_test_utils:run_and_check(Config, [{provider_hooks, [{post, [{compile, clean}]}]}],
  37. ["compile"], {ok, [{app, Name, invalid}]}).
  38. escriptize_artifacts(Config) ->
  39. AppDir = ?config(apps, Config),
  40. Name = rebar_test_utils:create_random_name("app1_"),
  41. Vsn = rebar_test_utils:create_random_vsn(),
  42. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  43. Artifact = "bin/"++Name,
  44. RConfFile =
  45. rebar_test_utils:create_config(AppDir,
  46. [
  47. {escript_name, list_to_atom(Name)}
  48. ,{artifacts, [Artifact]}
  49. ]),
  50. {ok, RConf} = file:consult(RConfFile),
  51. try rebar_test_utils:run_and_check(Config, RConf, ["compile"], return)
  52. catch
  53. {error,
  54. {rebar_prv_compile,
  55. {missing_artifact, Artifact}}} ->
  56. ok
  57. end,
  58. rebar_test_utils:run_and_check(Config, RConf++[{provider_hooks, [{post, [{compile, escriptize}]}]}],
  59. ["compile"], {ok, [{app, Name, valid}
  60. ,{file, filename:join([AppDir, "_build/default/", Artifact])}]}).
  61. run_hooks_once(Config) ->
  62. AppDir = ?config(apps, Config),
  63. Name = rebar_test_utils:create_random_name("app1_"),
  64. Vsn = rebar_test_utils:create_random_vsn(),
  65. RebarConfig = [{pre_hooks, [{compile, "mkdir blah"}]}],
  66. rebar_test_utils:create_config(AppDir, RebarConfig),
  67. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  68. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name, valid}]}).
  69. deps_hook_namespace(Config) ->
  70. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]),
  71. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]),
  72. TopDeps = rebar_test_utils:top_level_deps(Deps),
  73. RebarConfig = [
  74. {deps, TopDeps},
  75. {overrides, [
  76. {override, some_dep, [
  77. {provider_hooks, [
  78. {pre, [
  79. {compile, clean}
  80. ]}
  81. ]}
  82. ]}
  83. ]}
  84. ],
  85. rebar_test_utils:run_and_check(
  86. Config, RebarConfig, ["compile"],
  87. {ok, [{dep, "some_dep"}]}
  88. ).
  89. run_hooks_for_plugins(Config) ->
  90. AppDir = ?config(apps, Config),
  91. Name = rebar_test_utils:create_random_name("app1_"),
  92. Vsn = rebar_test_utils:create_random_vsn(),
  93. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  94. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  95. mock_git_resource:mock([{config, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]}]}]),
  96. RConfFile = rebar_test_utils:create_config(AppDir,
  97. [{plugins, [
  98. {list_to_atom(PluginName),
  99. {git, "http://site.com/user/"++PluginName++".git",
  100. {tag, Vsn}}}
  101. ]}]),
  102. {ok, RConf} = file:consult(RConfFile),
  103. rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid},
  104. {plugin, PluginName},
  105. {file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}).