tab: remap deprecated options in tabs.

If a deprecated option is found in a tab, rename it to the new option.
This commit is contained in:
Mike McQuaid 2014-10-16 13:01:48 +01:00
parent d0240e7cd4
commit 33b3449621
2 changed files with 21 additions and 1 deletions

View File

@ -43,6 +43,16 @@ class Tab < OpenStruct
for_formula(Formulary.factory(name))
end
def self.remap_deprecated_options deprecated_options, options
deprecated_options.each do |deprecated_option|
option = options.find {|option| option.name == deprecated_option.old }
next unless option
options -= [option]
options << Option.new(deprecated_option.current, option.description)
end
options
end
def self.for_formula f
paths = []
@ -63,7 +73,10 @@ class Tab < OpenStruct
path = paths.map { |pn| pn.join(FILENAME) }.find(&:file?)
if path
from_file(path)
tab = from_file(path)
used_options = remap_deprecated_options(f.deprecated_options, tab.used_options)
tab.used_options = used_options.as_flags
tab
else
dummy_tab(f)
end

View File

@ -90,6 +90,13 @@ class TabTests < Homebrew::TestCase
assert_equal @tab.compiler, tab.compiler
assert_equal @tab.stdlib, tab.stdlib
end
def test_remap_deprecated_options
deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")]
remapped_options = Tab.remap_deprecated_options(deprecated_options, @tab.used_options)
assert_includes remapped_options, Option.new("without-bar")
assert_includes remapped_options, Option.new("with-foo-new")
end
end
class TabLoadingTests < Homebrew::TestCase