invalid build options - fixed conflicts; rename

This commit is contained in:
Bruce Steedman 2016-10-03 09:42:53 +01:00
parent 1e1903e4cc
commit 62e14ea673
6 changed files with 40 additions and 2 deletions

View File

@ -101,6 +101,15 @@ class BuildOptions
@options - @args @options - @args
end end
# @private
def invalid_options
@args - @options
end
def invalid_option_names
invalid_options.map(&:flag).sort
end
private private
def option_defined?(name) def option_defined?(name)

View File

@ -261,7 +261,9 @@ module Homebrew
f.print_tap_action f.print_tap_action
fi = FormulaInstaller.new(f) fi = FormulaInstaller.new(f)
fi.options = f.build.used_options build_options = f.build
fi.options = build_options.used_options
fi.invalid_opt_names = build_options.invalid_option_names
fi.ignore_deps = ARGV.ignore_deps? fi.ignore_deps = ARGV.ignore_deps?
fi.only_deps = ARGV.only_deps? fi.only_deps = ARGV.only_deps?
fi.build_bottle = ARGV.build_bottle? fi.build_bottle = ARGV.build_bottle?

View File

@ -32,7 +32,7 @@ class FormulaInstaller
end end
attr_reader :formula attr_reader :formula
attr_accessor :options, :build_bottle attr_accessor :options, :build_bottle, :invalid_opt_names
mode_attr_accessor :show_summary_heading, :show_header mode_attr_accessor :show_summary_heading, :show_header
mode_attr_accessor :build_from_source, :force_bottle mode_attr_accessor :build_from_source, :force_bottle
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git
@ -52,6 +52,7 @@ class FormulaInstaller
@quieter = false @quieter = false
@debug = false @debug = false
@options = Options.new @options = Options.new
@invalid_opt_names = []
@@attempted ||= Set.new @@attempted ||= Set.new
@ -214,6 +215,10 @@ class FormulaInstaller
opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!" opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!"
end end
invalid_opt_names.each do |option|
opoo "#{formula.full_name}: #{option} is invalid for this formula and will be ignored!"
end
oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header? oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header?
if formula.tap && !formula.tap.private? if formula.tap && !formula.tap.private?

View File

@ -7,6 +7,8 @@ class BuildOptionsTests < Homebrew::TestCase
args = Options.create(%w[--with-foo --with-bar --without-qux]) args = Options.create(%w[--with-foo --with-bar --without-qux])
opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
@build = BuildOptions.new(args, opts) @build = BuildOptions.new(args, opts)
bad_args = Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc])
@bad_build = BuildOptions.new(bad_args, opts)
end end
def test_include def test_include
@ -31,4 +33,17 @@ class BuildOptionsTests < Homebrew::TestCase
def test_unused_options def test_unused_options
assert_includes @build.unused_options, "--without-baz" assert_includes @build.unused_options, "--without-baz"
end end
def test_invalid_options
assert_empty @build.invalid_options
assert_includes @bad_build.invalid_options, "--without-bas"
assert_includes @bad_build.invalid_options, "--without-abc"
refute_includes @bad_build.invalid_options, "--with-foo"
refute_includes @bad_build.invalid_options, "--with-baz"
end
def test_invalid_opt_names
assert_empty @build.invalid_opt_names
assert_equal @bad_build.invalid_opt_names, %w[--without-abc --without-bas]
end
end end

View File

@ -37,6 +37,7 @@ class InstallTests < Homebrew::TestCase
end end
def test_a_basic_install def test_a_basic_install
ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install
temporary_install(Testball.new) do |f| temporary_install(Testball.new) do |f|
# Test that things made it into the Keg # Test that things made it into the Keg
assert_predicate f.prefix+"readme", :exist? assert_predicate f.prefix+"readme", :exist?

View File

@ -21,4 +21,10 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
assert_match "testball1 already installed, it's just not migrated", assert_match "testball1 already installed, it's just not migrated",
cmd("install", "testball2") cmd("install", "testball2")
end end
def test_install_with_invalid_option
setup_test_formula "testball1"
assert_match "testball1: --with-fo is invalid for this formula and will be ignored!",
cmd("install", "testball1", "--with-fo")
end
end end