aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/options.rb5
-rw-r--r--Library/Homebrew/software_spec.rb26
-rw-r--r--Library/Homebrew/test/test_options.rb17
-rw-r--r--Library/Homebrew/test/test_software_spec.rb24
4 files changed, 71 insertions, 1 deletions
diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb
index edeb5d870..6d6242171 100644
--- a/Library/Homebrew/options.rb
+++ b/Library/Homebrew/options.rb
@@ -47,6 +47,11 @@ class DeprecatedOption
def current_flag
"--#{current}"
end
+
+ def ==(other)
+ instance_of?(other.class) && old == other.old && current == other.current
+ end
+ alias_method :eql?, :==
end
class Options
diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb
index 4ea2f56c4..fab50be73 100644
--- a/Library/Homebrew/software_spec.rb
+++ b/Library/Homebrew/software_spec.rb
@@ -20,6 +20,7 @@ class SoftwareSpec
attr_reader :name, :owner
attr_reader :build, :resources, :patches, :options
+ attr_reader :deprecated_flags, :deprecated_options
attr_reader :dependency_collector
attr_reader :bottle_specification
attr_reader :compiler_failures
@@ -36,7 +37,10 @@ class SoftwareSpec
@bottle_specification = BottleSpecification.new
@patches = []
@options = Options.new
- @build = BuildOptions.new(Options.create(ARGV.flags_only), options)
+ @flags = ARGV.flags_only
+ @deprecated_flags = []
+ @deprecated_options = []
+ @build = BuildOptions.new(Options.create(@flags), options)
@compiler_failures = []
end
@@ -99,6 +103,26 @@ class SoftwareSpec
options << opt
end
+ def deprecated_option hash
+ raise ArgumentError, "deprecated_option hash must not be empty" if hash.empty?
+ hash.each do |old_options, new_options|
+ Array(old_options).each do |old_option|
+ Array(new_options).each do |new_option|
+ deprecated_option = DeprecatedOption.new(old_option, new_option)
+ deprecated_options << deprecated_option
+
+ old_flag = deprecated_option.old_flag
+ new_flag = deprecated_option.current_flag
+ next unless @flags.include? old_flag
+ @flags -= [old_flag]
+ @flags |= [new_flag]
+ @deprecated_flags << deprecated_option
+ end
+ end
+ end
+ @build = BuildOptions.new(Options.create(@flags), options)
+ end
+
def depends_on spec
dep = dependency_collector.add(spec)
add_dep_option(dep) if dep
diff --git a/Library/Homebrew/test/test_options.rb b/Library/Homebrew/test/test_options.rb
index 1bd5ba3b0..fcf49a8d8 100644
--- a/Library/Homebrew/test/test_options.rb
+++ b/Library/Homebrew/test/test_options.rb
@@ -37,6 +37,23 @@ class DeprecatedOptionTests < Homebrew::TestCase
def test_current
assert_equal "bar", @deprecated_option.current
end
+
+ def test_old
+ assert_equal "--foo", @deprecated_option.old_flag
+ end
+
+ def test_current
+ assert_equal "--bar", @deprecated_option.current_flag
+ end
+
+ def test_equality
+ foobar = DeprecatedOption.new("foo", "bar")
+ boofar = DeprecatedOption.new("boo", "far")
+ assert_equal foobar, @deprecated_option
+ refute_equal boofar, @deprecated_option
+ assert_eql @deprecated_option, foobar
+ refute_eql @deprecated_option, boofar
+ end
end
class OptionsTests < Homebrew::TestCase
diff --git a/Library/Homebrew/test/test_software_spec.rb b/Library/Homebrew/test/test_software_spec.rb
index d4b271177..e067f2f10 100644
--- a/Library/Homebrew/test/test_software_spec.rb
+++ b/Library/Homebrew/test/test_software_spec.rb
@@ -72,6 +72,30 @@ class SoftwareSpecTests < Homebrew::TestCase
assert_equal "", @spec.options.first.description
end
+ def test_deprecated_option
+ @spec.deprecated_option('foo' => 'bar')
+ assert @spec.deprecated_options.any?
+ assert_equal "foo", @spec.deprecated_options.first.old
+ assert_equal "bar", @spec.deprecated_options.first.current
+ end
+
+ def test_deprecated_options
+ @spec.deprecated_option(['foo1', 'foo2'] => 'bar1', 'foo3' => ['bar2', 'bar3'])
+ refute_empty @spec.deprecated_options
+ assert_equal "foo1", @spec.deprecated_options.first.old
+ assert_equal "bar1", @spec.deprecated_options.first.current
+ assert_equal "foo2", @spec.deprecated_options[1].old
+ assert_equal "bar1", @spec.deprecated_options[1].current
+ assert_equal "foo3", @spec.deprecated_options[2].old
+ assert_equal "bar2", @spec.deprecated_options[2].current
+ assert_equal "foo3", @spec.deprecated_options.last.old
+ assert_equal "bar3", @spec.deprecated_options.last.current
+ end
+
+ def test_deprecated_option_raises_when_empty
+ assert_raises(ArgumentError) { @spec.deprecated_option({}) }
+ end
+
def test_depends_on
@spec.depends_on('foo')
assert_equal 'foo', @spec.deps.first.name