extend format_error/2 to handle missing_option_arg
This commit is contained in:
+28
-1
@@ -298,6 +298,19 @@ check_test_() ->
|
||||
?_assertEqual({error, {missing_required_option, arg}}, check(OptSpecList, Opts))},
|
||||
{"Parse arguments and check required options",
|
||||
?_assertEqual({error, {missing_required_option, arg}}, parse_and_check(OptSpecList, ""))},
|
||||
{"Parse arguments and check required option args",
|
||||
?_assertEqual({error, {missing_option_arg, arg}},
|
||||
parse_and_check(OptSpecList, "-a"))}].
|
||||
|
||||
format_error_test_() ->
|
||||
OptSpecList =
|
||||
[
|
||||
{ arg, $a, "arg", string, "Required arg"},
|
||||
{ short, $s, undefined, string, "short option"},
|
||||
{ long, undefined, "long", string, "long option"},
|
||||
{ other, undefined, undefined, string, "task"}
|
||||
],
|
||||
[
|
||||
{"Format missing option error test 1",
|
||||
?_assertEqual("missing required option: -a (arg)",
|
||||
format_error(OptSpecList, {error, {missing_required_option, arg}}))},
|
||||
@@ -321,7 +334,21 @@ check_test_() ->
|
||||
format_error(OptSpecList, {error, {invalid_option_arg, "arg_value"}}))},
|
||||
{"Format invalid option argument error test 2",
|
||||
?_assertEqual("option 'verbose' has invalid argument: 100",
|
||||
format_error(OptSpecList, {error, {invalid_option_arg, {verbose, "100"}}}))}
|
||||
format_error(OptSpecList, {error, {invalid_option_arg, {verbose, "100"}}}))},
|
||||
{"Format missing option argument error test 1",
|
||||
?_assertEqual("missing option argument: -a (arg) <arg>",
|
||||
format_error(OptSpecList, {error, {missing_option_arg, arg}}))},
|
||||
{"Format missing option argument error test 2",
|
||||
?_assertEqual("missing option argument: -a (arg) <arg>",
|
||||
format_error(OptSpecList, {missing_option_arg, arg}))},
|
||||
{"Format missing option argument error test 3",
|
||||
?_assertEqual("missing option argument: -s <short>",
|
||||
format_error(OptSpecList, {missing_option_arg, short}))},
|
||||
{"Format missing option argument error test 4",
|
||||
?_assertEqual("missing option argument: --long <long>",
|
||||
format_error(OptSpecList, {missing_option_arg, long}))},
|
||||
{"Format missing option argument error test 5",
|
||||
?_assertError(_, format_error(OptSpecList, {missing_option_arg, unknown}))}
|
||||
].
|
||||
|
||||
utf8_binary_test_() ->
|
||||
|
||||
Reference in New Issue
Block a user