summaryrefslogtreecommitdiff
path: root/test/rebar_alias_SUITE.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-12-05 07:47:07 -0500
committerFred Hebert <mononcqc@ferd.ca>2017-12-05 07:57:40 -0500
commit553a579b36fe0fb4a8bf464cd282d43c07d4e192 (patch)
tree92a62624f4be249cd583ea1f3c33145641087e09 /test/rebar_alias_SUITE.erl
parent46ea7e1e8f700d92947a0a9d8bfb0fb43b122a66 (diff)
Alias plugin promoted to built-in command
- Uses the code at https://github.com/tsloughter/rebar_alias and brings it within rebar3 - adds safety checks to prevent redefining built-in commands or obvious circular dependencies between commands (indirect circular deps are still possible) - adds tests - adds a systest to ensure no clash with the existing plugin
Diffstat (limited to 'test/rebar_alias_SUITE.erl')
-rw-r--r--test/rebar_alias_SUITE.erl113
1 files changed, 113 insertions, 0 deletions
diff --git a/test/rebar_alias_SUITE.erl b/test/rebar_alias_SUITE.erl
new file mode 100644
index 0000000..f889ae4
--- /dev/null
+++ b/test/rebar_alias_SUITE.erl
@@ -0,0 +1,113 @@
+-module(rebar_alias_SUITE).
+-compile([export_all]).
+
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+init_per_suite(Config) -> Config.
+end_per_suite(_Config) -> ok.
+
+init_per_testcase(_, Config) ->
+ rebar_test_utils:init_rebar_state(Config, "alias_").
+
+end_per_testcase(_, _Config) ->
+ ok.
+
+all() -> [command, args, many, override_default, no_circular].
+ %% namespaces: unsupported, untested.
+
+command() ->
+ [{doc, "Runs multiple regular commands as one alias"}].
+command(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("alias_command_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ RebarConfig = [{alias, [{test, [compile, unlock]}]}],
+
+ %% compile job ran
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["test"], {ok, [{app, Name}]}),
+ %% unlock job also ran
+ Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
+ ?assertNot(filelib:is_file(Lockfile)),
+ ok.
+
+args() ->
+ [{doc, "Runs multiple regular commands as one alias, some of "
+ "which have default arguments"}].
+args(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("alias_args_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ RebarConfig = [{alias, [{test, [{eunit,"-c"}, cover]}]}],
+
+ %% test job ran (compiled and succeeded)
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["test"], {ok, [{app, Name}]}),
+ %% cover job also ran, meaning eunit had coverage on, otherwise
+ %% the index file is not generated.
+ CoverFile = filename:join([?config(apps, Config),
+ "_build", "test", "cover", "index.html"]),
+ ?assert(filelib:is_file(CoverFile)),
+ ok.
+
+many() ->
+ [{doc, "Multiple aliases may be registered"}].
+many(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("alias_args_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ RebarConfig = [{alias, [{test, [{eunit,"-c"}, cover]},
+ {nolock, [compile, unlock]}]}],
+
+ %% test job ran (compiled and succeeded)
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["test"], {ok, [{app, Name}]}),
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["nolock"], {ok, [{app, Name}]}),
+ %% both jobs ran (see args/1 and command/1)
+ CoverFile = filename:join([?config(apps, Config),
+ "_build", "test", "cover", "index.html"]),
+ ?assert(filelib:is_file(CoverFile)),
+ Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
+ ?assertNot(filelib:is_file(Lockfile)),
+ ok.
+
+override_default() ->
+ [{doc, "An alias cannot take over a default provider"}].
+override_default(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("alias_override_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ RebarConfig = [{alias, [{compile, [help]}]}],
+
+ %% App compiles anyway
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
+ {ok, [{app, Name}]}),
+ ok.
+
+no_circular() ->
+ [{doc, "An alias cannot define itself as itself"},
+ {timetrap, 2000}].
+no_circular(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("alias_circular_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ RebarConfig = [{alias, [{test, [help, {test,"-a"}, compile]}]}],
+
+ %% Code does not deadlock forever and errors by not knowing
+ %% the command
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["test"],
+ {error, [$C,$o,$m,$m,$a,$n,$d,$ ,"test",$ ,$n,$o,$t,$ ,
+ $f,$o,$u,$n,$d]}),
+ ok.