aboutsummaryrefslogtreecommitdiffstats
path: root/test/rlx_command_SUITE.erl
blob: e0beec14873f94abd2e847b5ca53a64d27ca22ed (plain) (blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
%% -*- erlang-indent-level: 4; indent-tabs-mode: nil; fill-column: 92 -*-
%%% Copyright 2012 Erlware, LLC. All Rights Reserved.
%%%
%%% This file is provided to you under the Apache License,
%%% Version 2.0 (the "License"); you may not use this file
%%% except in compliance with the License.  You may obtain
%%% a copy of the License at
%%%
%%%   http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing,
%%% software distributed under the License is distributed on an
%%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%%% KIND, either express or implied.  See the License for the
%%% specific language governing permissions and limitations
%%% under the License.
%%%-------------------------------------------------------------------
%%% @author Eric Merrit <[email protected]>
%%% @copyright (C) 2012, Eric Merrit
-module(rlx_command_SUITE).

-export([suite/0,
         init_per_suite/1,
         end_per_suite/1,
         all/0,
         normal_passing_case/1,
         lib_expansion_case/1,
         lib_fail_case/1,
         spec_parse_fail_case/1,
         config_fail_case/1]).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

suite() ->
    [{timetrap,{seconds,30}}].

init_per_suite(Config) ->
    Config.

end_per_suite(_Config) ->
    ok.

all() ->
    [normal_passing_case, lib_expansion_case, lib_fail_case, config_fail_case].

normal_passing_case(Config) ->
    DataDir = filename:join(proplists:get_value(priv_dir, Config), ?MODULE),
    Lib1 = filename:join([DataDir, <<"lib1">>]),
    Lib2 = filename:join([DataDir, <<"lib2">>]),
    Outdir = filename:join([DataDir, "outdir"]),
    ok = rlx_util:mkdir_p(Lib1),
    ok = rlx_util:mkdir_p(Lib2),
    Goal1 = "app1<=33.33+build4",
    Goal2 = "app2:btwn:33.22,45.22+build.21",

    LogLevel = "2",
    RelName = "foo-release",
    RelVsn = "33.222",
    CmdLine = ["-V", LogLevel, "-g",Goal1,"-g",Goal2, "-l", Lib1, "-l", Lib2,
               "-n", RelName, "-v", RelVsn, "-o", Outdir, "-a", "lib1:"++binary_to_list(Lib1)],
    {ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
    {ok, State} = rlx_cmd_args:args2state(Opts, Targets),
    {ok, State1} = rlx_config:do(State),
    ?assertMatch([{lib1,Lib1}], rlx_state:overrides(State1)),
    ?assertMatch([Lib1, Lib2],
                 rlx_state:lib_dirs(State1)),
    ?assertMatch(Outdir, rlx_state:base_output_dir(State1)),

    ?assertMatch([{app1,{{33,33},{[],[<<"build4">>]}},lte},
                  {app2,
                   {{33,22},{[],[]}},
                   {{45,22},{[],[<<"build">>,21]}}, between}],
                 rlx_state:goals(State1)).

lib_expansion_case(Config) ->
    DataDir = filename:join(proplists:get_value(priv_dir, Config), ?MODULE),
    Lib1 = filename:join(DataDir, <<"lib1">>),
    Lib2 = filename:join(DataDir, <<"lib2">>),
    ok = rlx_util:mkdir_p(Lib1),
    ok = rlx_util:mkdir_p(Lib2),

    CmdLine = ["-l", filename:join(DataDir, "*")],
    {ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
    {ok, State} = rlx_cmd_args:args2state(Opts, Targets),
    {ok, State1} = rlx_config:do(State),
    ?assertMatch([Lib1, Lib2],
                 rlx_state:lib_dirs(State1)).

lib_fail_case(Config) ->
    DataDir = filename:join(proplists:get_value(priv_dir, Config), ?MODULE),
    Lib1 = filename:join([DataDir, "lib1"]),
    Lib2 = filename:join([DataDir, "lib3333"]),
    ok = rlx_util:mkdir_p(Lib1),

    CmdLine = ["-l", Lib1, "-l", Lib2],
    {ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
    ?assertMatch({error, {_, {not_directory, Lib2}}},
                 rlx_cmd_args:args2state(Opts, Targets)).

spec_parse_fail_case(_Config) ->
    Spec = "aaeu:3333:33.22a44",
    CmdLine = ["-g", Spec],
    {ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
    ?assertMatch({error, {_, {failed_to_parse, _Spec}}},
                 rlx_cmd_args:args2state(Opts, Targets)).

config_fail_case(_Config) ->
    ConfigFile = "does-not-exist",
    CmdLine = ["-c", ConfigFile],
    {ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
    ?assertMatch({error, {_, {invalid_config_file, ConfigFile}}},
                 rlx_cmd_args:args2state(Opts, Targets)).