Copies of BuildOptions should not share underlying collections

This commit is contained in:
Jack Nagel 2013-09-14 17:03:56 -05:00
parent cecf9a564f
commit 71b21c920f
2 changed files with 25 additions and 0 deletions

View File

@ -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"

View File

@ -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