Don’t expand executable path in SystemCommand.
This commit is contained in:
parent
7c18efe81c
commit
a9e109e31a
@ -20,7 +20,7 @@ module Hbc
|
|||||||
|
|
||||||
def run!
|
def run!
|
||||||
@processed_output = { stdout: "", stderr: "" }
|
@processed_output = { stdout: "", stderr: "" }
|
||||||
odebug "Executing: #{expanded_command}"
|
odebug command.shelljoin
|
||||||
|
|
||||||
each_output_line do |type, line|
|
each_output_line do |type, line|
|
||||||
case type
|
case type
|
||||||
@ -55,7 +55,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def command
|
def command
|
||||||
[*sudo_prefix, *env_args, executable, *args]
|
[*sudo_prefix, *env_args, executable.to_s, *expanded_args]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -87,18 +87,20 @@ module Hbc
|
|||||||
raise CaskCommandFailedError.new(command, processed_output[:stdout], processed_output[:stderr], processed_status)
|
raise CaskCommandFailedError.new(command, processed_output[:stdout], processed_output[:stderr], processed_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
def expanded_command
|
def expanded_args
|
||||||
@expanded_command ||= command.map do |arg|
|
@expanded_args ||= args.map do |arg|
|
||||||
if arg.respond_to?(:to_path)
|
if arg.respond_to?(:to_path)
|
||||||
File.absolute_path(arg)
|
File.absolute_path(arg)
|
||||||
|
elsif arg.is_a?(Integer) || arg.is_a?(Float)
|
||||||
|
arg.to_s
|
||||||
else
|
else
|
||||||
String(arg)
|
arg.to_str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_output_line(&b)
|
def each_output_line(&b)
|
||||||
executable, *args = expanded_command
|
executable, *args = command
|
||||||
|
|
||||||
raw_stdin, raw_stdout, raw_stderr, raw_wait_thr =
|
raw_stdin, raw_stdout, raw_stderr, raw_wait_thr =
|
||||||
Open3.popen3([executable, executable], *args, **options)
|
Open3.popen3([executable, executable], *args, **options)
|
||||||
|
|||||||
@ -7,15 +7,15 @@ describe Hbc::Container::Naked, :cask do
|
|||||||
|
|
||||||
path = "/tmp/downloads/kevin-spacey-1.2.pkg"
|
path = "/tmp/downloads/kevin-spacey-1.2.pkg"
|
||||||
expected_destination = cask.staged_path.join("kevin spacey.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)
|
container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand)
|
||||||
|
|
||||||
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
|
["/usr/bin/ditto", "--", path, expected_destination],
|
||||||
|
)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
container.extract
|
container.extract
|
||||||
}.not_to raise_error
|
}.not_to raise_error
|
||||||
|
|
||||||
expect(Hbc::FakeSystemCommand.system_calls[expected_command]).to eq(1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -23,19 +23,16 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.stubs_command(command, response = "")
|
def self.stubs_command(command, response = "")
|
||||||
|
command = command.map(&:to_s)
|
||||||
responses[command] = response
|
responses[command] = response
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.expects_command(command, response = "", times = 1)
|
def self.expects_command(command, response = "", times = 1)
|
||||||
|
command = command.map(&:to_s)
|
||||||
stubs_command(command, response)
|
stubs_command(command, response)
|
||||||
expectations[command] = times
|
expectations[command] = times
|
||||||
end
|
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!
|
def self.verify_expectations!
|
||||||
expectations.each do |command, times|
|
expectations.each do |command, times|
|
||||||
unless system_calls[command] == times
|
unless system_calls[command] == times
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user