From 4c024adba609a5d20306c4b4dfbc8304bd8d48e5 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera Date: Fri, 1 Aug 2025 05:56:32 +0800 Subject: [PATCH] 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. --- Library/Homebrew/formula_assertions.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index ed24d9d1b5..12913f36ef 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -26,7 +26,8 @@ module Homebrew # @api public sig { params(cmd: T.any(Pathname, String), result: Integer).returns(String) } 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}` assert_equal result, $CHILD_STATUS.exitstatus output @@ -41,7 +42,8 @@ module Homebrew # @api public 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) - 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| pipe.write(input) unless input.nil? pipe.close_write