cli_parser: Make Homebrew.args immutable once CLI arguments have been processed
This commit is contained in:
parent
322075130e
commit
6d3aa18f6a
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user