Skip to content
Snippets Groups Projects
Unverified Commit 18bac4fa authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #5204 from GauthamGoli/immutable-args

cli_parser: Make Homebrew.args immutable once CLI args have been processed
parents 033386a7 6d3aa18f
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment