formula_assertions: fix typechecking error in {shell,pipe}_output
`cmd` can be a `Pathname` (see the type signature), but `ohai` seems to expect only `String`s now. While we're here, let's assert that `cmd` exists whenever it is a `Pathname`, to avoid passing arguments like `bin/"cmd --version"` (which is not a valid `Pathname`). See, for example, Homebrew/homebrew-core#231882.
This commit is contained in:
parent
bcdb1d3af6
commit
4c024adba6
@ -26,7 +26,8 @@ module Homebrew
|
|||||||
# @api public
|
# @api public
|
||||||
sig { params(cmd: T.any(Pathname, String), result: Integer).returns(String) }
|
sig { params(cmd: T.any(Pathname, String), result: Integer).returns(String) }
|
||||||
def shell_output(cmd, result = 0)
|
def shell_output(cmd, result = 0)
|
||||||
ohai cmd
|
ohai cmd.to_s
|
||||||
|
assert_path_exists cmd, "Pathname '#{cmd}' does not exist!" if cmd.is_a?(Pathname)
|
||||||
output = `#{cmd}`
|
output = `#{cmd}`
|
||||||
assert_equal result, $CHILD_STATUS.exitstatus
|
assert_equal result, $CHILD_STATUS.exitstatus
|
||||||
output
|
output
|
||||||
@ -41,7 +42,8 @@ module Homebrew
|
|||||||
# @api public
|
# @api public
|
||||||
sig { params(cmd: T.any(String, Pathname), input: T.nilable(String), result: T.nilable(Integer)).returns(String) }
|
sig { params(cmd: T.any(String, Pathname), input: T.nilable(String), result: T.nilable(Integer)).returns(String) }
|
||||||
def pipe_output(cmd, input = nil, result = nil)
|
def pipe_output(cmd, input = nil, result = nil)
|
||||||
ohai cmd
|
ohai cmd.to_s
|
||||||
|
assert_path_exists cmd, "Pathname '#{cmd}' does not exist!" if cmd.is_a?(Pathname)
|
||||||
output = IO.popen(cmd, "w+") do |pipe|
|
output = IO.popen(cmd, "w+") do |pipe|
|
||||||
pipe.write(input) unless input.nil?
|
pipe.write(input) unless input.nil?
|
||||||
pipe.close_write
|
pipe.close_write
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user