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.

102 line
3.1 KiB

  1. %%% TODO: check that warnings are appearing
  2. -module(rebar_deps_SUITE).
  3. -compile(export_all).
  4. -include_lib("common_test/include/ct.hrl").
  5. -include_lib("eunit/include/eunit.hrl").
  6. all() -> [flat, pick_highest_left, pick_highest_right, pick_earliest,
  7. circular1, circular2].
  8. init_per_suite(Config) ->
  9. application:start(meck),
  10. Config.
  11. end_per_suite(_Config) ->
  12. application:stop(meck).
  13. init_per_testcase(Case, Config) ->
  14. {Deps, Expect} = deps(Case),
  15. Expected = case Expect of
  16. {ok, List} -> {ok, format_expected_deps(List)};
  17. {error, Reason} -> {error, Reason}
  18. end,
  19. [{expect, Expected} | setup_project(Case, Config, expand_deps(Deps))].
  20. format_expected_deps(Deps) ->
  21. [case Dep of
  22. {N,V} -> {dep, N, V};
  23. N -> {dep, N}
  24. end || Dep <- Deps].
  25. deps(flat) ->
  26. {[{"B", []},
  27. {"C", []}],
  28. {ok, ["B", "C"]}};
  29. deps(pick_highest_left) ->
  30. {[{"B", [{"C", "2", []}]},
  31. {"C", "1", []}],
  32. {ok, ["B", {"C", "1"}]}}; % Warn C2
  33. deps(pick_highest_right) ->
  34. {[{"B", "1", []},
  35. {"C", [{"B", "2", []}]}],
  36. {ok, [{"B","1"}, "C"]}}; % Warn B2
  37. deps(pick_earliest) ->
  38. {[{"B", [{"D", "1", []}]},
  39. {"C", [{"D", "2", []}]}],
  40. {ok, ["B","C",{"D","1"}]}}; % Warn D2
  41. deps(circular1) ->
  42. {[{"B", [{"A", []}]}, % A is the top-level app
  43. {"C", []}],
  44. {error, {cycles, [[<<"A">>,<<"B">>]]}}}; % circular dep
  45. deps(circular2) ->
  46. {[{"B", [{"C", [{"B", []}]}]},
  47. {"C", []}],
  48. {error, {cycles, [[<<"B">>,<<"C">>]]}}}. % circular dep
  49. end_per_testcase(_, Config) ->
  50. mock_git_resource:unmock(),
  51. meck:unload(),
  52. Config.
  53. expand_deps([]) -> [];
  54. expand_deps([{Name, Deps} | Rest]) ->
  55. Dep = {Name, ".*", {git, "https://example.org/user/"++Name++".git", "master"}},
  56. [{Dep, expand_deps(Deps)} | expand_deps(Rest)];
  57. expand_deps([{Name, Vsn, Deps} | Rest]) ->
  58. Dep = {Name, Vsn, {git, "https://example.org/user/"++Name++".git", {tag, Vsn}}},
  59. [{Dep, expand_deps(Deps)} | expand_deps(Rest)].
  60. setup_project(Case, Config0, Deps) ->
  61. Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)),
  62. AppDir = ?config(apps, Config),
  63. rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]),
  64. TopDeps = top_level_deps(Deps),
  65. RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
  66. mock_git_resource:mock([{deps, flat_deps(Deps)}]),
  67. [{rebarconfig, RebarConf} | Config].
  68. flat_deps([]) -> [];
  69. flat_deps([{{Name,_Vsn,_Ref}, Deps} | Rest]) ->
  70. [{Name, top_level_deps(Deps)}]
  71. ++
  72. flat_deps(Deps)
  73. ++
  74. flat_deps(Rest).
  75. top_level_deps(Deps) -> [{list_to_atom(Name),Vsn,Ref} || {{Name,Vsn,Ref},_} <- Deps].
  76. %%% TESTS %%%
  77. flat(Config) -> run(Config).
  78. pick_highest_left(Config) -> run(Config).
  79. pick_highest_right(Config) -> run(Config).
  80. pick_earliest(Config) -> run(Config).
  81. circular1(Config) -> run(Config).
  82. circular2(Config) -> run(Config).
  83. run(Config) ->
  84. {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
  85. rebar_test_utils:run_and_check(
  86. Config, RebarConfig, "install_deps", ?config(expect, Config)
  87. ).