@@ -250,6 +250,7 @@ def caveats
250250 Pathname . new ( f . opt_bin ) . mkpath
251251 FileUtils . touch ( f . opt_bin /"foo" )
252252 FileUtils . chmod ( 0755 , f . opt_bin /"foo" )
253+ allow ( f ) . to receive ( :any_version_installed? ) . and_return ( true )
253254 allow_any_instance_of ( Object ) . to receive ( :which ) . and_call_original
254255 end
255256
@@ -291,6 +292,29 @@ def caveats
291292 expect ( described_class . new ( keg_only_f ) . caveats ) . not_to include ( "shadowed" )
292293 end
293294
295+ it "does not warn when the queried formula itself is not installed" do
296+ uninstalled_f = formula ( "foo@old" ) do
297+ url "foo-1.0"
298+ keg_only :versioned_formula
299+ end
300+ Pathname . new ( uninstalled_f . opt_bin ) . mkpath
301+ FileUtils . touch ( uninstalled_f . opt_bin /"foo" )
302+ FileUtils . chmod ( 0755 , uninstalled_f . opt_bin /"foo" )
303+
304+ sibling_keg_bin = HOMEBREW_CELLAR /"foo@2.0/2.0/bin"
305+ sibling_keg_bin . mkpath
306+ sibling_shadower = sibling_keg_bin /"foo"
307+ sibling_shadower . write ( "#!/bin/sh\n " )
308+ sibling_shadower . chmod ( 0755 )
309+
310+ allow ( uninstalled_f ) . to receive_messages ( versioned_formulae_names : [ "foo@2.0" ] ,
311+ unversioned_formula_name : "foo" ,
312+ any_version_installed? : false )
313+ allow_any_instance_of ( Object ) . to receive ( :which ) . with ( "foo" , ORIGINAL_PATHS ) . and_return ( sibling_shadower )
314+
315+ expect ( described_class . new ( uninstalled_f ) . caveats ) . not_to include ( "shadowed" )
316+ end
317+
294318 it "warns for a keg-only formula when a sibling keg is linked over it" do
295319 keg_only_f = formula ( "foo@1.0" ) do
296320 url "foo-1.0"
@@ -307,7 +331,8 @@ def caveats
307331 sibling_shadower . chmod ( 0755 )
308332
309333 allow ( keg_only_f ) . to receive_messages ( versioned_formulae_names : [ "foo@2.0" ] ,
310- unversioned_formula_name : "foo" )
334+ unversioned_formula_name : "foo" ,
335+ any_version_installed? : true )
311336 allow_any_instance_of ( Object ) . to receive ( :which ) . with ( "foo" , ORIGINAL_PATHS ) . and_return ( sibling_shadower )
312337
313338 caveats = described_class . new ( keg_only_f ) . caveats
@@ -323,7 +348,7 @@ def caveats
323348 Pathname . new ( keg_only_f . opt_bin ) . mkpath
324349 FileUtils . touch ( keg_only_f . opt_bin /"foo" )
325350 FileUtils . chmod ( 0755 , keg_only_f . opt_bin /"foo" )
326- allow ( keg_only_f ) . to receive ( : linked?) . and_return ( true )
351+ allow ( keg_only_f ) . to receive_messages ( linked? : true , any_version_installed? : true )
327352 shadower = Pathname . new ( "/usr/local/bin/foo" )
328353 allow_any_instance_of ( Object ) . to receive ( :which ) . with ( "foo" , ORIGINAL_PATHS ) . and_return ( shadower )
329354 allow ( shadower ) . to receive ( :realpath ) . and_return ( shadower )
0 commit comments