Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

217 rindas
8.3 KiB

pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
  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_once_profiles/1,
  12. run_hooks_for_plugins/1,
  13. eunit_app_hooks/1,
  14. deps_hook_namespace/1,
  15. bare_compile_hooks_default_ns/1,
  16. deps_clean_hook_namespace/1]).
  17. -include_lib("common_test/include/ct.hrl").
  18. -include_lib("eunit/include/eunit.hrl").
  19. -include_lib("kernel/include/file.hrl").
  20. suite() ->
  21. [].
  22. init_per_suite(Config) ->
  23. Config.
  24. end_per_suite(_Config) ->
  25. meck:unload().
  26. init_per_testcase(_, Config) ->
  27. rebar_test_utils:init_rebar_state(Config).
  28. end_per_testcase(_, _Config) ->
  29. catch meck:unload().
  30. all() ->
  31. [build_and_clean_app, run_hooks_once, run_hooks_once_profiles,
  32. escriptize_artifacts, run_hooks_for_plugins, deps_hook_namespace,
  33. bare_compile_hooks_default_ns, deps_clean_hook_namespace, eunit_app_hooks].
  34. %% Test post provider hook cleans compiled project app, leaving it invalid
  35. build_and_clean_app(Config) ->
  36. AppDir = ?config(apps, Config),
  37. Name = rebar_test_utils:create_random_name("app1_"),
  38. Vsn = rebar_test_utils:create_random_vsn(),
  39. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  40. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name, valid}]}),
  41. RConfFile =
  42. rebar_test_utils:create_config(AppDir,
  43. [{provider_hooks, [{post, [{compile, clean}]}]}]),
  44. {ok, RConf} = file:consult(RConfFile),
  45. rebar_test_utils:run_and_check(Config, RConf,
  46. ["compile"], {ok, [{app, Name, invalid}]}).
  47. escriptize_artifacts(Config) ->
  48. AppDir = ?config(apps, Config),
  49. Name = rebar_test_utils:create_random_name("app1_"),
  50. Vsn = rebar_test_utils:create_random_vsn(),
  51. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  52. Artifact = "{{profile_dir}}/bin/"++Name,
  53. RConfFile =
  54. rebar_test_utils:create_config(AppDir,
  55. [
  56. {escript_name, list_to_atom(Name)}
  57. ,{artifacts, [Artifact]}
  58. ]),
  59. {ok, RConf} = file:consult(RConfFile),
  60. try rebar_test_utils:run_and_check(Config, RConf, ["compile"], return)
  61. catch
  62. {error,
  63. {rebar_prv_compile,
  64. {missing_artifact, Artifact}}} ->
  65. ok
  66. end,
  67. RConfFile1 =
  68. rebar_test_utils:create_config(AppDir,
  69. [
  70. {escript_name, list_to_atom(Name)}
  71. ,{artifacts, [Artifact]}
  72. ,{provider_hooks, [{post, [{compile, escriptize}]}]}
  73. ]),
  74. {ok, RConf1} = file:consult(RConfFile1),
  75. rebar_test_utils:run_and_check(Config, RConf1,
  76. ["compile"], {ok, [{app, Name, valid}
  77. ,{file, filename:join([AppDir, "_build/default/bin", Name])}]}).
  78. run_hooks_once(Config) ->
  79. AppDir = ?config(apps, Config),
  80. Name = rebar_test_utils:create_random_name("app1_"),
  81. Vsn = rebar_test_utils:create_random_vsn(),
  82. RebarConfig = [{pre_hooks, [{compile, "mkdir blah"}]}],
  83. rebar_test_utils:create_config(AppDir, RebarConfig),
  84. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  85. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name, valid}]}).
  86. %% test that even if a hook is defined at the project level in a used profile
  87. %% the hook is not run for each application in the project umbrella
  88. run_hooks_once_profiles(Config) ->
  89. AppDir = ?config(apps, Config),
  90. Name = rebar_test_utils:create_random_name("app1_"),
  91. Vsn = rebar_test_utils:create_random_vsn(),
  92. RebarConfig = [{profiles, [{hooks, [{pre_hooks, [{compile, "mkdir blah"}]}]}]}],
  93. rebar_test_utils:create_config(AppDir, RebarConfig),
  94. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  95. rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "hooks", "compile"], {ok, [{app, Name, valid}]}).
  96. deps_hook_namespace(Config) ->
  97. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]),
  98. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]),
  99. TopDeps = rebar_test_utils:top_level_deps(Deps),
  100. RebarConfig = [
  101. {deps, TopDeps},
  102. {overrides, [
  103. {override, some_dep, [
  104. {provider_hooks, [
  105. {pre, [
  106. {compile, clean}
  107. ]}
  108. ]}
  109. ]}
  110. ]}
  111. ],
  112. rebar_test_utils:run_and_check(
  113. Config, RebarConfig, ["compile"],
  114. {ok, [{dep, "some_dep"}]}
  115. ).
  116. %% tests that hooks to compile when running bare compile run in the default namespace
  117. bare_compile_hooks_default_ns(Config) ->
  118. AppDir = ?config(apps, Config),
  119. Name = rebar_test_utils:create_random_name("app1_"),
  120. Vsn = rebar_test_utils:create_random_vsn(),
  121. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  122. RConfFile = rebar_test_utils:create_config(AppDir,
  123. [{provider_hooks, [{post, [{compile, clean}]}]}]),
  124. {ok, RConf} = file:consult(RConfFile),
  125. rebar_test_utils:run_and_check(
  126. Config, RConf, ["bare", "compile", "--paths", "."],
  127. {ok, []}
  128. ).
  129. deps_clean_hook_namespace(Config) ->
  130. mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]),
  131. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]),
  132. TopDeps = rebar_test_utils:top_level_deps(Deps),
  133. RebarConfig = [
  134. {deps, TopDeps},
  135. {overrides, [
  136. {override, some_dep, [
  137. {provider_hooks, [
  138. {pre, [
  139. {compile, clean}
  140. ]}
  141. ]}
  142. ]}
  143. ]}
  144. ],
  145. rebar_test_utils:run_and_check(
  146. Config, RebarConfig, ["clean"],
  147. {ok, [{dep, "some_dep"}]}
  148. ).
  149. %% Checks that a hook that is defined on an app (not a top level hook of a project with subapps) is run
  150. eunit_app_hooks(Config) ->
  151. AppDir = ?config(apps, Config),
  152. Name = rebar_test_utils:create_random_name("app1_"),
  153. Vsn = rebar_test_utils:create_random_vsn(),
  154. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  155. RConfFile =
  156. rebar_test_utils:create_config(AppDir,
  157. [
  158. {escript_name, list_to_atom(Name)}
  159. ,{provider_hooks, [{post, [{eunit, escriptize}]}]}
  160. ]),
  161. {ok, RConf} = file:consult(RConfFile),
  162. rebar_test_utils:run_and_check(Config, RConf,
  163. ["eunit"], {ok, [{app, Name, valid}
  164. ,{file, filename:join([AppDir, "_build/test/bin", Name])}]}).
  165. run_hooks_for_plugins(Config) ->
  166. AppDir = ?config(apps, Config),
  167. Name = rebar_test_utils:create_random_name("app1_"),
  168. Vsn = rebar_test_utils:create_random_vsn(),
  169. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  170. PluginName = rebar_test_utils:create_random_name("plugin1_"),
  171. mock_git_resource:mock([{config, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]}]}]),
  172. RConfFile = rebar_test_utils:create_config(AppDir,
  173. [{plugins, [
  174. {list_to_atom(PluginName),
  175. {git, "http://site.com/user/"++PluginName++".git",
  176. {tag, Vsn}}}
  177. ]}]),
  178. {ok, RConf} = file:consult(RConfFile),
  179. rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid},
  180. {plugin, PluginName},
  181. {file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}).