Przeglądaj źródła

release and tar tests

pull/167/head
Tristan Sloughter 10 lat temu
rodzic
commit
633dafafc3
5 zmienionych plików z 94 dodań i 9 usunięć
  1. +7
    -4
      src/rebar3.erl
  2. +5
    -2
      src/rebar_prv_release.erl
  3. +6
    -3
      src/rebar_prv_tar.erl
  4. +52
    -0
      test/rebar_release_SUITE.erl
  5. +24
    -0
      test/rebar_test_utils.erl

+ 7
- 4
src/rebar3.erl Wyświetl plik

@ -76,7 +76,8 @@ main(Args) ->
run(BaseState, Commands) -> run(BaseState, Commands) ->
_ = application:load(rebar), _ = application:load(rebar),
BaseState1 = rebar_state:set(BaseState, task, Commands), BaseState1 = rebar_state:set(BaseState, task, Commands),
run_aux(BaseState1, [], Commands).
BaseState2 = rebar_state:set(BaseState1, caller, api),
run_aux(BaseState2, [], Commands).
%% ==================================================================== %% ====================================================================
%% Internal functions %% Internal functions
@ -84,7 +85,9 @@ run(BaseState, Commands) ->
run(RawArgs) -> run(RawArgs) ->
_ = application:load(rebar), _ = application:load(rebar),
{GlobalPluginProviders, BaseConfig} = init_config(),
{GlobalPluginProviders, BaseState} = init_config(),
BaseState1 = rebar_state:set(BaseState, caller, command_line),
case erlang:system_info(version) of case erlang:system_info(version) of
"6.1" -> "6.1" ->
@ -94,8 +97,8 @@ run(RawArgs) ->
ok ok
end, end,
{BaseConfig1, _Args1} = set_options(BaseConfig, {[], []}),
run_aux(BaseConfig1, GlobalPluginProviders, RawArgs).
{BaseState2, _Args1} = set_options(BaseState1, {[], []}),
run_aux(BaseState2, GlobalPluginProviders, RawArgs).
run_aux(State, GlobalPluginProviders, RawArgs) -> run_aux(State, GlobalPluginProviders, RawArgs) ->
%% Make sure crypto is running %% Make sure crypto is running

+ 5
- 2
src/rebar_prv_release.erl Wyświetl plik

@ -32,6 +32,7 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) -> do(State) ->
Caller = rebar_state:get(State, caller, api),
Options = rebar_state:command_args(State), Options = rebar_state:command_args(State),
DepsDir = rebar_dir:deps_dir(State), DepsDir = rebar_dir:deps_dir(State),
LibDirs = rebar_utils:filtermap(fun ec_file:exists/1, LibDirs = rebar_utils:filtermap(fun ec_file:exists/1,
@ -42,11 +43,13 @@ do(State) ->
case rebar_state:get(State, relx, []) of case rebar_state:get(State, relx, []) of
[] -> [] ->
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{output_dir, OutputDir}], AllOptions);
,{output_dir, OutputDir}
,{caller, Caller}], AllOptions);
Config -> Config ->
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{config, Config} ,{config, Config}
,{output_dir, OutputDir}], AllOptions)
,{output_dir, OutputDir}
,{caller, Caller}], AllOptions)
end, end,
{ok, State} {ok, State}
catch catch

+ 6
- 3
src/rebar_prv_tar.erl Wyświetl plik

@ -32,6 +32,7 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) -> do(State) ->
Caller = rebar_state:get(State, caller, api),
Options = rebar_state:command_args(State), Options = rebar_state:command_args(State),
DepsDir = rebar_dir:deps_dir(State), DepsDir = rebar_dir:deps_dir(State),
LibDirs = rebar_utils:filtermap(fun ec_file:exists/1, LibDirs = rebar_utils:filtermap(fun ec_file:exists/1,
@ -40,12 +41,14 @@ do(State) ->
AllOptions = string:join(["release", "tar" | Options], " "), AllOptions = string:join(["release", "tar" | Options], " "),
case rebar_state:get(State, relx, []) of case rebar_state:get(State, relx, []) of
[] -> [] ->
relx:main([{lib_dirs, LibDirs
,{output_dir, OutputDir}}], AllOptions);
relx:main([{lib_dirs, LibDirs}
,{output_dir, OutputDir}
,{caller, Caller}], AllOptions);
Config -> Config ->
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{config, Config} ,{config, Config}
,{output_dir, OutputDir}], AllOptions)
,{output_dir, OutputDir}
,{caller, Caller}], AllOptions)
end, end,
{ok, State}. {ok, State}.

