summaryrefslogtreecommitdiff
path: root/test/rebar_utils_SUITE.erl
blob: 24e8afe3cddbd9f5a8c8f44b1b8e6d34d0cda121 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
-module(rebar_utils_SUITE).

-export([all/0,
         init_per_testcase/2,
         end_per_testcase/2,
         groups/0,
         init_per_group/2,
         end_per_group/2,
         empty_arglist/1,
         single_task/1,
         single_task_with_immediate_comma/1,
         single_task_with_trailing_comma/1,
         multiple_task/1,
         multiple_task_no_spaces/1,
         multiple_task_with_immediate_comma/1,
         multiple_task_with_trailing_comma/1,
         task_with_arg/1,
         task_with_arg_with_immediate_comma/1,
         task_with_arg_with_trailing_comma/1,
         task_with_multiple_args/1,
         task_with_flag/1,
         task_with_flag_with_immediate_comma/1,
         task_with_flag_with_trailing_comma/1,
         task_with_flag_with_commas/1,
         task_with_multiple_flags/1,
         special_task_do/1,
         valid_otp_version/1,
         valid_old_format_otp_version/1,
         valid_otp_version_equal/1,
         invalid_otp_version/1,
         nonblacklisted_otp_version/1,
         blacklisted_otp_version/1,
         sh_does_not_miss_messages/1]).

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

init_per_testcase(_, Config) ->
    rebar_test_utils:init_rebar_state(Config).

end_per_testcase(_, _Config) ->
    catch meck:unload().

all() ->
    [{group, args_to_tasks},
     sh_does_not_miss_messages].

groups() ->
    [{args_to_tasks, [], [empty_arglist,
                          single_task,
                          single_task_with_immediate_comma,
                          single_task_with_trailing_comma,
                          multiple_task,
                          multiple_task_no_spaces,
                          multiple_task_with_immediate_comma,
                          multiple_task_with_trailing_comma,
                          task_with_arg,
                          task_with_arg_with_immediate_comma,
                          task_with_arg_with_trailing_comma,
                          task_with_multiple_args,
                          task_with_flag,
                          task_with_flag_with_immediate_comma,
                          task_with_flag_with_trailing_comma,
                          task_with_flag_with_commas,
                          task_with_multiple_flags,
                          special_task_do,
                          valid_otp_version,
                          valid_old_format_otp_version,
                          valid_otp_version_equal,
                          invalid_otp_version,
                          nonblacklisted_otp_version,
                          blacklisted_otp_version
    ]}].

init_per_group(_, Config) -> Config.
end_per_group(_, Config) -> Config.

empty_arglist(_Config) ->
    [] = rebar_utils:args_to_tasks([]).

single_task(_Config) ->
    [{"foo", []}] = rebar_utils:args_to_tasks(["foo"]).

single_task_with_immediate_comma(_Config) ->
    [{"foo", []}] = rebar_utils:args_to_tasks(["foo,"]).

single_task_with_trailing_comma(_Config) ->
    [{"foo", []}] = rebar_utils:args_to_tasks(["foo", ","]).

multiple_task(_Config) ->
    [{"foo", []}, {"bar", []}, {"baz", []}] = rebar_utils:args_to_tasks(["foo,",
                                                                         "bar,",
                                                                         "baz"]).

multiple_task_no_spaces(_Config) ->
    [{"foo", []}, {"bar", []}, {"baz", []}] = rebar_utils:args_to_tasks(["foo,bar,baz"]).

multiple_task_with_immediate_comma(_Config) ->
    [{"foo", []}, {"bar", []}, {"baz", []}] = rebar_utils:args_to_tasks(["foo,",
                                                                         "bar,",
                                                                         "baz,"]).

multiple_task_with_trailing_comma(_Config) ->
    [{"foo", []}, {"bar", []}, {"baz", []}] = rebar_utils:args_to_tasks(["foo",
                                                                         ",",
                                                                         "bar",
                                                                         ",",
                                                                         "baz",
                                                                         ","]).
task_with_arg(_Config) ->
    [{"foo", ["bar"]}] = rebar_utils:args_to_tasks(["foo", "bar"]).

task_with_arg_with_immediate_comma(_Config) ->
    [{"foo", ["bar"]}, {"baz", []}] = rebar_utils:args_to_tasks(["foo", "bar,", "baz"]).

