summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mock_git_resource.erl11
-rw-r--r--test/rebar_ct_SUITE.erl90
-rw-r--r--test/rebar_deps_SUITE.erl112
-rw-r--r--test/rebar_dir_SUITE.erl36
-rw-r--r--test/rebar_dist_utils_SUITE.erl74
-rw-r--r--test/rebar_eunit_SUITE.erl43
-rw-r--r--test/rebar_hooks_SUITE.erl22
-rw-r--r--test/rebar_lock_SUITE.erl46
-rw-r--r--test/rebar_pkg_SUITE.erl9
-rw-r--r--test/rebar_plugins_SUITE.erl93
-rw-r--r--test/rebar_test_utils.erl29
11 files changed, 516 insertions, 49 deletions
diff --git a/test/mock_git_resource.erl b/test/mock_git_resource.erl
index 0f4aff6..e922af3 100644
--- a/test/mock_git_resource.erl
+++ b/test/mock_git_resource.erl
@@ -1,6 +1,6 @@
%%% Mock a git resource and create an app magically for each URL submitted.
-module(mock_git_resource).
--export([mock/0, mock/1, unmock/0]).
+-export([mock/0, mock/1, mock/2, unmock/0]).
-define(MOD, rebar_git_resource).
%%%%%%%%%%%%%%%%%
@@ -24,11 +24,14 @@ mock() -> mock([]).
| {pkg, App, term()},
Vsn :: string().
mock(Opts) ->
+ mock(Opts, create_app).
+
+mock(Opts, CreateType) ->
meck:new(?MOD, [no_link]),
mock_lock(Opts),
mock_update(Opts),
mock_vsn(Opts),
- mock_download(Opts),
+ mock_download(Opts, CreateType),
ok.
unmock() ->
@@ -98,7 +101,7 @@ mock_vsn(Opts) ->
%% `{deps, [{"app1", [{app2, ".*", {git, ...}}]}]}' -- basically
%% the `deps' option takes a key/value list of terms to output directly
%% into a `rebar.config' file to describe dependencies.
-mock_download(Opts) ->
+mock_download(Opts, CreateType) ->
Deps = proplists:get_value(deps, Opts, []),
Config = proplists:get_value(config, Opts, []),
Default = proplists:get_value(default_vsn, Opts, "0.0.0"),
@@ -110,7 +113,7 @@ mock_download(Opts) ->
{git, Url, {_, Vsn}} = normalize_git(Git, Overrides, Default),
App = app(Url),
AppDeps = proplists:get_value({App,Vsn}, Deps, []),
- rebar_test_utils:create_app(
+ rebar_test_utils:CreateType(
Dir, App, Vsn,
[kernel, stdlib] ++ [element(1,D) || D <- AppDeps]
),
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 94ab690..1da7571 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -6,8 +6,10 @@
end_per_group/2]).
-export([basic_app_default_dirs/1,
basic_app_default_beams/1,
+ basic_app_ct_macro/1,
multi_app_default_dirs/1,
multi_app_default_beams/1,
+ multi_app_ct_macro/1,
single_app_dir/1,
single_extra_dir/1,
single_unmanaged_dir/1,
@@ -38,9 +40,11 @@
cmd_multiply_timetraps/1,
cmd_scale_timetraps/1,
cmd_create_priv_dir/1,
+ cmd_include_dir/1,
cfg_opts/1,
cfg_arbitrary_opts/1,
cfg_test_spec/1,
+ cfg_cover_spec/1,
cfg_atom_suites/1,
cover_compiled/1,
misspecified_ct_opts/1,
@@ -56,16 +60,18 @@ all() -> [{group, basic_app},
{group, ct_opts},
{group, cover},
cfg_opts, cfg_arbitrary_opts,
- cfg_test_spec,
+ cfg_test_spec, cfg_cover_spec,
cfg_atom_suites,
misspecified_ct_opts,
misspecified_ct_compile_opts,
misspecified_ct_first_files].
groups() -> [{basic_app, [], [basic_app_default_dirs,
- basic_app_default_beams]},
+ basic_app_default_beams,
+ basic_app_ct_macro]},
{multi_app, [], [multi_app_default_dirs,
- multi_app_default_beams]},
+ multi_app_default_beams,
+ multi_app_ct_macro]},
{dirs_and_suites, [], [single_app_dir,
single_extra_dir,
single_unmanaged_dir,
@@ -95,7 +101,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
cmd_abort_if_missing_suites,
cmd_multiply_timetraps,
cmd_scale_timetraps,
- cmd_create_priv_dir]},
+ cmd_create_priv_dir,
+ cmd_include_dir]},
{cover, [], [cover_compiled]}].
init_per_group(basic_app, Config) ->
@@ -118,7 +125,7 @@ init_per_group(basic_app, Config) ->
{ok, T} = Tests,
Opts = rebar_prv_common_test:translate_paths(NewState, T),
- [{result, Opts}, {appnames, [Name]}|C];
+ [{result, Opts}, {appnames, [Name]}, {compile_state, NewState}|C];
init_per_group(multi_app, Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_"),
@@ -153,7 +160,7 @@ init_per_group(multi_app, Config) ->
{ok, T} = Tests,
Opts = rebar_prv_common_test:translate_paths(NewState, T),
- [{result, Opts}, {appnames, [Name1, Name2]}|C];
+ [{result, Opts}, {appnames, [Name1, Name2]}, {compile_state, NewState}|C];
init_per_group(dirs_and_suites, Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_"),
@@ -211,7 +218,7 @@ init_per_group(ct_opts, Config) ->
{ok, State} = rebar_test_utils:run_and_check(C, [], ["as", "test", "lock"], return),
- [{result, State}|C];
+ [{result, State}, {name, Name}|C];
init_per_group(cover, Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_opts"),
@@ -252,6 +259,15 @@ basic_app_default_beams(Config) ->
true = filelib:is_file(File).
+basic_app_ct_macro(Config) ->
+ State = ?config(compile_state, Config),
+
+ [App] = rebar_state:project_apps(State),
+ Opts = rebar_app_info:opts(App),
+ ErlOpts = dict:fetch(erl_opts, Opts),
+ true = lists:member({d, 'COMMON_TEST'}, ErlOpts).
+
+
multi_app_default_dirs(Config) ->
AppDir = ?config(apps, Config),
[Name1, Name2] = ?config(appnames, Config),
@@ -293,6 +309,16 @@ multi_app_default_beams(Config) ->
true = filelib:is_file(File2),
true = filelib:is_file(File3).
+multi_app_ct_macro(Config) ->
+ State = ?config(compile_state, Config),
+
+ Apps = rebar_state:project_apps(State),
+ lists:foreach(fun(App) ->
+ Opts = rebar_app_info:opts(App),
+ ErlOpts = dict:fetch(erl_opts, Opts),
+ true = lists:member({d, 'COMMON_TEST'}, ErlOpts)
+ end, Apps).
+
single_app_dir(Config) ->
AppDir = ?config(apps, Config),
[Name1, _Name2] = ?config(appnames, Config),
@@ -700,7 +726,6 @@ suite_at_app_root(Config) ->
data_dir_correct(Config) ->
DataDir = ?config(data_dir, Config),
Parts = filename:split(DataDir),
- ct:pal(Parts),
["rebar_ct_SUITE_data","test","rebar","lib","test","_build"|_] = lists:reverse(Parts).
cmd_label(Config) ->
@@ -973,6 +998,29 @@ cmd_create_priv_dir(Config) ->
true = lists:member({create_priv_dir, manual_per_tc}, TestOpts).
+cmd_include_dir(Config) ->
+ State = ?config(result, Config),
+ AppDir = ?config(apps, Config),
+
+ Providers = rebar_state:providers(State),
+ Namespace = rebar_state:namespace(State),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--include=foo/bar/baz,qux"]),
+
+ NewState = rebar_state:command_parsed_args(State, GetOptResult),
+
+ Tests = rebar_prv_common_test:prepare_tests(NewState),
+ {ok, _} = rebar_prv_common_test:compile(NewState, Tests),
+
+ Name = ?config(name, Config),
+ Beam = filename:join([AppDir, "_build", "test", "lib", Name, "ebin", Name ++ ".beam"]),
+
+ {ok, {_, [{compile_info, Info}]}} = beam_lib:chunks(Beam, [compile_info]),
+ CompileOpts = proplists:get_value(options, Info),
+ true = lists:member({i, "foo/bar/baz"}, CompileOpts),
+ true = lists:member({i, "qux"}, CompileOpts).
+
cfg_opts(Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_opts_"),
@@ -1020,13 +1068,30 @@ cfg_test_spec(Config) ->
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
- RebarConfig = [{ct_opts, [{test_spec, "spec/foo.spec"}]}],
+ RebarConfig = [{ct_opts, [Opt = {test_spec, "spec/foo.spec"}]}],
{ok, State} = rebar_test_utils:run_and_check(C, RebarConfig, ["as", "test", "lock"], return),
- {error, {rebar_prv_common_test, Error}} = rebar_prv_common_test:prepare_tests(State),
+ {ok, TestOpts} = rebar_prv_common_test:prepare_tests(State),
+
+ false = lists:member(Opt, TestOpts).
+
+cfg_cover_spec(Config) ->
+ C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_cover_spec_opts_"),
+
+ AppDir = ?config(apps, C),
- {badconfig, "Test specs not supported"} = Error.
+ Name = rebar_test_utils:create_random_name("ct_cfg_cover_spec_opts_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig = [{ct_opts, [Opt = {cover, "spec/foo.spec"}]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(C, RebarConfig, ["as", "test", "lock"], return),
+
+ {ok, TestOpts} = rebar_prv_common_test:prepare_tests(State),
+
+ false = lists:member(Opt, TestOpts).
cfg_atom_suites(Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_atom_suites_"),
@@ -1116,9 +1181,10 @@ misspecified_ct_first_files(Config) ->
{badconfig, {"Value `~p' of option `~p' must be a list", {some_file, ct_first_files}}} = Error.
+
%% helper for generating test data
test_suite(Name) ->
io_lib:format("-module(~ts_SUITE).\n"
"-compile(export_all).\n"
"all() -> [some_test].\n"
- "some_test(_) -> ok.\n", [Name]). \ No newline at end of file
+ "some_test(_) -> ok.\n", [Name]).
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl
index fcc46c3..c95854a 100644
--- a/test/rebar_deps_SUITE.erl
+++ b/test/rebar_deps_SUITE.erl
@@ -3,7 +3,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, {group, git}, {group, pkg}].
+all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, semver_matching_lt, semver_matching_lte, semver_matching_gt, valid_version, {group, git}, {group, pkg}].
groups() ->
[{all, [], [flat, pick_highest_left, pick_highest_right,
@@ -29,6 +29,14 @@ init_per_group(_, Config) ->
end_per_group(_, Config) ->
Config.
+init_per_testcase(valid_version, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(semver_matching_lt, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(semver_matching_lte, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(semver_matching_gt, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
init_per_testcase(newly_added_after_empty_lock, Config) ->
rebar_test_utils:init_rebar_state(Config);
init_per_testcase(newly_added_dep, Config) ->
@@ -49,14 +57,14 @@ init_per_testcase(http_proxy_settings, Config) ->
%% Insert proxy variables into config
rebar_test_utils:create_config(GlobalConfigDir,
[{http_proxy, "http://localhost:1234"}
- ]),
+ ]),
rebar_test_utils:init_rebar_state(Config);
init_per_testcase(https_proxy_settings, Config) ->
SupportsHttpsProxy = case erlang:system_info(otp_release) of
- "R16"++_ -> true;
- "R"++_ -> false;
- _ -> true % 17 and up don't have a "R" in the version
- end,
+ "R16"++_ -> true;
+ "R"++_ -> false;
+ _ -> true % 17 and up don't have a "R" in the version
+ end,
if not SupportsHttpsProxy ->
{skip, https_proxy_unsupported_before_R16};
SupportsHttpsProxy ->
@@ -73,20 +81,20 @@ init_per_testcase(https_proxy_settings, Config) ->
%% Insert proxy variables into config
rebar_test_utils:create_config(GlobalConfigDir,
[{https_proxy, "http://localhost:1234"}
- ]),
+ ]),
rebar_test_utils:init_rebar_state(Config)
end;
init_per_testcase(Case, Config) ->
{Deps, Warnings, Expect} = deps(Case),
Expected = case Expect of
- {ok, List} -> {ok, format_expected_deps(List)};
- {error, Reason} -> {error, Reason}
- end,
+ {ok, List} -> {ok, format_expected_deps(List)};
+ {error, Reason} -> {error, Reason}
+ end,
DepsType = ?config(deps_type, Config),
mock_warnings(),
[{expect, Expected},
{warnings, Warnings}
- | setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))].
+ | setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))].
end_per_testcase(https_proxy_settings, Config) ->
meck:unload(rebar_dir),
@@ -100,8 +108,8 @@ end_per_testcase(_, Config) ->
format_expected_deps(Deps) ->
[case Dep of
- {N,V} -> {dep, N, V};
- N -> {dep, N}
+ {N,V} -> {dep, N, V};
+ N -> {dep, N}
end || Dep <- Deps].
%% format:
@@ -208,7 +216,7 @@ sub_app_deps(Config) ->
SubAppsDir = filename:join([AppDir, "apps", Name]),
SubDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
- ,{"b", "2.0.0", []}])),
+ ,{"b", "2.0.0", []}])),
rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
rebar_test_utils:create_config(SubAppsDir, [{deps, SubDeps}]),
@@ -242,12 +250,12 @@ newly_added_dep(Config) ->
%% Add a and c to top level
TopDeps2 = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
- ,{"c", "2.0.0", []}
- ,{"b", "1.0.0", []}])),
+ ,{"c", "2.0.0", []}
+ ,{"b", "1.0.0", []}])),
{ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])),
LockFile = filename:join(AppDir, "rebar.lock"),
RebarConfig3 = rebar_config:merge_locks(RebarConfig2,
- rebar_config:consult_lock_file(LockFile)),
+ rebar_config:consult_lock_file(LockFile)),
%% a should now be installed and c should not change
rebar_test_utils:run_and_check(
@@ -277,7 +285,7 @@ newly_added_after_empty_lock(Config) ->
{ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])),
LockFile = filename:join(AppDir, "rebar.lock"),
RebarConfig3 = rebar_config:merge_locks(RebarConfig2,
- rebar_config:consult_lock_file(LockFile)),
+ rebar_config:consult_lock_file(LockFile)),
%% a should now be installed and c should not change
rebar_test_utils:run_and_check(
@@ -304,6 +312,74 @@ https_proxy_settings(_Config) ->
httpc:get_option(https_proxy, rebar)).
+semver_matching_lt(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
+ ?assertEqual([{Dep, <<"0.1.9">>}],
+ rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:lt/2)).
+
+semver_matching_lte(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
+ ?assertEqual([{Dep, <<"0.2.0">>}],
+ rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:lte/2)).
+
+semver_matching_gt(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
+ ?assertEqual([{Dep, <<"0.2.1">>}],
+ rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:gt/2)).
+semver_matching_gte(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>],
+ ?assertEqual([{Dep, <<"0.2.0">>}],
+ rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:gt/2)).
+
+valid_version(_Config) ->
+ ?assert(rebar_prv_update:valid_vsn(<<"0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<=0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<=0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">=0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">=0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"==0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"==0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~>0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~>0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
+ ?assertNot(rebar_prv_update:valid_vsn(<<"> 0.1.0 and < 0.2.0">>)),
+ ok.
+
+
run(Config) ->
{ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
rebar_test_utils:run_and_check(
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 1221db7..9734830 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -6,6 +6,7 @@
-export([src_dirs/1, extra_src_dirs/1, all_src_dirs/1]).
-export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]).
-export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]).
+-export([global_cache_dir/1, default_global_cache_dir/1, overwrite_default_global_cache_dir/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -15,8 +16,20 @@
all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
src_dirs, extra_src_dirs, all_src_dirs,
profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs,
- retarget_path, alt_base_dir_abs, alt_base_dir_rel].
-
+ retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir,
+ default_global_cache_dir, overwrite_default_global_cache_dir].
+
+init_per_testcase(default_global_cache_dir, Config) ->
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
+ NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
+init_per_testcase(overwrite_default_global_cache_dir, Config) ->
+ os:putenv("REBAR_CACHE_DIR", ?config(priv_dir, Config)),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
+ NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
init_per_testcase(_, Config) ->
C = rebar_test_utils:init_rebar_state(Config),
AppDir = ?config(apps, C),
@@ -162,3 +175,22 @@ alt_base_dir_rel(Config) ->
?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
+
+global_cache_dir(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ DataDir = ?config(priv_dir, Config),
+ Expected = filename:join([DataDir, "cache"]),
+ ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
+
+default_global_cache_dir(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ Expected = filename:join([rebar_dir:home_dir(), ".cache", "rebar3"]),
+ ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
+
+overwrite_default_global_cache_dir(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ Expected = ?config(priv_dir, Config),
+ ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
diff --git a/test/rebar_dist_utils_SUITE.erl b/test/rebar_dist_utils_SUITE.erl
new file mode 100644
index 0000000..e190b94
--- /dev/null
+++ b/test/rebar_dist_utils_SUITE.erl
@@ -0,0 +1,74 @@
+%%% This suite currently only tests for options parsing since we do
+%%% not know if epmd will be running to actually boot nodes.
+-module(rebar_dist_utils_SUITE).
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+-compile(export_all).
+
+all() -> [from_config, from_cli, overlap, from_config_profile].
+
+init_per_testcase(_, Config0) ->
+ Config = rebar_test_utils:init_rebar_state(Config0),
+ AppDir = ?config(apps, Config),
+ Name = rebar_test_utils:create_random_name("app_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(filename:join([AppDir,"apps",Name]), Name, Vsn, [kernel, stdlib]),
+ Config.
+
+
+end_per_testcase(_, _) ->
+ ok.
+
+from_config(Config) ->
+ ShortConfig = [{dist_node, [{sname, 'a@localhost'}, {setcookie, abc}]}],
+ LongConfig = [{dist_node, [{name, 'a@localhost.x'}, {setcookie, abc}]}],
+ BothConfig = [{dist_node, [{sname, 'a@localhost'}, {name, 'a@localhost.x'}, {setcookie,abc}]}],
+ NoConfig = [],
+ CookieConfig = [{dist_node, [{setcookie, def}]}],
+ NoCookie = [{dist_node, [{sname, 'a@localhost'}]}],
+ {ok, State0} = rebar_test_utils:run_and_check(Config, ShortConfig, ["version"], return),
+ {undefined, 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State0),
+ {ok, State1} = rebar_test_utils:run_and_check(Config, LongConfig, ["version"], return),
+ {'a@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State1),
+ %% only support the first name found, side-effect of wanting profile support
+ {ok, State2} = rebar_test_utils:run_and_check(Config, BothConfig, ["version"], return),
+ {undefined, 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State2),
+ {ok, State3} = rebar_test_utils:run_and_check(Config, NoConfig, ["version"], return),
+ {undefined, undefined, []} = rebar_dist_utils:find_options(State3),
+ {ok, State4} = rebar_test_utils:run_and_check(Config, CookieConfig, ["version"], return),
+ {undefined, undefined, [{setcookie, def}]} = rebar_dist_utils:find_options(State4),
+ {ok, State5} = rebar_test_utils:run_and_check(Config, NoCookie, ["version"], return),
+ {undefined, 'a@localhost', []} = rebar_dist_utils:find_options(State5),
+ ok.
+
+from_cli(Config) ->
+ {ok, State0} = rebar_test_utils:run_and_check(Config, [], ["version"], return),
+ {undefined, undefined, []} = rebar_dist_utils:find_options(State0),
+ State1 = rebar_state:command_parsed_args(State0, {[{sname, 'a@localhost'}, {setcookie,abc}], []}),
+ {undefined, 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State1),
+ State2 = rebar_state:command_parsed_args(State0, {[{name, 'a@localhost.x'}, {setcookie,abc}], []}),
+ {'a@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State2),
+ State3 = rebar_state:command_parsed_args(State0, {[{sname, 'a@localhost'}, {name, 'a@localhost.x'}, {setcookie,abc}], []}),
+ {'a@localhost.x', 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State3),
+ State4 = rebar_state:command_parsed_args(State0, {[{setcookie,def}], []}),
+ {undefined, undefined, [{setcookie, def}]} = rebar_dist_utils:find_options(State4),
+ State5 = rebar_state:command_parsed_args(State0, {[{sname, 'a@localhost'}], []}),
+ {undefined, 'a@localhost', []} = rebar_dist_utils:find_options(State5),
+ ok.
+
+overlap(Config) ->
+ %% Make sure that CLI config takes over rebar config without clash for names, though
+ %% cookies can pass through
+ RebarConfig = [{dist_node, [{sname, 'a@localhost'}, {setcookie, abc}]}],
+ {ok, State0} = rebar_test_utils:run_and_check(Config, RebarConfig, ["version"], return),
+ State1 = rebar_state:command_parsed_args(State0, {[{name, 'b@localhost.x'}], []}),
+ {'b@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State1),
+ ok.
+
+from_config_profile(Config) ->
+ %% running as a profile does not create name clashes
+ RebarConfig = [{dist_node, [{sname, 'a@localhost'}, {setcookie, abc}]},
+ {profiles, [ {fake, [{dist_node, [{name, 'a@localhost.x'}]}]} ]}],
+ {ok, State0} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as","fake","version"], return),
+ {'a@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State0),
+ ok.
diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl
index cb2c911..41ab6ff 100644
--- a/test/rebar_eunit_SUITE.erl
+++ b/test/rebar_eunit_SUITE.erl
@@ -2,8 +2,12 @@
-export([all/0, groups/0]).
-export([init_per_suite/1, init_per_group/2, end_per_group/2]).
--export([basic_app_compiles/1, basic_app_files/1, basic_app_exports/1, basic_app_testset/1]).
--export([multi_app_compiles/1, multi_app_files/1, multi_app_exports/1, multi_app_testset/1]).
+-export([basic_app_compiles/1, basic_app_files/1]).
+-export([basic_app_exports/1, basic_app_testset/1]).
+-export([basic_app_eunit_macro/1]).
+-export([multi_app_compiles/1, multi_app_files/1]).
+-export([multi_app_exports/1, multi_app_testset/1]).
+-export([multi_app_eunit_macro/1]).
-export([eunit_tests/1, eunit_opts/1, eunit_first_files/1]).
-export([single_application_arg/1, multi_application_arg/1, missing_application_arg/1]).
-export([single_module_arg/1, multi_module_arg/1, missing_module_arg/1]).
@@ -27,9 +31,15 @@ all() ->
groups() ->
[{basic_app, [sequence], [basic_app_compiles, {group, basic_app_results}]},
- {basic_app_results, [], [basic_app_files, basic_app_exports, basic_app_testset]},
+ {basic_app_results, [], [basic_app_files,
+ basic_app_exports,
+ basic_app_testset,
+ basic_app_eunit_macro]},
{multi_app, [sequence], [multi_app_compiles, {group, multi_app_results}]},
- {multi_app_results, [], [multi_app_files, multi_app_exports, multi_app_testset]},
+ {multi_app_results, [], [multi_app_files,
+ multi_app_exports,
+ multi_app_testset,
+ multi_app_eunit_macro]},
{cmd_line_args, [], [eunit_tests, eunit_opts, eunit_first_files,
single_application_arg, multi_application_arg, missing_application_arg,
single_module_arg, multi_module_arg, missing_module_arg,
@@ -160,7 +170,16 @@ basic_app_testset(Config) ->
{module, basic_app_tests_helper}]},
Set = rebar_prv_eunit:prepare_tests(Result).
-
+basic_app_eunit_macro(_Config) ->
+ Macro = fun(Mod) ->
+ begin
+ Path = code:which(Mod),
+ {ok, {Mod, [{compile_info, CompileInfo}]}} = beam_lib:chunks(Path, [compile_info]),
+ Opts = proplists:get_value(options, CompileInfo, []),
+ true = lists:member({d, 'EUNIT'}, Opts)
+ end
+ end,
+ lists:foreach(Macro, [basic_app, basic_app_tests, basic_app_tests_helper]).
%% === tests for multiple applications in the `apps' directory of a project ===
@@ -220,7 +239,19 @@ multi_app_testset(Config) ->
{module, multi_app_tests_helper}]},
Set = rebar_prv_eunit:prepare_tests(Result).
-
+multi_app_eunit_macro(_Config) ->
+ Macro = fun(Mod) ->
+ begin
+ Path = code:which(Mod),
+ {ok, {Mod, [{compile_info, CompileInfo}]}} = beam_lib:chunks(Path, [compile_info]),
+ Opts = proplists:get_value(options, CompileInfo, []),
+ true = lists:member({d, 'EUNIT'}, Opts)
+ end
+ end,
+ lists:foreach(Macro, [multi_app_bar, multi_app_bar_tests,
+ multi_app_baz, multi_app_baz_tests,
+ multi_app_tests, multi_app_tests_helper,
+ multi_app_bar_tests_helper, multi_app_baz_tests_helper]).
%% === tests for command line arguments ===
diff --git a/test/rebar_hooks_SUITE.erl b/test/rebar_hooks_SUITE.erl
index 188fb34..b121dd5 100644
--- a/test/rebar_hooks_SUITE.erl
+++ b/test/rebar_hooks_SUITE.erl
@@ -10,6 +10,7 @@
escriptize_artifacts/1,
run_hooks_once/1,
run_hooks_for_plugins/1,
+ eunit_app_hooks/1,
deps_hook_namespace/1]).
-include_lib("common_test/include/ct.hrl").
@@ -33,7 +34,7 @@ end_per_testcase(_, _Config) ->
all() ->
[build_and_clean_app, run_hooks_once, escriptize_artifacts,
- run_hooks_for_plugins, deps_hook_namespace].
+ run_hooks_for_plugins, deps_hook_namespace, eunit_app_hooks].
%% Test post provider hook cleans compiled project app, leaving it invalid
build_and_clean_app(Config) ->
@@ -119,6 +120,25 @@ deps_hook_namespace(Config) ->
{ok, [{dep, "some_dep"}]}
).
+%% Checks that a hook that is defined on an app (not a top level hook of a project with subapps) is run
+eunit_app_hooks(Config) ->
+ AppDir = ?config(apps, Config),
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RConfFile =
+ rebar_test_utils:create_config(AppDir,
+ [
+ {escript_name, list_to_atom(Name)}
+ ,{provider_hooks, [{post, [{eunit, escriptize}]}]}
+ ]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ rebar_test_utils:run_and_check(Config, RConf,
+ ["eunit"], {ok, [{app, Name, valid}
+ ,{file, filename:join([AppDir, "_build/test/bin", Name])}]}).
+
run_hooks_for_plugins(Config) ->
AppDir = ?config(apps, Config),
diff --git a/test/rebar_lock_SUITE.erl b/test/rebar_lock_SUITE.erl
new file mode 100644
index 0000000..00875f7
--- /dev/null
+++ b/test/rebar_lock_SUITE.erl
@@ -0,0 +1,46 @@
+%%% Most locking tests are implicit in other test suites handling
+%%% dependencies.
+%%% This suite is to test the compatibility layers between various
+%%% versions of lockfiles.
+-module(rebar_lock_SUITE).
+-compile(export_all).
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+all() -> [current_version, future_versions_no_attrs, future_versions_attrs].
+
+current_version(Config) ->
+ %% Current version just dumps the locks as is on disk.
+ LockFile = filename:join(?config(priv_dir, Config), "current_version"),
+ Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
+ {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
+ {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
+ {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
+ file:write_file(LockFile, io_lib:format("~p.~n", [Locks])),
+ ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)).
+
+future_versions_no_attrs(Config) ->
+ %% Future versions will keep the same core attribute in there, but
+ %% will do so under a new format bundled with a version and potentially
+ %% some trailing attributes
+ LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
+ Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
+ {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
+ {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
+ {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
+ LockData = {"3.5.2", Locks},
+ file:write_file(LockFile, io_lib:format("~p.~n", [LockData])),
+ ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)).
+
+future_versions_attrs(Config) ->
+ %% Future versions will keep the same core attribute in there, but
+ %% will do so under a new format bundled with a version and potentially
+ %% some trailing attributes
+ LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
+ Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
+ {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
+ {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
+ {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
+ LockData = {"3.5.2", Locks},
+ file:write_file(LockFile, io_lib:format("~p.~na.~n{b,c}.~n[d,e,f].~n", [LockData])),
+ ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)).
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index 9f19e0d..6a75f32 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -180,11 +180,14 @@ pkgs_provider(Config) ->
find_highest_matching(_Config) ->
State = rebar_state:new(),
- {ok, Vsn} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0.0">>, package_index, State),
+ {ok, Vsn} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"1.0.0">>, package_index, State),
?assertEqual(<<"1.0.1">>, Vsn),
- {ok, Vsn1} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0">>, package_index, State),
+ {ok, Vsn1} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"1.0">>, package_index, State),
?assertEqual(<<"1.1.1">>, Vsn1),
- {ok, Vsn2} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"2.0">>, package_index, State),
+ {ok, Vsn2} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"2.0">>, package_index, State),
?assertEqual(<<"2.0.0">>, Vsn2).
diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl
index c1a98de..a313683 100644
--- a/test/rebar_plugins_SUITE.erl
+++ b/test/rebar_plugins_SUITE.erl
@@ -11,8 +11,10 @@
complex_plugins/1,
list/1,
upgrade/1,
+ upgrade_project_plugin/1,
sub_app_plugins/1,
- sub_app_plugin_overrides/1]).
+ sub_app_plugin_overrides/1,
+ project_plugins/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -34,7 +36,8 @@ end_per_testcase(_, _Config) ->
catch meck:unload().
all() ->
- [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins, sub_app_plugin_overrides].
+ [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, upgrade_project_plugin,
+ sub_app_plugins, sub_app_plugin_overrides, project_plugins].
%% Tests that compiling a project installs and compiles the plugins of deps
compile_plugins(Config) ->
@@ -211,6 +214,45 @@ upgrade(Config) ->
{ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]}
).
+upgrade_project_plugin(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ PkgName = rebar_test_utils:create_random_name("pkg1_"),
+ mock_git_resource:mock([]),
+ mock_pkg_resource:mock([
+ {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
+ {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
+ {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
+ ]),
+
+ RConfFile = rebar_test_utils:create_config(AppDir, [{project_plugins, [list_to_atom(PkgName)]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name}, {plugin, PkgName, <<"0.1.1">>}]}
+ ),
+
+ catch mock_pkg_resource:unmock(),
+ mock_pkg_resource:mock([
+ {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
+ {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
+ {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
+ {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]},
+ {upgrade, [PkgName]}
+ ]),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ Config, RConf, ["plugins", "upgrade", PkgName],
+ {ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]}
+ ).
+
sub_app_plugins(Config) ->
AppDir = ?config(apps, Config),
@@ -281,3 +323,50 @@ sub_app_plugin_overrides(Config) ->
Config, RConf, ["compile"],
{ok, [{app, Name}, {dep, Dep2Name, Vsn}, {plugin, DepName, Vsn2}, {plugin, PluginName}]}
).
+
+%% Check that project plugins are first in providers even if they override defaults but that
+%% normal plugins do not
+project_plugins(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ DepName = rebar_test_utils:create_random_name("dep1_"),
+ PluginName = "compile",
+ PluginName2 = "release",
+
+ Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}, {PluginName2, Vsn, []}]),
+ {SrcDeps, _} = rebar_test_utils:flat_deps(Plugins),
+ mock_git_resource:mock([{deps, SrcDeps}], create_plugin),
+
+ mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
+ {config, [{plugins, [
+ {list_to_atom(PluginName),
+ {git, "http://site.com/user/"++PluginName++".git",
+ {tag, Vsn}}}]}]}]),
+
+ RConfFile =
+ rebar_test_utils:create_config(AppDir,
+ [{deps, [
+ list_to_atom(DepName)
+ ]},
+ {project_plugins, [
+ {list_to_atom(PluginName2),
+ {git, "http://site.com/user/"++PluginName2++".git",
+ {tag, Vsn}}}]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ {ok, State} = rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name}, {plugin, PluginName}, {plugin, PluginName2}, {dep, DepName}]}
+ ),
+
+ %% Should have 2 release providers but only 1 compile provider
+ Release = [P || P <- rebar_state:providers(State), providers:impl(P) =:= release, providers:namespace(P) =:= default],
+ Compile = [P || P <- rebar_state:providers(State), providers:impl(P) =:= compile, providers:namespace(P) =:= default],
+
+ ?assertEqual(length(Release), 2),
+ ?assertEqual(length(Compile), 1).
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 5187bda..23b0178 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -3,7 +3,7 @@
-include_lib("eunit/include/eunit.hrl").
-export([init_rebar_state/1, init_rebar_state/2, run_and_check/4, check_results/3]).
-export([expand_deps/2, flat_deps/1, top_level_deps/1]).
--export([create_app/4, create_eunit_app/4, create_empty_app/4,
+-export([create_app/4, create_plugin/4, create_eunit_app/4, create_empty_app/4,
create_config/2, create_config/3, package_app/3]).
-export([create_random_name/1, create_random_vsn/0, write_src_file/2]).
@@ -82,6 +82,16 @@ create_app(AppDir, Name, Vsn, Deps) ->
write_app_src_file(AppDir, Name, Vsn, Deps),
rebar_app_info:new(Name, Vsn, AppDir, Deps).
+%% @doc Creates a dummy plugin including:
+%% - src/<file>.erl
+%% - src/<file>.app.src
+%% And returns a `rebar_app_info' object.
+create_plugin(AppDir, Name, Vsn, Deps) ->
+ write_plugin_file(AppDir, Name ++ ".erl"),
+ write_src_file(AppDir, "not_a_real_src_" ++ Name ++ ".erl"),
+ write_app_src_file(AppDir, Name, Vsn, Deps),
+ rebar_app_info:new(Name, Vsn, AppDir, Deps).
+
%% @doc Creates a dummy application including:
%% - src/<file>.erl
%% - src/<file>.app.src
@@ -365,6 +375,11 @@ check_results(AppDir, Expected, ProfileRun) ->
?assert(filelib:is_dir(Dirname))
end, Expected).
+write_plugin_file(Dir, Name) ->
+ Erl = filename:join([Dir, "src", Name]),
+ ok = filelib:ensure_dir(Erl),
+ ok = ec_file:write(Erl, plugin_src_file(Name)).
+
write_src_file(Dir, Name) ->
Erl = filename:join([Dir, "src", Name]),
ok = filelib:ensure_dir(Erl),
@@ -395,6 +410,18 @@ erl_src_file(Name) ->
"-export([main/0]).\n"
"main() -> ok.\n", [filename:basename(Name, ".erl")]).
+plugin_src_file(Name) ->
+ io_lib:format("-module('~s').\n"
+ "-export([init/1]).\n"
+ "init(State) -> \n"
+ "Provider = providers:create([\n"
+ "{name, '~s'},\n"
+ "{module, '~s'}\n"
+ "]),\n"
+ "{ok, rebar_state:add_provider(State, Provider)}.\n", [filename:basename(Name, ".erl"),
+ filename:basename(Name, ".erl"),
+ filename:basename(Name, ".erl")]).
+
erl_eunitized_src_file(Name) ->
io_lib:format("-module('~s').\n"
"-export([main/0]).\n"