mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00
[ruby/optparse] Add raise_unknown
flag
(https://github.com/ruby/optparse/pull/38)
12529653cd
This commit is contained in:
parent
dcf94e719c
commit
0bfb185654
2 changed files with 19 additions and 0 deletions
|
@ -98,6 +98,18 @@ class TestOptionParser < Test::Unit::TestCase
|
|||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
|
||||
end
|
||||
|
||||
def test_raise_unknown
|
||||
@opt.def_option('--foo [ARG]') {|arg| @foo = arg}
|
||||
assert @opt.raise_unknown
|
||||
|
||||
@opt.raise_unknown = false
|
||||
assert_equal(%w[--bar], @opt.parse(%w[--foo --bar]))
|
||||
assert_nil(@foo)
|
||||
|
||||
assert_equal(%w[--bar], @opt.parse(%w[--foo x --bar]))
|
||||
assert_equal("x", @foo)
|
||||
end
|
||||
|
||||
def test_nonopt_pattern
|
||||
@opt.def_option(/^[^-]/) do |arg|
|
||||
assert(false, "Never gets called")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue