Don’t expand executable path in SystemCommand.

This commit is contained in:
Markus Reiter 2018-07-14 02:26:59 +02:00
parent 7c18efe81c
commit a9e109e31a
3 changed files with 14 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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