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.

100 lines
3.6 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. -include_lib("common_test/include/ct.hrl").
  11. -include_lib("eunit/include/eunit.hrl").
  12. -include_lib("kernel/include/file.hrl").
  13. all() ->
  14. [profile_new_key, profile_merge_keys, profile_merges].
  15. init_per_suite(Config) ->
  16. application:start(meck),
  17. Config.
  18. end_per_suite(_Config) ->
  19. application:stop(meck).
  20. init_per_testcase(_, Config) ->
  21. rebar_test_utils:init_rebar_state(Config).
  22. end_per_testcase(_, Config) ->
  23. meck:unload(),
  24. Config.
  25. profile_new_key(Config) ->
  26. AppDir = ?config(apps, Config),
  27. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  28. ,{"b", "1.0.0", []}]),
  29. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
  30. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  31. Vsn = rebar_test_utils:create_random_vsn(),
  32. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  33. Deps = rebar_test_utils:top_level_deps(
  34. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  35. ,{"b", "1.0.0", []}])),
  36. ct:pal("Deps ~p", [Deps]),
  37. RebarConfig = [{profiles,
  38. [{ct,
  39. [{deps, Deps}]}]}],
  40. rebar_test_utils:run_and_check(Config, RebarConfig,
  41. ["as", "ct", "compile"], {ok, [{app, Name}
  42. ,{dep, "a", "1.0.0"}
  43. ,{dep, "b", "1.0.0"}]}).
  44. profile_merge_keys(Config) ->
  45. AppDir = ?config(apps, Config),
  46. AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  47. ,{"b", "1.0.0", []}
  48. ,{"b", "2.0.0", []}]),
  49. mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
  50. Name = rebar_test_utils:create_random_name("profile_new_key_"),
  51. Vsn = rebar_test_utils:create_random_vsn(),
  52. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  53. Deps = rebar_test_utils:top_level_deps(
  54. rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  55. ,{"b", "1.0.0", []}])),
  56. ProfileDeps = rebar_test_utils:top_level_deps(
  57. rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])),
  58. RebarConfig = [{deps, Deps},
  59. {profiles,
  60. [{ct,
  61. [{deps, ProfileDeps}]}]}],
  62. rebar_test_utils:run_and_check(Config, RebarConfig,
  63. ["as", "ct", "compile"], {ok, [{app, Name}
  64. ,{dep, "a", "1.0.0"}
  65. ,{dep, "b", "2.0.0"}]}).
  66. profile_merges(_Config) ->
  67. RebarConfig = [{test1, [{key1, 1, 2}, key2]},
  68. {test2, "hello"},
  69. {profiles,
  70. [{profile1,
  71. [{test1, [{key3, 5}, key1]}]},
  72. {profile2, [{test2, "goodbye"}]}]}],
  73. State = rebar_state:new(RebarConfig),
  74. State1 = rebar_state:apply_profiles(State, [profile1, profile2]),
  75. %% Combine lists
  76. ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]),
  77. lists:sort(rebar_state:get(State1, test1))),
  78. %% Use new value for strings
  79. "goodbye" = rebar_state:get(State1, test2).