task_with_arg_with_trailing_comma(_Config) ->
    [{"foo", ["bar"]}, {"baz", []}] = rebar_utils:args_to_tasks(["foo", "bar", ",", "baz"]).

task_with_multiple_args(_Config) ->
    [{"foo", ["bar", "baz"]}] = rebar_utils:args_to_tasks(["foo", "bar", "baz"]).

task_with_flag(_Config) ->
    [{"foo", ["--bar"]}] = rebar_utils:args_to_tasks(["foo", "--bar"]).

task_with_flag_with_immediate_comma(_Config) ->
    [{"foo", ["--bar"]}, {"baz", []}] = rebar_utils:args_to_tasks(["foo", "--bar,", "baz"]).

task_with_flag_with_trailing_comma(_Config) ->
    [{"foo", ["--bar"]}, {"baz", []}] = rebar_utils:args_to_tasks(["foo", "--bar", ",", "baz"]).

task_with_flag_with_commas(_Config) ->
    [{"foo", ["--bar=baz,qux"]}] = rebar_utils:args_to_tasks(["foo", "--bar=baz,qux"]).

task_with_multiple_flags(_Config) ->
    [{"foo", ["--bar", "--baz"]}] = rebar_utils:args_to_tasks(["foo", "--bar", "--baz"]).

special_task_do(_Config) ->
    [{"foo", []}, {"do", ["bar,", "baz"]}] = rebar_utils:args_to_tasks(["foo,",
                                                                        "do",
                                                                        "bar,",
                                                                        "baz"]).

valid_otp_version(_Config) ->
    meck:new(rebar_utils, [passthrough]),
    meck:expect(rebar_utils, otp_release, fun() -> "42.4" end),
    rebar_utils:check_min_otp_version("42.3"),
    meck:unload(rebar_utils).

valid_old_format_otp_version(_Config) ->
    meck:new(rebar_utils, [passthrough]),
    meck:expect(rebar_utils, otp_release, fun() -> "R15B03-1" end),
    rebar_utils:check_min_otp_version("14"),

    meck:expect(rebar_utils, otp_release, fun() -> "R16B03" end),
    rebar_utils:check_min_otp_version("16.0"),

    meck:expect(rebar_utils, otp_release, fun() -> "18.0.1" end),
    rebar_utils:check_min_otp_version("17.5.4"),

    meck:expect(rebar_utils, otp_release, fun() -> "18.0-rc1" end),
    ?assertException(throw, rebar_abort, rebar_utils:check_min_otp_version("19")),

    meck:unload(rebar_utils).

valid_otp_version_equal(_Config) ->
    meck:new(rebar_utils, [passthrough]),
    meck:expect(rebar_utils, otp_release, fun() -> "42.3" end),
    rebar_utils:check_min_otp_version("42.3"),
    meck:unload(rebar_utils).

invalid_otp_version(_Config) ->
    meck:new(rebar_utils, [passthrough]),
    meck:expect(rebar_utils, otp_release, fun() -> "17.4" end),
    ?assertException(throw, rebar_abort, rebar_utils:check_min_otp_version("42.3")),
    meck:unload(rebar_utils).

nonblacklisted_otp_version(_Config) ->
    meck:new(rebar_utils, [passthrough]),
    meck:expect(rebar_utils, otp_release, fun() -> "42.4" end),
    rebar_utils:check_blacklisted_otp_versions(["1\\.2", "42\\.3"]),
    meck:unload(rebar_utils).

blacklisted_otp_version(_Config) ->
    meck:new(rebar_utils, [passthrough]),
    meck:expect(rebar_utils, otp_release, fun() -> "42.4" end),
    ?assertException(throw, rebar_abort, rebar_utils:check_blacklisted_otp_versions(["1\\.2", "42\\.[1-4]"])),
    meck:unload(rebar_utils).

sh_does_not_miss_messages(_Config) ->
    Source = "~nmain(_) ->~n io:format(\"donotmissme\").~n",
    file:write_file("do_not_miss_messages", io_lib:format(Source,[])),
    {ok, "donotmissme"} = rebar_utils:sh("escript do_not_miss_messages", []),
    AnyMessageRemained =
        receive
            What -> What
        after 100 ->
            false
        end,
    AnyMessageRemained = false.