Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in CLI arg/env var prioritization + corresponding tests #5805

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cli_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def check_conflicts
next if violations.count < 2

env_var_options = violations.select do |option|
@switch_sources[option_to_name(option)] == :env_var
@switch_sources[option_to_name(option)] == :env
end

select_cli_arg = violations.count - env_var_options.count == 1
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/test/cli_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@
end

it "prioritizes cli arguments over env vars when they conflict" do
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return("0")
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return(nil)
parser.parse(["--switch-b"])
expect(Homebrew.args.switch_a).to be_falsy
expect(Homebrew.args).to be_switch_b
end

it "raises an exception on constraint violation when both are env vars" do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return("1")
allow(ENV).to receive(:[])
expect { parser.parse(["--switch-a", "--switch-b"]) }.to raise_error(Homebrew::CLI::OptionConflictError)
expect { parser.parse([]) }.to raise_error(Homebrew::CLI::OptionConflictError)
end
end

Expand Down