From 9b2e04593fae9d864795b8b6f0a14f91f2741bad Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Thu, 22 Aug 2013 11:46:47 -0500 Subject: [PATCH] Options: ensure copies do not share the underlying collection --- Library/Homebrew/options.rb | 5 +++++ Library/Homebrew/test/test_options.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb index b59cd29300..033e5b69e9 100644 --- a/Library/Homebrew/options.rb +++ b/Library/Homebrew/options.rb @@ -54,6 +54,11 @@ class Options @options = Set.new(*args) end + def initialize_copy(other) + super + @options = @options.dup + end + def each(*args, &block) @options.each(*args, &block) end diff --git a/Library/Homebrew/test/test_options.rb b/Library/Homebrew/test/test_options.rb index b0f5603541..493aa100ac 100644 --- a/Library/Homebrew/test/test_options.rb +++ b/Library/Homebrew/test/test_options.rb @@ -152,4 +152,10 @@ class OptionsTests < Test::Unit::TestCase debug = Option.new("-d") assert_equal [verbose, debug].sort, Options.coerce(array).to_a.sort end + + def test_copies_do_not_share_underlying_collection + copy = @options.dup << Option.new("foo") + assert_empty @options + assert_equal 1, copy.count + end end