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.

95 lines
3.0 KiB

пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
  1. %% TODO: add tests for:
  2. %% - only part of deps fetched
  3. %% - only part of deps locked
  4. %% - output only shown once
  5. %% - modification asterisk on locked file
  6. -module(rebar_deps_SUITE).
  7. -compile(export_all).
  8. -include_lib("common_test/include/ct.hrl").
  9. -include_lib("eunit/include/eunit.hrl").
  10. all() -> [default_nodep, default_lock].
  11. init_per_suite(Config) ->
  12. application:start(meck),
  13. Config.
  14. end_per_suite(_Config) ->
  15. application:stop(meck).
  16. init_per_testcase(Case, Config) ->
  17. meck:new(io, [no_link, passthrough, unstick]),
  18. setup_project(Case, Config).
  19. end_per_testcase(_, Config) ->
  20. meck:unload(),
  21. Config.
  22. config_content() ->
  23. [{deps, [
  24. {src_a, ".*", {git, "https://example.org/ferd/src_a.git", {branch, "master"}}},
  25. {src_b, {git, "https://example.org/ferd/src_b.git", {branch, "master"}}},
  26. {pkg_a, "1.0.0"}
  27. ]},
  28. {profiles,
  29. [{test,
  30. [{deps, [
  31. {tdep, {git, "git://example.org/ferd/tdep.git", {tag, "0.8.2"}}}
  32. ]}]
  33. }]}
  34. ].
  35. setup_project(Case, Config0) ->
  36. Config = rebar_test_utils:init_rebar_state(
  37. Config0,
  38. atom_to_list(Case)++"_"
  39. ),
  40. AppDir = ?config(apps, Config),
  41. rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]),
  42. TopDeps = proplists:get_value(deps, config_content()),
  43. StringDeps = [erlang:setelement(1, Dep, atom_to_list(element(1,Dep)))
  44. || Dep <- TopDeps],
  45. RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
  46. mock_git_resource:mock([{deps, lists:filter(fun src_dep/1, StringDeps)}]),
  47. mock_pkg_resource:mock([{pkgdeps,
  48. [{{ec_cnv:to_binary(N),
  49. ec_cnv:to_binary(V)},[]}
  50. || {N,V} <- lists:filter(fun pkg_dep/1, StringDeps)]}]),
  51. [{rebarconfig, RebarConf} | Config].
  52. src_dep(Dep) ->
  53. case element(1, Dep) of
  54. "src_"++_ -> true;
  55. _ -> false
  56. end.
  57. pkg_dep(Dep) ->
  58. case element(1, Dep) of
  59. "pkg_"++_ -> true;
  60. _ -> false
  61. end.
  62. default_nodep(Config) ->
  63. {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
  64. rebar_test_utils:run_and_check(
  65. Config, RebarConfig, ["deps"], {ok, []}
  66. ),
  67. History = meck:history(io),
  68. Strings = [io_lib:format(Str, Args) || {_, {io, format, [Str, Args]}, _} <- History],
  69. {match, _} = re:run(Strings, "src_a\\* \\(git source\\)"),
  70. {match, _} = re:run(Strings, "src_b\\* \\(git source\\)"),
  71. {match, _} = re:run(Strings, "pkg_a\\* \\(package 1.0.0\\)").
  72. default_lock(Config) ->
  73. {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
  74. rebar_test_utils:run_and_check(
  75. Config, RebarConfig, ["lock"], {ok, []}
  76. ),
  77. rebar_test_utils:run_and_check(
  78. Config, RebarConfig, ["deps"], {ok, []}
  79. ),
  80. History = meck:history(io),
  81. Strings = [io_lib:format(Str, Args) || {_, {io, format, [Str, Args]}, _} <- History],
  82. {match, _} = re:run(Strings, "src_a\\ \\(locked git source\\)"),
  83. {match, _} = re:run(Strings, "src_b\\ \\(locked git source\\)"),
  84. {match, _} = re:run(Strings, "pkg_a\\ \\(locked package 1.0.0\\)").