From: Alexis Laferrière Date: Wed, 20 Apr 2016 11:34:29 +0000 (-0400) Subject: lib/opts: report invalid integer passed to an OptionInt X-Git-Url: http://nitlanguage.org lib/opts: report invalid integer passed to an OptionInt Signed-off-by: Alexis Laferrière --- diff --git a/lib/opts.nit b/lib/opts.nit index da78780..30ea286 100644 --- a/lib/opts.nit +++ b/lib/opts.nit @@ -236,7 +236,13 @@ class OptionInt super(help, default, names) end - redef fun convert(str) do return str.to_i + redef fun convert(str) + do + if str.is_int then return str.to_i + + errors.add "Expected an integer for option {names.join(", ")}." + return 0 + end end # An option with a Float as parameter diff --git a/tests/sav/test_opts_args5.res b/tests/sav/test_opts_args5.res index 76da1d5..cd209be 100644 --- a/tests/sav/test_opts_args5.res +++ b/tests/sav/test_opts_args5.res @@ -2,6 +2,8 @@ Arguments: 2 -i one Rest: 0 +Errors: 1 +Expected an integer for option -i, --int. OptionBool: false OptionCount: 0 OptionString: