Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

240 Zeilen
9.2 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. {test5, [{key5, true}]},
  85. {test6, [{key6, false}]},
  86. {profiles,
  87. [{profile1,
  88. [{test1, [{key3, 5}, key1]}]},
  89. {profile2, [{test2, "goodbye"},
  90. {test3, []},
  91. {test4, []},
  92. {test5, [{key5, false}]},
  93. {test6, [{key6, true}]}
  94. ]}]}],
  95. State = rebar_state:new(RebarConfig),
  96. State1 = rebar_state:apply_profiles(State, [profile1, profile2]),
  97. %% Combine lists
  98. ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]),
  99. lists:sort(rebar_state:get(State1, test1))),
  100. %% Use new value for strings
  101. "goodbye" = rebar_state:get(State1, test2),
  102. %% Check that a newvalue of []/"" doesn't override non-string oldvalues
  103. [key3] = rebar_state:get(State1, test3),
  104. [] = rebar_state:get(State1, test4),
  105. [{key5, false}, {key5, true}] = rebar_state:get(State1, test5),
  106. [{key6, true}, {key6, false}] = rebar_state:get(State1, test6).
  107. add_to_profile(_Config) ->
  108. RebarConfig = [{foo, true}, {bar, false}],
  109. State = rebar_state:new(RebarConfig),
  110. State1 = rebar_state:add_to_profile(State, test, [{foo, false}]),
  111. State2 = rebar_state:apply_profiles(State1, test),
  112. Opts = rebar_state:opts(State2),
  113. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar]).
  114. add_to_existing_profile(_Config) ->
  115. RebarConfig = [{foo, true}, {bar, false}, {profiles, [
  116. {test, [{foo, false}]}
  117. ]}],
  118. State = rebar_state:new(RebarConfig),
  119. State1 = rebar_state:add_to_profile(State, test, [{baz, false}]),
  120. State2 = rebar_state:apply_profiles(State1, test),
  121. Opts = rebar_state:opts(State2),
  122. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]).
  123. profiles_remain_applied_with_config_present(Config) ->
  124. AppDir = ?config(apps, Config),
  125. Name = rebar_test_utils:create_random_name("profiles_remain_applied_"),
  126. Vsn = rebar_test_utils:create_random_vsn(),
  127. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  128. RebarConfig = [{erl_opts, []}, {profiles, [
  129. {not_ok, [{erl_opts, [{d, not_ok}]}]}
  130. ]}],
  131. rebar_test_utils:create_config(AppDir, RebarConfig),
  132. rebar_test_utils:run_and_check(Config, RebarConfig,
  133. ["as", "not_ok", "compile"], {ok, [{app, Name}]}),
  134. Mod = list_to_atom("not_a_real_src_" ++ Name),
  135. true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])).
  136. test_profile_applied_at_completion(Config) ->
  137. AppDir = ?config(apps, Config),
  138. Name = rebar_test_utils:create_random_name("test_profile_at_completion_"),
  139. Vsn = rebar_test_utils:create_random_vsn(),
  140. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  141. RebarConfig = [{erl_opts, [{d, some_define}]}],
  142. rebar_test_utils:create_config(AppDir, RebarConfig),
  143. {ok, State} = rebar_test_utils:run_and_check(Config,
  144. RebarConfig,
  145. ["eunit"],
  146. return),
  147. Opts = rebar_state:opts(State),
  148. ErlOpts = dict:fetch(erl_opts, Opts),
  149. true = lists:member({d, 'TEST'}, ErlOpts).
  150. test_profile_applied_before_compile(Config) ->
  151. AppDir = ?config(apps, Config),
  152. Name = rebar_test_utils:create_random_name("test_profile_before_compile_"),
  153. Vsn = rebar_test_utils:create_random_vsn(),
  154. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  155. RebarConfig = [{erl_opts, [{d, some_define}]}],
  156. rebar_test_utils:create_config(AppDir, RebarConfig),
  157. rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  158. S = list_to_atom("not_a_real_src_" ++ Name),
  159. true = lists:member({d, 'TEST'}, proplists:get_value(options, S:module_info(compile), [])).
  160. test_profile_applied_before_eunit(Config) ->
  161. AppDir = ?config(apps, Config),
  162. Name = rebar_test_utils:create_random_name("test_profile_before_eunit_"),
  163. Vsn = rebar_test_utils:create_random_vsn(),
  164. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  165. RebarConfig = [{erl_opts, [{d, some_define}]}],
  166. rebar_test_utils:create_config(AppDir, RebarConfig),
  167. rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  168. T = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"),
  169. true = lists:member({d, 'TEST'}, proplists:get_value(options, T:module_info(compile), [])).
  170. test_profile_applied_to_apps(Config) ->
  171. AppDir = ?config(apps, Config),
  172. Name = rebar_test_utils:create_random_name("test_profile_applied_to_apps_"),
  173. Vsn = rebar_test_utils:create_random_vsn(),
  174. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  175. RebarConfig = [{erl_opts, [{d, some_define}]}],
  176. rebar_test_utils:create_config(AppDir, RebarConfig),
  177. {ok, State} = rebar_test_utils:run_and_check(Config,
  178. RebarConfig,
  179. ["eunit"],
  180. return),
  181. Apps = rebar_state:project_apps(State),
  182. lists:foreach(fun(App) ->
  183. AppState = rebar_app_info:state(App),
  184. Opts = rebar_state:opts(AppState),
  185. ErlOpts = dict:fetch(erl_opts, Opts),
  186. true = lists:member({d, 'TEST'}, ErlOpts)
  187. end, Apps).