You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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