From d57f291a1e780b49d05995d5a3a9574420790ec7 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 22 Apr 2023 10:06:52 -0700 Subject: [PATCH] formulary: sub home placeholder in caveats We set a placeholder for the home directory when generating API JSON so we should substitute the actual home directory back in when printing caveats locally. This allows people to use `Dir.home` in caveats and have it display correctly no matter the platform or operating system. --- Library/Homebrew/formulary.rb | 1 + Library/Homebrew/test/formulary_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 349b5b5041..f16246e9d5 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -287,6 +287,7 @@ module Formulary def caveats self.class.instance_variable_get(:@caveats_string) &.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX) + &.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home) end @tap_git_head_string = json_formula["tap_git_head"] diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index d8f3fb0400..5e3ac4950d 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -270,7 +270,7 @@ describe Formulary do "conflicts_with" => ["conflicting_formula"], "conflicts_with_reasons" => ["it does"], "link_overwrite" => ["bin/abc"], - "caveats" => "example caveat string", + "caveats" => "example caveat string\n/$HOME\n$HOMEBREW_PREFIX", "service" => { "run" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "test"], "run_type" => "immediate", @@ -356,7 +356,7 @@ describe Formulary do expect(formula.conflicts.map(&:reason)).to include "it does" expect(formula.class.link_overwrite_paths).to include "bin/abc" - expect(formula.caveats).to eq "example caveat string" + expect(formula.caveats).to eq "example caveat string\n#{Dir.home}\n#{HOMEBREW_PREFIX}" expect(formula).to be_a_service expect(formula.service.command).to eq(["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "test"])