tests: add some runtime error in nitin.input
[nit.git] / lib / opts.nit
index 3d15652..c93d39a 100644 (file)
@@ -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
@@ -286,9 +292,7 @@ class OptionContext
        private var optmap = new HashMap[String, Option]
 
        # Add one or more options to the context
-       fun add_option(opts: Option...) do
-                       options.add_all(opts)
-       end
+       fun add_option(opts: Option...) do options.add_all(opts)
 
        # Display all the options available
        fun usage
@@ -309,9 +313,10 @@ class OptionContext
                end
        end
 
-       # Parse and assign options everywhere in the argument list
-       fun parse(argv: Collection[String])
+       # Parse and assign options in `argv` or `args`
+       fun parse(argv: nullable Collection[String])
        do
+               if argv == null then argv = args
                var it = argv.iterator
                parse_intern(it)
        end