diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index 5129720c5e..ec99b832bd 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -49,7 +49,8 @@ class SystemCommand end end - assert_success if must_succeed? + result = Result.new(command, @output, @status, secrets: @secrets) + result.assert_success! if must_succeed? result end @@ -105,12 +106,6 @@ class SystemCommand ["/usr/bin/sudo", *askpass_flags, "-E", "--"] end - def assert_success - return if @status.success? - - raise ErrorDuringExecution.new(command, status: @status, output: @output, secrets: @secrets) - end - def expanded_args @expanded_args ||= args.map do |arg| if arg.respond_to?(:to_path) @@ -166,18 +161,21 @@ class SystemCommand sources.each(&:close_read) end - def result - Result.new(command, @output, @status) - end - class Result attr_accessor :command, :status, :exit_status - def initialize(command, output, status) + def initialize(command, output, status, secrets:) @command = command @output = output @status = status @exit_status = status.exitstatus + @secrets = secrets + end + + def assert_success! + return if @status.success? + + raise ErrorDuringExecution.new(command, status: @status, output: @output, secrets: @secrets) end def stdout diff --git a/Library/Homebrew/test/cask/pkg_spec.rb b/Library/Homebrew/test/cask/pkg_spec.rb index 3772ea0940..486ab8f822 100644 --- a/Library/Homebrew/test/cask/pkg_spec.rb +++ b/Library/Homebrew/test/cask/pkg_spec.rb @@ -152,7 +152,8 @@ describe Cask::Pkg, :cask do "/usr/sbin/pkgutil", args: ["--pkg-info-plist", pkg_id], ).and_return( - SystemCommand::Result.new(nil, [[:stdout, pkg_info_plist]], instance_double(Process::Status, exitstatus: 0)), + SystemCommand::Result.new(nil, [[:stdout, pkg_info_plist]], instance_double(Process::Status, exitstatus: 0), + secrets: []), ) info = pkg.info diff --git a/Library/Homebrew/test/support/helper/cask/fake_system_command.rb b/Library/Homebrew/test/support/helper/cask/fake_system_command.rb index 2f767ae9c9..253e9c8e86 100644 --- a/Library/Homebrew/test/support/helper/cask/fake_system_command.rb +++ b/Library/Homebrew/test/support/helper/cask/fake_system_command.rb @@ -55,7 +55,7 @@ class FakeSystemCommand if response.respond_to?(:call) response.call(command_string, options) else - SystemCommand::Result.new(command, [[:stdout, response]], OpenStruct.new(exitstatus: 0)) + SystemCommand::Result.new(command, [[:stdout, response]], OpenStruct.new(exitstatus: 0), secrets: []) end end diff --git a/Library/Homebrew/test/system_command_result_spec.rb b/Library/Homebrew/test/system_command_result_spec.rb index c76cb5d6fa..1d53f5e7b6 100644 --- a/Library/Homebrew/test/system_command_result_spec.rb +++ b/Library/Homebrew/test/system_command_result_spec.rb @@ -4,7 +4,8 @@ require "system_command" describe SystemCommand::Result do subject(:result) { - described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true)) + described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true), + secrets: []) } let(:output_array) {