summaryrefslogtreecommitdiff
path: root/test/rebar_deps_SUITE.erl
blob: 4aaa7e3a3a0fad8c05dc05d2ca67d763abe46f47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
%% TODO: add tests for:
%% - only part of deps fetched
%% - only part of deps locked
%% - output only shown once
%% - modification asterisk on locked file
-module(rebar_deps_SUITE).
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

all() -> [default_nodep, default_lock].

init_per_suite(Config) ->
    application:start(meck),
    Config.

end_per_suite(_Config) ->
    application:stop(meck).

init_per_testcase(Case, Config) ->
    meck:new(io, [no_link, passthrough, unstick]),
    setup_project(Case, Config).

end_per_testcase(_, Config) ->
    meck:unload(),
    Config.

config_content() ->
    [{deps, [
        {src_a, ".*", {git, "https://example.org/ferd/src_a.git", {branch, "master"}}},
        {src_b, {git, "https://example.org/ferd/src_b.git", {branch, "master"}}},
        {pkg_a, "1.0.0"}
     ]},
     {profiles,
      [{test,
        [{deps, [
            {tdep, {git, "git://example.org/ferd/tdep.git", {tag, "0.8.2"}}}
        ]}]
      }]}
    ].

setup_project(Case, Config0) ->
    Config = rebar_test_utils:init_rebar_state(
            Config0,
            atom_to_list(Case)++"_"
    ),
    AppDir = ?config(apps, Config),
    rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]),
    TopDeps = proplists:get_value(deps, config_content()),
    StringDeps = [erlang:setelement(1, Dep, atom_to_list(element(1,Dep)))
                  || Dep <- TopDeps],
    RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
    mock_git_resource:mock([{deps, lists:filter(fun src_dep/1, StringDeps)}]),
    mock_pkg_resource:mock([{pkgdeps,
      [{{ec_cnv:to_binary(N),
         ec_cnv:to_binary(V)},[]}
       || {N,V} <- lists:filter(fun pkg_dep/1, StringDeps)]}]),
    [{rebarconfig, RebarConf} | Config].

src_dep(Dep) ->
    case element(1, Dep) of
        "src_"++_ -> true;
        _ -> false
    end.

pkg_dep(Dep) ->
    case element(1, Dep) of
        "pkg_"++_ -> true;
        _ -> false
    end.

default_nodep(Config) ->
    {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
    rebar_test_utils:run_and_check(
        Config, RebarConfig, ["deps"], {ok, []}
    ),
    History = meck:history(io),
    Strings = [io_lib:format(Str, Args) || {_, {io, format, [Str, Args]}, _} <- History],
    {match, _} = re:run(Strings, "src_a\\* \\(git source\\)"),
    {match, _} = re:run(Strings, "src_b\\* \\(git source\\)"),
    {match, _} = re:run(Strings, "pkg_a\\* \\(package 1.0.0\\)").

default_lock(Config) ->
    {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
    rebar_test_utils:run_and_check(
        Config, RebarConfig, ["lock"], {ok, []}
    ),
    rebar_test_utils:run_and_check(
        Config, RebarConfig, ["deps"], {ok, []}
    ),
    History = meck:history(io),
    Strings = [io_lib:format(Str, Args) || {_, {io, format, [Str, Args]}, _} <- History],
    {match, _} = re:run(Strings, "src_a\\ \\(locked git source\\)"),
    {match, _} = re:run(Strings, "src_b\\ \\(locked git source\\)"),
    {match, _} = re:run(Strings, "pkg_a\\ \\(locked package 1.0.0\\)").