Merge pull request #5204 from GauthamGoli/immutable-args

cli_parser: Make Homebrew.args immutable once CLI args have been processed
This commit is contained in:
Mike McQuaid 2018-10-29 13:39:58 +00:00 committed by GitHub
commit 18bac4fa5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

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

View File

@ -177,4 +177,18 @@ describe Homebrew::CLI::Parser do
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