Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

233 wiersze
8.8 KiB

  1. -module(rebar_profiles_SUITE).
  2. -export([init_per_suite/1,
  3. end_per_suite/1,
  4. init_per_testcase/2,
  5. end_per_testcase/2,
  6. all/0,
  7. profile_new_key/1,
  8. profile_merge_keys/1,
  9. profile_merges/1,
  10. add_to_profile/1,
  11. add_to_existing_profile/1,
  12. profiles_remain_applied_with_config_present/1,
  13. test_profile_applied_at_completion/1,
  14. test_profile_applied_before_compile/1,
  15. test_profile_applied_before_eunit/1,
  16. test_profile_applied_to_apps/1]).
  17. -include_lib("common_test/include/ct.hrl").
  18. -include_lib("eunit/include/eunit.hrl").
  19. -include_lib("kernel/include/file.hrl").
  20. all() ->
  21. [profile_new_key, profile_merge_keys, profile_merges,
  22. add_to_profile, add_to_existing_profile,
  23. profiles_remain_applied_with_config_present,
  24. test_profile_applied_at_completion,
  25. test_profile_applied_before_compile,
  26. test_profile_applied_before_eunit,
  27. test_profile_applied_to_apps].
  28. init_per_suite(Config) ->
  29. application:start(meck),
  30. Config.
  31. end_per_suite(_Config) ->
  32. application:stop(meck).
  33. init_per_testcase(_, Config) ->
  34. rebar_test_utils:init_rebar_state(Config, "profiles_").
  35. end_per_testcase(_, Config) ->
  36. meck:unload(),
  37. Config.
  38. profile_new_key(Config) ->
  39. AppDir = ?config(apps, Config),
  40. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  41. ,{"b", "1.0.0", []}]),
  42. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
  43. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  44. Vsn = rebar_test_utils:create_random_vsn(),
  45. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  46. Deps = rebar_test_utils:top_level_deps(
  47. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  48. ,{"b", "1.0.0", []}])),
  49. ct:pal("Deps ~p", [Deps]),
  50. RebarConfig = [{profiles,
  51. [{ct,
  52. [{deps, Deps}]}]}],
  53. rebar_test_utils:run_and_check(Config, RebarConfig,
  54. ["as", "ct", "compile"], {ok, [{app, Name}
  55. ,{dep, "a", "1.0.0"}
  56. ,{dep, "b", "1.0.0"}]}).
  57. profile_merge_keys(Config) ->
  58. AppDir = ?config(apps, Config),
  59. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  60. ,{"b", "1.0.0", []}
  61. ,{"b", "2.0.0", []}]),
  62. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
  63. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  64. Vsn = rebar_test_utils:create_random_vsn(),
  65. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  66. Deps = rebar_test_utils:top_level_deps(
  67. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  68. ,{"b", "1.0.0", []}])),
  69. ProfileDeps = rebar_test_utils:top_level_deps(
  70. rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])),
  71. RebarConfig = [{deps, Deps},
  72. {profiles,
  73. [{ct,
  74. [{deps, ProfileDeps}]}]}],
  75. rebar_test_utils:run_and_check(Config, RebarConfig,
  76. ["as", "ct", "compile"], {ok, [{app, Name}
  77. ,{dep, "a", "1.0.0"}
  78. ,{dep, "b", "2.0.0"}]}).
  79. profile_merges(_Config) ->
  80. RebarConfig = [{test1, [{key1, 1, 2}, key2]},
  81. {test2, "hello"},
  82. {test3, [key3]},
  83. {test4, "oldvalue"},
  84. {profiles,
  85. [{profile1,
  86. [{test1, [{key3, 5}, key1]}]},
  87. {profile2, [{test2, "goodbye"},
  88. {test3, []},
  89. {test4, []}]}]}],
  90. State = rebar_state:new(RebarConfig),
  91. State1 = rebar_state:apply_profiles(State, [profile1, profile2]),
  92. %% Combine lists
  93. ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]),
  94. lists:sort(rebar_state:get(State1, test1))),
  95. %% Use new value for strings
  96. "goodbye" = rebar_state:get(State1, test2),
  97. %% Check that a newvalue of []/"" doesn't override non-string oldvalues
  98. [key3] = rebar_state:get(State1, test3),
  99. [] = rebar_state:get(State1, test4).
  100. add_to_profile(_Config) ->
  101. RebarConfig = [{foo, true}, {bar, false}],
  102. State = rebar_state:new(RebarConfig),
  103. State1 = rebar_state:add_to_profile(State, test, [{foo, false}]),
  104. State2 = rebar_state:apply_profiles(State1, test),
  105. Opts = rebar_state:opts(State2),
  106. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar]).
  107. add_to_existing_profile(_Config) ->
  108. RebarConfig = [{foo, true}, {bar, false}, {profiles, [
  109. {test, [{foo, false}]}
  110. ]}],
  111. State = rebar_state:new(RebarConfig),
  112. State1 = rebar_state:add_to_profile(State, test, [{baz, false}]),
  113. State2 = rebar_state:apply_profiles(State1, test),
  114. Opts = rebar_state:opts(State2),
  115. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]).
  116. profiles_remain_applied_with_config_present(Config) ->
  117. AppDir = ?config(apps, Config),
  118. Name = rebar_test_utils:create_random_name("profiles_remain_applied_"),
  119. Vsn = rebar_test_utils:create_random_vsn(),
  120. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  121. RebarConfig = [{erl_opts, []}, {profiles, [
  122. {not_ok, [{erl_opts, [{d, not_ok}]}]}
  123. ]}],
  124. rebar_test_utils:create_config(AppDir, RebarConfig),
  125. rebar_test_utils:run_and_check(Config, RebarConfig,
  126. ["as", "not_ok", "compile"], {ok, [{app, Name}]}),
  127. Mod = list_to_atom("not_a_real_src_" ++ Name),
  128. true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])).
  129. test_profile_applied_at_completion(Config) ->
  130. AppDir = ?config(apps, Config),
  131. Name = rebar_test_utils:create_random_name("test_profile_at_completion_"),
  132. Vsn = rebar_test_utils:create_random_vsn(),
  133. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  134. RebarConfig = [{erl_opts, [{d, some_define}]}],
  135. rebar_test_utils:create_config(AppDir, RebarConfig),
  136. {ok, State} = rebar_test_utils:run_and_check(Config,
  137. RebarConfig,
  138. ["eunit"],
  139. return),
  140. Opts = rebar_state:opts(State),
  141. ErlOpts = dict:fetch(erl_opts, Opts),
  142. true = lists:member({d, 'TEST'}, ErlOpts).
  143. test_profile_applied_before_compile(Config) ->
  144. AppDir = ?config(apps, Config),
  145. Name = rebar_test_utils:create_random_name("test_profile_before_compile_"),
  146. Vsn = rebar_test_utils:create_random_vsn(),
  147. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  148. RebarConfig = [{erl_opts, [{d, some_define}]}],
  149. rebar_test_utils:create_config(AppDir, RebarConfig),
  150. rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  151. S = list_to_atom("not_a_real_src_" ++ Name),
  152. true = lists:member({d, 'TEST'}, proplists:get_value(options, S:module_info(compile), [])).
  153. test_profile_applied_before_eunit(Config) ->
  154. AppDir = ?config(apps, Config),
  155. Name = rebar_test_utils:create_random_name("test_profile_before_eunit_"),
  156. Vsn = rebar_test_utils:create_random_vsn(),
  157. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  158. RebarConfig = [{erl_opts, [{d, some_define}]}],
  159. rebar_test_utils:create_config(AppDir, RebarConfig),
  160. rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  161. T = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"),
  162. true = lists:member({d, 'TEST'}, proplists:get_value(options, T:module_info(compile), [])).
  163. test_profile_applied_to_apps(Config) ->
  164. AppDir = ?config(apps, Config),
  165. Name = rebar_test_utils:create_random_name("test_profile_applied_to_apps_"),
  166. Vsn = rebar_test_utils:create_random_vsn(),
  167. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  168. RebarConfig = [{erl_opts, [{d, some_define}]}],
  169. rebar_test_utils:create_config(AppDir, RebarConfig),
  170. {ok, State} = rebar_test_utils:run_and_check(Config,
  171. RebarConfig,
  172. ["eunit"],
  173. return),
  174. Apps = rebar_state:project_apps(State),
  175. lists:foreach(fun(App) ->
  176. AppState = rebar_app_info:state(App),
  177. Opts = rebar_state:opts(AppState),
  178. ErlOpts = dict:fetch(erl_opts, Opts),
  179. true = lists:member({d, 'TEST'}, ErlOpts)
  180. end, Apps).