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.

101 lines
3.6 KiB

  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. run_hooks_once/1,
  10. run_hooks_for_plugins/1,
  11. deps_hook_namespace/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. meck:unload().
  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. [build_and_clean_app, run_hooks_once,
  27. run_hooks_for_plugins, deps_hook_namespace].
  28. %% Test post provider hook cleans compiled project app, leaving it invalid
  29. build_and_clean_app(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. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name, valid}]}),
  35. rebar_test_utils:run_and_check(Config, [{provider_hooks, [{post, [{compile, clean}]}]}],
  36. ["compile"], {ok, [{app, Name, invalid}]}).
  37. run_hooks_once(Config) ->
  38. AppDir = ?config(apps, Config),
  39. Name = rebar_test_utils:create_random_name("app1_"),
  40. Vsn = rebar_test_utils:create_random_vsn(),
  41. RebarConfig = [{pre_hooks, [{compile, "mkdir blah"}]}],
  42. rebar_test_utils:create_config(AppDir, RebarConfig),
  43. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  44. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name, valid}]}).
  45. deps_hook_namespace(Config) ->
  46. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]),
  47. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]),
  48. TopDeps = rebar_test_utils:top_level_deps(Deps),
  49. RebarConfig = [
  50. {deps, TopDeps},
  51. {overrides, [
  52. {override, some_dep, [
  53. {provider_hooks, [
  54. {pre, [
  55. {compile, clean}
  56. ]}
  57. ]}
  58. ]}
  59. ]}
  60. ],
  61. rebar_test_utils:run_and_check(
  62. Config, RebarConfig, ["compile"],
  63. {ok, [{dep, "some_dep"}]}
  64. ).
  65. run_hooks_for_plugins(Config) ->
  66. AppDir = ?config(apps, Config),
  67. Name = rebar_test_utils:create_random_name("app1_"),
  68. Vsn = rebar_test_utils:create_random_vsn(),
  69. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  70. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  71. mock_git_resource:mock([{config, [{pre_hooks, [{compile, "touch randomfile"}]}]}]),
  72. RConfFile = rebar_test_utils:create_config(AppDir,
  73. [{plugins, [
  74. {list_to_atom(PluginName),
  75. {git, "http://site.com/user/"++PluginName++".git",
  76. {tag, Vsn}}}
  77. ]}]),
  78. {ok, RConf} = file:consult(RConfFile),
  79. rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid},
  80. {plugin, PluginName},
  81. {file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}).