Copies of BuildOptions should not share underlying collections
This commit is contained in:
parent
cecf9a564f
commit
71b21c920f
@ -6,11 +6,20 @@ class BuildOptions
|
||||
attr_accessor :args
|
||||
include Enumerable
|
||||
|
||||
attr_reader :options
|
||||
protected :options
|
||||
|
||||
def initialize args
|
||||
@args = Options.coerce(args)
|
||||
@options = Options.new
|
||||
end
|
||||
|
||||
def initialize_copy(other)
|
||||
super
|
||||
@options = other.options.dup
|
||||
@args = other.args.dup
|
||||
end
|
||||
|
||||
def add name, description=nil
|
||||
description ||= case name.to_s
|
||||
when "universal" then "Build a universal binary"
|
||||
|
||||
@ -71,4 +71,20 @@ class BuildOptionsTests < Test::Unit::TestCase
|
||||
def test_actually_recognizes_implicit_options
|
||||
assert @build.has_opposite_of?("--with-baz")
|
||||
end
|
||||
|
||||
def test_copies_do_not_share_underlying_options
|
||||
orig = BuildOptions.new []
|
||||
copy = orig.dup
|
||||
copy.add 'foo'
|
||||
assert_empty orig
|
||||
assert_equal 1, copy.count
|
||||
end
|
||||
|
||||
def test_copies_do_not_share_underlying_args
|
||||
orig = BuildOptions.new []
|
||||
copy = orig.dup
|
||||
copy.args << Option.new('foo')
|
||||
assert_empty orig.args
|
||||
assert_equal 1, copy.args.count
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user