From 71b21c920ffab63f55fa8c7d86e84747e6696190 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 14 Sep 2013 17:03:56 -0500 Subject: [PATCH] Copies of BuildOptions should not share underlying collections --- Library/Homebrew/build_options.rb | 9 +++++++++ Library/Homebrew/test/test_build_options.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb index 6400b36cea..a1069694e9 100644 --- a/Library/Homebrew/build_options.rb +++ b/Library/Homebrew/build_options.rb @@ -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" diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb index 38eeae22bd..b5674ea503 100644 --- a/Library/Homebrew/test/test_build_options.rb +++ b/Library/Homebrew/test/test_build_options.rb @@ -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