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

This commit is contained in:
Gautham Goli 2018-10-29 02:27:00 +05:30
parent 322075130e
commit 6d3aa18f6a
No known key found for this signature in database
GPG Key ID: 6A9ABBC284468364
2 changed files with 15 additions and 0 deletions

View File

@ -126,6 +126,7 @@ module Homebrew
remaining_args = @parser.parse(cmdline_args) remaining_args = @parser.parse(cmdline_args)
check_constraint_violations check_constraint_violations
Homebrew.args[:remaining] = remaining_args Homebrew.args[:remaining] = remaining_args
Homebrew.args.freeze
@parser @parser
end end

View File

@ -177,4 +177,18 @@ describe Homebrew::CLI::Parser do
expect(Homebrew.args.switch_b?).to be true expect(Homebrew.args.switch_b?).to be true
end end
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 end