mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/optparse] Don't treat empty string as an option description
https://github.com/ruby/optparse/commit/078638ee6d
This commit is contained in:
parent
3531086095
commit
0f231f2bab
2 changed files with 24 additions and 1 deletions
|
@ -1502,7 +1502,7 @@ XXX
|
|||
style = notwice(default_style.guess(arg = o), style, 'style')
|
||||
default_pattern, conv = search(:atype, Object) unless default_pattern
|
||||
else
|
||||
desc.push(o)
|
||||
desc.push(o) if o && !o.empty?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -55,4 +55,27 @@ class TestOptionParserSummaryTest < TestOptionParser
|
|||
o.release = "rel"
|
||||
assert_equal "foo 0.1 (rel)", o.ver
|
||||
end
|
||||
|
||||
# https://github.com/ruby/optparse/issues/37
|
||||
def test_very_long_without_short
|
||||
o = OptionParser.new do |opts|
|
||||
# This causes TypeError
|
||||
opts.on('', '--long-long-option-param-without-short', "Error desc") { options[:long_long_option_param_without_short] = true }
|
||||
opts.on('', '--long-option-param', "Long desc") { options[:long_option_param_without_short] = true }
|
||||
opts.on('-a', '--long-long-option-param-with-short', "Normal description") { options[:long_long_option_param_with_short] = true }
|
||||
|
||||
opts.on('', '--long-long-option-param-without-short-but-with-desc', 'Description of the long long param') { options[:long_long_option_param_without_short_but_with_desc] = true }
|
||||
end
|
||||
|
||||
s = o.summarize
|
||||
|
||||
assert_match(/^\s*--long-long-option-param-without-short$/, s[0])
|
||||
assert_match(/^\s*Error desc$/, s[1])
|
||||
assert_match(/^\s*--long-option-param\s+Long desc$/, s[2])
|
||||
assert_match(/^\s*-a\s+Normal description$/, s[3])
|
||||
assert_match(/^\s*--long-long-option-param-with-short$/, s[4])
|
||||
|
||||
assert_match(/^\s*--long-long-option-param-without-short-but-with-desc$/, s[5])
|
||||
assert_match(/^\s*Description of the long long param$/, s[6])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue