From a9e109e31a9b962c0ea5edc36a36b0296b3fb229 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Jul 2018 02:26:59 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20expand=20`executable`=20path=20?= =?UTF-8?q?in=20`SystemCommand`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/lib/hbc/system_command.rb | 14 ++++++++------ Library/Homebrew/test/cask/container/naked_spec.rb | 8 ++++---- .../support/helper/cask/fake_system_command.rb | 7 ++----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 48d57689ca..e1cbb3122a 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -20,7 +20,7 @@ module Hbc def run! @processed_output = { stdout: "", stderr: "" } - odebug "Executing: #{expanded_command}" + odebug command.shelljoin each_output_line do |type, line| case type @@ -55,7 +55,7 @@ module Hbc end def command - [*sudo_prefix, *env_args, executable, *args] + [*sudo_prefix, *env_args, executable.to_s, *expanded_args] end private @@ -87,18 +87,20 @@ module Hbc raise CaskCommandFailedError.new(command, processed_output[:stdout], processed_output[:stderr], processed_status) end - def expanded_command - @expanded_command ||= command.map do |arg| + def expanded_args + @expanded_args ||= args.map do |arg| if arg.respond_to?(:to_path) File.absolute_path(arg) + elsif arg.is_a?(Integer) || arg.is_a?(Float) + arg.to_s else - String(arg) + arg.to_str end end end def each_output_line(&b) - executable, *args = expanded_command + executable, *args = command raw_stdin, raw_stdout, raw_stderr, raw_wait_thr = Open3.popen3([executable, executable], *args, **options) diff --git a/Library/Homebrew/test/cask/container/naked_spec.rb b/Library/Homebrew/test/cask/container/naked_spec.rb index 1ccdf4ef42..1167a9cc10 100644 --- a/Library/Homebrew/test/cask/container/naked_spec.rb +++ b/Library/Homebrew/test/cask/container/naked_spec.rb @@ -7,15 +7,15 @@ describe Hbc::Container::Naked, :cask do path = "/tmp/downloads/kevin-spacey-1.2.pkg" expected_destination = cask.staged_path.join("kevin spacey.pkg") - expected_command = ["/usr/bin/ditto", "--", path, expected_destination] - Hbc::FakeSystemCommand.stubs_command(expected_command) container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand) + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/ditto", "--", path, expected_destination], + ) + expect { container.extract }.not_to raise_error - - expect(Hbc::FakeSystemCommand.system_calls[expected_command]).to eq(1) end end 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 93e1c194f1..4e7e53a956 100644 --- a/Library/Homebrew/test/support/helper/cask/fake_system_command.rb +++ b/Library/Homebrew/test/support/helper/cask/fake_system_command.rb @@ -23,19 +23,16 @@ module Hbc end def self.stubs_command(command, response = "") + command = command.map(&:to_s) responses[command] = response end def self.expects_command(command, response = "", times = 1) + command = command.map(&:to_s) stubs_command(command, response) expectations[command] = times end - def self.expect_and_pass_through(command, times = 1) - pass_through = ->(cmd, opts) { Hbc::SystemCommand.run(cmd, opts) } - expects_command(command, pass_through, times) - end - def self.verify_expectations! expectations.each do |command, times| unless system_calls[command] == times