Here goes the patch implementing Tom’s idea. I also removed the clumsy
loop in #terminate, and than I started to write a test-suite, but I
got puzzled by this behavior ( same for the original getoptlong.rb and
the patched one ):
------------------- 8< -----------------------------
577/77 > cat test_getoptlong_basic.rb && ruby test_getoptlong_basic.rb
require ‘test/unit’
require ‘getoptlong’
class GetoptLong; include Enumerable end
class TestGetoptLongBasic < Test::Unit::TestCase
def setup
@opt = GetoptLong.new([ ‘-x’, GetoptLong::NO_ARGUMENT ],[ ‘-b’,
GetoptLong::REQUIRED_ARGUMENT])
end
def test_0_basic
ARGV.clear.push *%w{ -x -b 4096 }
assert_equal [ ["-x", “”], ["-b", “4096”] ],
@opt.dup.inject([]){|a, o| a << o }
assert_equal [], ARGV
ARGV.push *%w{ alpha -x 12 -b 4096 }
assert_equal [ ["-x", ""], ["-b", "4096"] ],
@opt.dup.inject([]){|a, o| a << o }
assert_equal %w{ alpha 12 }, ARGV
ARGV.clear.push *%w{ -- -b 4096 }
assert_equal [], @opt.dup.inject([]){|a, o| a << o }
assert_equal %w{-b 4096}, ARGV # line 23
end
end
Loaded suite test_getoptlong_basic
Started
F
Finished in 0.014403 seconds.
- Failure:
test_0_basic(TestGetoptLongBasic) [test_getoptlong_basic.rb:23]:
<["-b", “4096”]> expected but was
<[“alpha”, “12”, “-b”, “4096”]>.
1 tests, 6 assertions, 1 failures, 0 errors
------------------- 8< -----------------------------
Any thoughts about it?
cheers
Robert