1%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
2%% ex: ts=4 sw=4 et
3%% -------------------------------------------------------------------
4%%
5%% rebar: Erlang Build Tools
6%%
7%% Copyright (c) 2015 Luis Rascao (luis.rascao@gmail.com)
8%%
9%% Permission is hereby granted, free of charge, to any person obtaining a copy
10%% of this software and associated documentation files (the "Software"), to deal
11%% in the Software without restriction, including without limitation the rights
12%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13%% copies of the Software, and to permit persons to whom the Software is
14%% furnished to do so, subject to the following conditions:
15%%
16%% The above copyright notice and this permission notice shall be included in
17%% all copies or substantial portions of the Software.
18%%
19%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25%% THE SOFTWARE.
26%% -------------------------------------------------------------------
27-module(appup_src_rt).
28
29-compile(export_all).
30
31-include_lib("eunit/include/eunit.hrl").
32
33setup([Target]) ->
34  retest_utils:load_module(filename:join(Target, "inttest_utils.erl")),
35  ok.
36
37files() ->
38    [
39     {copy, "src", "src"}
40    ] ++ inttest_utils:rebar_setup().
41
42run(Dir) ->
43    retest_log:log(debug, "Running in Dir: ~s~n", [Dir]),
44    {ok, [_Pid|Output]} = retest:sh("./rebar compile -vv",
45                                    [{async, false}]),
46
47    LineRegexp = "Compiled src/app\.appup\.src",
48    ?assertEqual(true, has_line(Output, LineRegexp)),
49
50    %% check that ebin/app.appup exists
51    ?assertMatch(true, filelib:is_regular("ebin/app.appup")),
52    retest_log:log(debug, "Generated ebin/app.appup~n", []),
53
54    %% check that ebin/app.appup has expected version
55    {ok, [{AppVersion, [{UpgradeFrom, _} |  _UpgradeFromRest], [{DowngradeTo, _} | _DowngradeToRest]}]} =
56        file:consult("ebin/app.appup"),
57    ?assertEqual(AppVersion, "%VSN%"),
58    ?assertEqual(UpgradeFrom, "1.3"),
59    ?assertEqual(DowngradeTo, "1.3"),
60    ok.
61
62has_line([], _RE) ->
63    false;
64has_line([L|T], RE) ->
65    case re:run(L, RE, []) of
66        {match, _Captured} ->
67            true;
68        match ->
69            true;
70        nomatch ->
71            has_line(T, RE)
72    end.
73