+ 52
- 0
test/rebar_release_SUITE.erl Wyświetl plik

@ -0,0 +1,52 @@
-module(rebar_release_SUITE).
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
all() -> [release, tar].
init_per_testcase(Case, Config0) ->
Config = rebar_test_utils:init_rebar_state(Config0),
Name = rebar_test_utils:create_random_name(atom_to_list(Case)),
AppDir = ?config(apps, Config),
application:load(rebar),
ok = ec_file:mkdir_p(AppDir),
State = rebar_state:new([{base_dir, filename:join([AppDir, "_build"])}]),
rebar_test_utils:create_app(AppDir, Name, "1.0.0", [kernel, stdlib]),
[{name, Name}, {apps, AppDir}, {state, State} | Config].
end_per_testcase(_, Config) ->
meck:unload(),
Config.
release(Config) ->
AppDir = ?config(apps, Config),
Name = ?config(name, Config),
Vsn = "1.0.0",
{ok, RebarConfig} =
file:consult(rebar_test_utils:create_config(AppDir,
[{relx, [{release, {list_to_atom(Name), Vsn},
[list_to_atom(Name)]},
{lib_dirs, [AppDir]}]}])),
rebar_test_utils:run_and_check(
Config, RebarConfig,
["release"],
{ok, [{release, list_to_atom(Name), Vsn}]}
).
tar(Config) ->
AppDir = ?config(apps, Config),
Name = ?config(name, Config),
Vsn = "1.0.0",
{ok, RebarConfig} =
file:consult(rebar_test_utils:create_config(AppDir,
[{relx, [{release, {list_to_atom(Name), Vsn},
[list_to_atom(Name)]},
{lib_dirs, [AppDir]}]}])),
rebar_test_utils:run_and_check(
Config, RebarConfig,
["tar"],
{ok, [{release, list_to_atom(Name), Vsn}, {tar, Name, Vsn}]}
).

+ 24
- 0
test/rebar_test_utils.erl Wyświetl plik

@ -115,6 +115,7 @@ check_results(AppDir, Expected) ->
DepsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Deps], DepsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Deps],
Checkouts = rebar_app_discover:find_apps([CheckoutsDir], all), Checkouts = rebar_app_discover:find_apps([CheckoutsDir], all),
CheckoutsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Checkouts], CheckoutsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Checkouts],
lists:foreach( lists:foreach(
fun({app, Name}) -> fun({app, Name}) ->
ct:pal("Name: ~p", [Name]), ct:pal("Name: ~p", [Name]),
@ -167,6 +168,29 @@ check_results(AppDir, Expected) ->
?assertEqual(iolist_to_binary(Vsn), ?assertEqual(iolist_to_binary(Vsn),
iolist_to_binary(LockVsn)) iolist_to_binary(LockVsn))
end end
; ({release, Name, Vsn}) ->
ct:pal("Release: ~p-~s", [Name, Vsn]),
{ok, Cwd} = file:get_cwd(),
try
file:set_cwd(AppDir),
ReleaseDir = filename:join([AppDir, "_build", "rel"]),
RelxState = rlx_state:new("", [], []),
RelxState1 = rlx_state:base_output_dir(RelxState, ReleaseDir),
{ok, RelxState2} = rlx_prv_app_discover:do(RelxState1),
{ok, RelxState3} = rlx_prv_rel_discover:do(RelxState2),
%% throws not_found if it doesn't exist
rlx_state:get_realized_release(RelxState3, Name, Vsn)
catch
_ ->
ct:fail(release_not_found)
after
file:set_cwd(Cwd)
end
; ({tar, Name, Vsn}) ->
ct:pal("Tarball: ~s-~s", [Name, Vsn]),
TarballWildcard = filename:join([AppDir, "**", Name++"-"++Vsn++".tar.gz"]),
?assertNotEqual([], filelib:wildcard(TarballWildcard))
end, Expected). end, Expected).
write_src_file(Dir, Name) -> write_src_file(Dir, Name) ->

Ładowanie…
Anuluj
Zapisz