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.

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