From 5fba0c4776668c7ec8235ec3485511838f9c4a44 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 20 Jul 2017 03:47:02 +0530 Subject: [PATCH] Added tests for function_completion_caveats --- Library/Homebrew/caveats.rb | 33 +++++++----- Library/Homebrew/test/caveats_spec.rb | 78 +++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index ee09063fd9..2c724ab815 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -164,20 +164,8 @@ class Caveats def plist_caveats s = [] if f.plist || (keg && keg.plist_installed?) - destination = if f.plist_startup - "/Library/LaunchDaemons" - else - "~/Library/LaunchAgents" - end - - plist_filename = if f.plist - f.plist_path.basename - else - File.basename Dir["#{keg}/*.plist"].first - end plist_domain = f.plist_path.basename(".plist") - destination_path = Pathname.new File.expand_path destination - plist_path = destination_path/plist_filename + plist_path = plist_complete_path # we readlink because this path probably doesn't exist since caveats # occurs before the link step of installation @@ -209,10 +197,29 @@ class Caveats s << " #{f.plist_manual}" end + # pbpaste is a system clipboard tool for OSX that doesn't work well with tmux + # This checks if tmux is being used and warns about brew failure if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") s << "" << "WARNING: brew services will fail when run under tmux." end end s.join("\n") + "\n" unless s.empty? end + + def plist_complete_path + destination = if f.plist_startup + "/Library/LaunchDaemons" + else + "~/Library/LaunchAgents" + end + + plist_filename = if f.plist + f.plist_path.basename + else + File.basename Dir["#{keg}/*.plist"].first + end + destination_path = Pathname.new File.expand_path destination + + return destination_path/plist_filename + end end diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index f7e60be65c..6c734faf6a 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -97,5 +97,83 @@ describe Caveats do end end end + + context "shell completions" do + let(:f) { + formula do + url "foo-1.0" + end + } + let(:caveats) { described_class.new(f).caveats } + let(:path) { f.prefix.resolved_path } + + before do + allow_any_instance_of(Pathname).to receive(:children).and_return([Pathname.new("child")]) + allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell")) + end + + it "gives dir where bash completions have been installed" do + (path/"etc/bash_completion.d").mkpath + expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d") + end + + it "gives dir where zsh completions have been installed" do + (path/"share/zsh/site-functions").mkpath + expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions") + end + + it "gives dir where fish completions have been installed" do + (path/"share/fish/vendor_completions.d").mkpath + expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") + end + end + + context "when plist_caveats are given" do + it "gives information about plist_manual" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + plist_options manual: "foo" + end + caveats = described_class.new(f).caveats + + expect(caveats).to include("background service") + expect(caveats).to include(f.plist_manual) + end + + it "warns about brew failing under tmux" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + end + allow(ENV).to receive(:[]).with("TMUX").and_return(true) + allow(Homebrew).to receive(:_system).with("/usr/bin/pbpaste").and_return(false) + caveats = described_class.new(f).caveats + + expect(caveats).to include("WARNING:") + expect(caveats).to include("tmux") + end + + it "gives information about restarting services after upgrade" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + plist_options startup: true + end + f_obj = described_class.new(f) + plist_path = Pathname.new("plist") + FileUtils.touch plist_path + allow(f_obj).to receive(:plist_complete_path).and_return(plist_path) + allow(plist_path).to receive(:symlink?).and_return(true) + expect(f_obj.caveats).to include("restart #{f.full_name}") + expect(f_obj.caveats).to include("sudo") + end + end end end