Skip to content

Commit 6638c5d

Browse files
committed
Accept Backtrace::Locations in OptParse::ParseError#set_backtrace
1 parent b1220ac commit 6638c5d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/optparse.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ def recover(argv)
22712271
DIR = File.join(__dir__, '')
22722272
def self.filter_backtrace(array)
22732273
unless $DEBUG
2274-
array.delete_if {|bt| bt.start_with?(DIR)}
2274+
array.delete_if {|bt| (bt.respond_to?(:path) ? bt.path : bt).start_with?(DIR)}
22752275
end
22762276
array
22772277
end

test/optparse/test_optparse.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def test_nonopt_pattern
178178
assert_equal(["-t"], e.args)
179179
end
180180

181+
def test_parse_error_set_backtrace
182+
e = assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-t))}
183+
assert_nothing_raised {e.set_backtrace(e.backtrace)}
184+
assert_nothing_raised {e.set_backtrace(e.backtrace_locations)}
185+
end
186+
181187
def test_help_pager
182188
require 'tmpdir'
183189
Dir.mktmpdir do |dir|

0 commit comments

Comments
 (0)