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.

153 wiersze
5.7 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. -include_lib("common_test/include/ct.hrl").
  14. -include_lib("eunit/include/eunit.hrl").
  15. -include_lib("kernel/include/file.hrl").
  16. all() ->
  17. [profile_new_key, profile_merge_keys, profile_merges,
  18. add_to_profile, add_to_existing_profile,
  19. profiles_remain_applied_with_config_present].
  20. init_per_suite(Config) ->
  21. application:start(meck),
  22. Config.
  23. end_per_suite(_Config) ->
  24. application:stop(meck).
  25. init_per_testcase(_, Config) ->
  26. rebar_test_utils:init_rebar_state(Config, "profiles_").
  27. end_per_testcase(_, Config) ->
  28. meck:unload(),
  29. Config.
  30. profile_new_key(Config) ->
  31. AppDir = ?config(apps, Config),
  32. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  33. ,{"b", "1.0.0", []}]),
  34. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
  35. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  36. Vsn = rebar_test_utils:create_random_vsn(),
  37. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  38. Deps = rebar_test_utils:top_level_deps(
  39. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  40. ,{"b", "1.0.0", []}])),
  41. ct:pal("Deps ~p", [Deps]),
  42. RebarConfig = [{profiles,
  43. [{ct,
  44. [{deps, Deps}]}]}],
  45. rebar_test_utils:run_and_check(Config, RebarConfig,
  46. ["as", "ct", "compile"], {ok, [{app, Name}
  47. ,{dep, "a", "1.0.0"}
  48. ,{dep, "b", "1.0.0"}]}).
  49. profile_merge_keys(Config) ->
  50. AppDir = ?config(apps, Config),
  51. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  52. ,{"b", "1.0.0", []}
  53. ,{"b", "2.0.0", []}]),
  54. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
  55. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  56. Vsn = rebar_test_utils:create_random_vsn(),
  57. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  58. Deps = rebar_test_utils:top_level_deps(
  59. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  60. ,{"b", "1.0.0", []}])),
  61. ProfileDeps = rebar_test_utils:top_level_deps(
  62. rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])),
  63. RebarConfig = [{deps, Deps},
  64. {profiles,
  65. [{ct,
  66. [{deps, ProfileDeps}]}]}],
  67. rebar_test_utils:run_and_check(Config, RebarConfig,
  68. ["as", "ct", "compile"], {ok, [{app, Name}
  69. ,{dep, "a", "1.0.0"}
  70. ,{dep, "b", "2.0.0"}]}).
  71. profile_merges(_Config) ->
  72. RebarConfig = [{test1, [{key1, 1, 2}, key2]},
  73. {test2, "hello"},
  74. {test3, [key3]},
  75. {test4, "oldvalue"},
  76. {profiles,
  77. [{profile1,
  78. [{test1, [{key3, 5}, key1]}]},
  79. {profile2, [{test2, "goodbye"},
  80. {test3, []},
  81. {test4, []}]}]}],
  82. State = rebar_state:new(RebarConfig),
  83. State1 = rebar_state:apply_profiles(State, [profile1, profile2]),
  84. %% Combine lists
  85. ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]),
  86. lists:sort(rebar_state:get(State1, test1))),
  87. %% Use new value for strings
  88. "goodbye" = rebar_state:get(State1, test2),
  89. %% Check that a newvalue of []/"" doesn't override non-string oldvalues
  90. [key3] = rebar_state:get(State1, test3),
  91. [] = rebar_state:get(State1, test4).
  92. add_to_profile(_Config) ->
  93. RebarConfig = [{foo, true}, {bar, false}],
  94. State = rebar_state:new(RebarConfig),
  95. State1 = rebar_state:add_to_profile(State, test, [{foo, false}]),
  96. State2 = rebar_state:apply_profiles(State1, test),
  97. Opts = rebar_state:opts(State2),
  98. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar]).
  99. add_to_existing_profile(_Config) ->
  100. RebarConfig = [{foo, true}, {bar, false}, {profiles, [
  101. {test, [{foo, false}]}
  102. ]}],
  103. State = rebar_state:new(RebarConfig),
  104. State1 = rebar_state:add_to_profile(State, test, [{baz, false}]),
  105. State2 = rebar_state:apply_profiles(State1, test),
  106. Opts = rebar_state:opts(State2),
  107. lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]).
  108. profiles_remain_applied_with_config_present(Config) ->
  109. AppDir = ?config(apps, Config),
  110. Name = rebar_test_utils:create_random_name("profiles_remain_applied_"),
  111. Vsn = rebar_test_utils:create_random_vsn(),
  112. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  113. RebarConfig = [{erl_opts, []}, {profiles, [
  114. {not_ok, [{erl_opts, [{d, not_ok}]}]}
  115. ]}],
  116. rebar_test_utils:create_config(AppDir, RebarConfig),
  117. rebar_test_utils:run_and_check(Config, RebarConfig,
  118. ["as", "not_ok", "compile"], {ok, [{app, Name}]}),
  119. Mod = list_to_atom("not_a_real_src_" ++ Name),
  120. true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])).