Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

143 righe
5.2 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. 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. RConfFile =
  37. rebar_test_utils:create_config(AppDir,
  38. [{provider_hooks, [{post, [{compile, clean}]}]}]),
  39. {ok, RConf} = file:consult(RConfFile),
  40. rebar_test_utils:run_and_check(Config, RConf,
  41. ["compile"], {ok, [{app, Name, invalid}]}).
  42. escriptize_artifacts(Config) ->
  43. AppDir = ?config(apps, Config),
  44. Name = rebar_test_utils:create_random_name("app1_"),
  45. Vsn = rebar_test_utils:create_random_vsn(),
  46. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  47. Artifact = "{{profile_dir}}/bin/"++Name,
  48. RConfFile =
  49. rebar_test_utils:create_config(AppDir,
  50. [
  51. {escript_name, list_to_atom(Name)}
  52. ,{artifacts, [Artifact]}
  53. ]),
  54. {ok, RConf} = file:consult(RConfFile),
  55. try rebar_test_utils:run_and_check(Config, RConf, ["compile"], return)
  56. catch
  57. {error,
  58. {rebar_prv_compile,
  59. {missing_artifact, Artifact}}} ->
  60. ok
  61. end,
  62. RConfFile1 =
  63. rebar_test_utils:create_config(AppDir,
  64. [
  65. {escript_name, list_to_atom(Name)}
  66. ,{artifacts, [Artifact]}
  67. ,{provider_hooks, [{post, [{compile, escriptize}]}]}
  68. ]),
  69. {ok, RConf1} = file:consult(RConfFile1),
  70. rebar_test_utils:run_and_check(Config, RConf1,
  71. ["compile"], {ok, [{app, Name, valid}
  72. ,{file, filename:join([AppDir, "_build/default/bin", Name])}]}).
  73. run_hooks_once(Config) ->
  74. AppDir = ?config(apps, Config),
  75. Name = rebar_test_utils:create_random_name("app1_"),
  76. Vsn = rebar_test_utils:create_random_vsn(),
  77. RebarConfig = [{pre_hooks, [{compile, "mkdir blah"}]}],
  78. rebar_test_utils:create_config(AppDir, RebarConfig),
  79. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  80. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name, valid}]}).
  81. deps_hook_namespace(Config) ->
  82. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]),
  83. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]),
  84. TopDeps = rebar_test_utils:top_level_deps(Deps),
  85. RebarConfig = [
  86. {deps, TopDeps},
  87. {overrides, [
  88. {override, some_dep, [
  89. {provider_hooks, [
  90. {pre, [
  91. {compile, clean}
  92. ]}
  93. ]}
  94. ]}
  95. ]}
  96. ],
  97. rebar_test_utils:run_and_check(
  98. Config, RebarConfig, ["compile"],
  99. {ok, [{dep, "some_dep"}]}
  100. ).
  101. run_hooks_for_plugins(Config) ->
  102. AppDir = ?config(apps, Config),
  103. Name = rebar_test_utils:create_random_name("app1_"),
  104. Vsn = rebar_test_utils:create_random_vsn(),
  105. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  106. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  107. mock_git_resource:mock([{config, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]}]}]),
  108. RConfFile = rebar_test_utils:create_config(AppDir,
  109. [{plugins, [
  110. {list_to_atom(PluginName),
  111. {git, "http://site.com/user/"++PluginName++".git",
  112. {tag, Vsn}}}
  113. ]}]),
  114. {ok, RConf} = file:consult(RConfFile),
  115. rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid},
  116. {plugin, PluginName},
  117. {file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}).