diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-03-23 20:34:28 -0700 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-03-23 20:34:28 -0700 |
commit | 63fb911303d57294c8e5f8a291026ca6b5f3709c (patch) | |
tree | e1f461d37fd2debd2eaafaeaa2e9e9ee9257d840 | |
parent | 549c63b75d2b97165816a5975481595c3dc8bdf1 (diff) | |
parent | 5a42523cd564544487a8198764c83e12b49e93fd (diff) |
Merge pull request #292 from talentdeficit/get_opt_fix
handle additional errors returned from `getopt:parse/2`
-rw-r--r-- | src/rebar_core.erl | 6 | ||||
-rw-r--r-- | test/rebar_opts_parser_SUITE.erl | 54 |
2 files changed, 59 insertions, 1 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 1c1bf66..6abab68 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -93,7 +93,11 @@ process_command(State, Command) -> State2 = rebar_state:command_parsed_args(State1, Args), do(TargetProviders, State2); {error, {invalid_option, Option}} -> - {error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])} + {error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])}; + {error, {invalid_option_arg, {Option, Arg}}} -> + {error, io_lib:format("Invalid argument ~s to option ~s", [Arg, Option])}; + {error, {missing_option_arg, Option}} -> + {error, io_lib:format("Missing argument to option ~s", [Option])} end end end. diff --git a/test/rebar_opts_parser_SUITE.erl b/test/rebar_opts_parser_SUITE.erl new file mode 100644 index 0000000..fc738b9 --- /dev/null +++ b/test/rebar_opts_parser_SUITE.erl @@ -0,0 +1,54 @@ +-module(rebar_opts_parser_SUITE). + +-export([all/0, init_per_testcase/2]). +-export([bad_arg_to_flag/1, missing_arg_to_flag/1]). + +-include_lib("common_test/include/ct.hrl"). + + +all() -> [bad_arg_to_flag, missing_arg_to_flag]. + +init_per_testcase(_, Config) -> + rebar_test_utils:init_rebar_state(Config, "opts_parser_"). + +bad_arg_to_flag(Config) -> + ok = meck:new(getopt), + ok = meck:expect(getopt, + parse, + fun(_, _) -> {error, {invalid_option_arg, {foo, "null"}}} end), + + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("bad_arg_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + {error, Error} = rebar_test_utils:run_and_check(Config, + [], + ["compile", "--foo=null"], + return), + + true = meck:validate(getopt), + ok = meck:unload(getopt), + + "Invalid argument null to option foo" = lists:flatten(Error). + +missing_arg_to_flag(Config) -> + ok = meck:new(getopt), + ok = meck:expect(getopt, parse, fun(_, _) -> {error, {missing_option_arg, foo}} end), + + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("missing_arg_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + {error, Error} = rebar_test_utils:run_and_check(Config, + [], + ["compile", "--foo"], + return), + + true = meck:validate(getopt), + ok = meck:unload(getopt), + + "Missing argument to option foo" = lists:flatten(Error).
\ No newline at end of file |