diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index b87c94721e..352d6405aa 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -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 diff --git a/Library/Homebrew/test/cli_parser_spec.rb b/Library/Homebrew/test/cli_parser_spec.rb index 615e20d78e..891de621eb 100644 --- a/Library/Homebrew/test/cli_parser_spec.rb +++ b/Library/Homebrew/test/cli_parser_spec.rb @@ -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