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

cli_parser: Make Homebrew.args immutable once CLI args have been processed #5204

Merged
merged 1 commit into from
Oct 29, 2018
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
1 change: 1 addition & 0 deletions Library/Homebrew/cli_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def parse(cmdline_args = ARGV)
remaining_args = @parser.parse(cmdline_args)
check_constraint_violations
Homebrew.args[:remaining] = remaining_args
Homebrew.args.freeze
@parser
end

Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/cli_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,18 @@
expect(Homebrew.args.switch_b?).to be true
end
end

describe "test immutability of args" do
subject(:parser) {
described_class.new do
switch "-a", "--switch-a"
switch "-b", "--switch-b"
end
}

it "raises exception upon Homebrew.args mutation" do
parser.parse(["--switch-a"])
expect { parser.parse(["--switch-b"]) }.to raise_error(RuntimeError, /can't modify frozen OpenStruct/)
end
end
end