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.

163 regels
6.2 KiB

10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
10 jaren geleden
  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. eunit_app_hooks/1,
  13. deps_hook_namespace/1]).
  14. -include_lib("common_test/include/ct.hrl").
  15. -include_lib("eunit/include/eunit.hrl").
  16. -include_lib("kernel/include/file.hrl").
  17. suite() ->
  18. [].
  19. init_per_suite(Config) ->
  20. Config.
  21. end_per_suite(_Config) ->
  22. meck:unload().
  23. init_per_testcase(_, Config) ->
  24. rebar_test_utils:init_rebar_state(Config).
  25. end_per_testcase(_, _Config) ->
  26. catch meck:unload().
  27. all() ->
  28. [build_and_clean_app, run_hooks_once, escriptize_artifacts,
  29. run_hooks_for_plugins, deps_hook_namespace, eunit_app_hooks].
  30. %% Test post provider hook cleans compiled project app, leaving it invalid
  31. build_and_clean_app(Config) ->
  32. AppDir = ?config(apps, Config),
  33. Name = rebar_test_utils:create_random_name("app1_"),
  34. Vsn = rebar_test_utils:create_random_vsn(),
  35. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  36. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name, valid}]}),
  37. RConfFile =
  38. rebar_test_utils:create_config(AppDir,
  39. [{provider_hooks, [{post, [{compile, clean}]}]}]),
  40. {ok, RConf} = file:consult(RConfFile),
  41. rebar_test_utils:run_and_check(Config, RConf,
  42. ["compile"], {ok, [{app, Name, invalid}]}).
  43. escriptize_artifacts(Config) ->
  44. AppDir = ?config(apps, Config),
  45. Name = rebar_test_utils:create_random_name("app1_"),
  46. Vsn = rebar_test_utils:create_random_vsn(),
  47. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  48. Artifact = "{{profile_dir}}/bin/"++Name,
  49. RConfFile =
  50. rebar_test_utils:create_config(AppDir,
  51. [
  52. {escript_name, list_to_atom(Name)}
  53. ,{artifacts, [Artifact]}
  54. ]),
  55. {ok, RConf} = file:consult(RConfFile),
  56. try rebar_test_utils:run_and_check(Config, RConf, ["compile"], return)
  57. catch
  58. {error,
  59. {rebar_prv_compile,
  60. {missing_artifact, Artifact}}} ->
  61. ok
  62. end,
  63. RConfFile1 =
  64. rebar_test_utils:create_config(AppDir,
  65. [
  66. {escript_name, list_to_atom(Name)}
  67. ,{artifacts, [Artifact]}
  68. ,{provider_hooks, [{post, [{compile, escriptize}]}]}
  69. ]),
  70. {ok, RConf1} = file:consult(RConfFile1),
  71. rebar_test_utils:run_and_check(Config, RConf1,
  72. ["compile"], {ok, [{app, Name, valid}
  73. ,{file, filename:join([AppDir, "_build/default/bin", Name])}]}).
  74. run_hooks_once(Config) ->
  75. AppDir = ?config(apps, Config),
  76. Name = rebar_test_utils:create_random_name("app1_"),
  77. Vsn = rebar_test_utils:create_random_vsn(),
  78. RebarConfig = [{pre_hooks, [{compile, "mkdir blah"}]}],
  79. rebar_test_utils:create_config(AppDir, RebarConfig),
  80. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  81. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name, valid}]}).
  82. deps_hook_namespace(Config) ->
  83. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]),
  84. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]),
  85. TopDeps = rebar_test_utils:top_level_deps(Deps),
  86. RebarConfig = [
  87. {deps, TopDeps},
  88. {overrides, [
  89. {override, some_dep, [
  90. {provider_hooks, [
  91. {pre, [
  92. {compile, clean}
  93. ]}
  94. ]}
  95. ]}
  96. ]}
  97. ],
  98. rebar_test_utils:run_and_check(
  99. Config, RebarConfig, ["compile"],
  100. {ok, [{dep, "some_dep"}]}
  101. ).
  102. %% Checks that a hook that is defined on an app (not a top level hook of a project with subapps) is run
  103. eunit_app_hooks(Config) ->
  104. AppDir = ?config(apps, Config),
  105. Name = rebar_test_utils:create_random_name("app1_"),
  106. Vsn = rebar_test_utils:create_random_vsn(),
  107. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  108. RConfFile =
  109. rebar_test_utils:create_config(AppDir,
  110. [
  111. {escript_name, list_to_atom(Name)}
  112. ,{provider_hooks, [{post, [{eunit, escriptize}]}]}
  113. ]),
  114. {ok, RConf} = file:consult(RConfFile),
  115. rebar_test_utils:run_and_check(Config, RConf,
  116. ["eunit"], {ok, [{app, Name, valid}
  117. ,{file, filename:join([AppDir, "_build/test/bin", Name])}]}).
  118. run_hooks_for_plugins(Config) ->
  119. AppDir = ?config(apps, Config),
  120. Name = rebar_test_utils:create_random_name("app1_"),
  121. Vsn = rebar_test_utils:create_random_vsn(),
  122. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  123. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  124. mock_git_resource:mock([{config, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]}]}]),
  125. RConfFile = rebar_test_utils:create_config(AppDir,
  126. [{plugins, [
  127. {list_to_atom(PluginName),
  128. {git, "http://site.com/user/"++PluginName++".git",
  129. {tag, Vsn}}}
  130. ]}]),
  131. {ok, RConf} = file:consult(RConfFile),
  132. rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid},
  133. {plugin, PluginName},
  134. {file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}).