From 6de94839de75e269883efeb85fa7faa2e1e5c1ba Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 20 Jun 2017 05:32:13 +0530 Subject: Adding tests for caveats --- Library/Homebrew/test/caveats_spec.rb | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index d8be9dc52..176d8e6ca 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -26,4 +26,51 @@ describe Caveats do expect(described_class.new(f)).not_to be_empty end end + + describe "#caveats" do + context "when f.plist is not nil" do + it "prints plist startup information when f.plist_startup is not nil" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + plist_options startup: true + end + expect(described_class.new(f).caveats).to include("startup:\n sudo brew") + end + + it "prints plist login information when f.plist_startup is nil" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + end + expect(described_class.new(f).caveats).to include("login:\n brew") + end + end + + context "when f.keg_only is not nil" do + it "tells formula is keg_only and gives information about command to be run when f.bin and f.sbin are directories" do + Path = Pathname.new("path") + f = formula do + url "foo-1.0" + keg_only "some reason" + end + + allow(f).to receive(:bin).and_return(Path) + allow(f.bin).to receive(:directory?).and_return(true) + + allow(f).to receive(:sbin).and_return(Path) + allow(f.sbin).to receive(:directory?).and_return(true) + + caveats = described_class.new(f).caveats + + expect(caveats).to include("keg-only") + expect(caveats).to include(f.opt_bin.to_s) + expect(caveats).to include(f.opt_sbin.to_s) + end + end + end end -- cgit v1.2.3 From a5334b9dcaf89ba854582a09af5cde939d217bf0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 18 Jul 2017 01:29:05 +0530 Subject: Added tests for keg_only_text --- Library/Homebrew/test/caveats_spec.rb | 51 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index 176d8e6ca..f7e60be65 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -1,5 +1,6 @@ require "formula" require "caveats" +require "pathname" describe Caveats do subject { described_class.new(f) } @@ -37,7 +38,7 @@ describe Caveats do end plist_options startup: true end - expect(described_class.new(f).caveats).to include("startup:\n sudo brew") + expect(described_class.new(f).caveats).to include("startup") end it "prints plist login information when f.plist_startup is nil" do @@ -47,30 +48,54 @@ describe Caveats do "plist_test.plist" end end - expect(described_class.new(f).caveats).to include("login:\n brew") + expect(described_class.new(f).caveats).to include("login") end end context "when f.keg_only is not nil" do - it "tells formula is keg_only and gives information about command to be run when f.bin and f.sbin are directories" do - Path = Pathname.new("path") - f = formula do + let(:f) { + formula do url "foo-1.0" keg_only "some reason" end + } + let(:caveats) { described_class.new(f).caveats } - allow(f).to receive(:bin).and_return(Path) - allow(f.bin).to receive(:directory?).and_return(true) - - allow(f).to receive(:sbin).and_return(Path) - allow(f.sbin).to receive(:directory?).and_return(true) - - caveats = described_class.new(f).caveats - + it "tells formula is keg_only" do expect(caveats).to include("keg-only") + end + + it "gives command to be run when f.bin is a directory" do + Pathname.new(f.bin).mkpath expect(caveats).to include(f.opt_bin.to_s) + end + + it "gives command to be run when f.sbin is a directory" do + Pathname.new(f.sbin).mkpath expect(caveats).to include(f.opt_sbin.to_s) end + + context "when f.lib or f.include is a directory" do + it "gives command to be run when f.lib is a directory" do + Pathname.new(f.lib).mkpath + expect(caveats).to include("-L#{f.opt_lib}") + end + + it "gives command to be run when f.include is a directory" do + Pathname.new(f.include).mkpath + expect(caveats).to include("-I#{f.opt_include}") + end + + it "gives PKG_CONFIG_PATH when f.lib/'pkgconfig' and f.share/'pkgconfig' are directories" do + allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("blah")) + + Pathname.new(f.share/"pkgconfig").mkpath + Pathname.new(f.lib/"pkgconfig").mkpath + + expect(caveats).to include("#{f.opt_lib}/pkgconfig") + expect(caveats).to include("#{f.opt_share}/pkgconfig") + end + end end end end -- cgit v1.2.3 From 5fba0c4776668c7ec8235ec3485511838f9c4a44 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 20 Jul 2017 03:47:02 +0530 Subject: 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(-) (limited to 'Library') diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index ee09063fd..2c724ab81 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 f7e60be65..6c734faf6 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 -- cgit v1.2.3 From 9218d3014d6b97a0225e537b6227eca885dd1260 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 21 Jul 2017 06:38:45 +0530 Subject: Added tests for plist_caveats --- Library/Homebrew/caveats.rb | 11 ++- Library/Homebrew/test/caveats_spec.rb | 124 ++++++++++++++++++++-------------- 2 files changed, 80 insertions(+), 55 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 2c724ab81..172d3c73f 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -165,7 +165,6 @@ class Caveats s = [] if f.plist || (keg && keg.plist_installed?) plist_domain = f.plist_path.basename(".plist") - plist_path = plist_complete_path # we readlink because this path probably doesn't exist since caveats # occurs before the link step of installation @@ -197,8 +196,8 @@ 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 + # pbpaste pastes the system clipboard tool on macOS and fails with `tmux` by default + # check if this is being run under `tmux` to avoid failing if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") s << "" << "WARNING: brew services will fail when run under tmux." end @@ -206,7 +205,7 @@ class Caveats s.join("\n") + "\n" unless s.empty? end - def plist_complete_path + def plist_path destination = if f.plist_startup "/Library/LaunchDaemons" else @@ -218,8 +217,8 @@ class Caveats else File.basename Dir["#{keg}/*.plist"].first end - destination_path = Pathname.new File.expand_path destination + destination_path = Pathname.new(File.expand_path(destination)) - return destination_path/plist_filename + destination_path/plist_filename end end diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index 6c734faf6..e04e4eab3 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -1,6 +1,5 @@ require "formula" require "caveats" -require "pathname" describe Caveats do subject { described_class.new(f) } @@ -50,6 +49,81 @@ describe Caveats do end expect(described_class.new(f).caveats).to include("login") 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_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 + + context "when plist_path is not a file nor symlinked and plist_startup is false" do + let(:f) { + formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + end + } + let(:f_obj) { described_class.new(f) } + let(:caveats) { f_obj.caveats } + let(:plist_path) { Pathname.new("plist") } + + before do + FileUtils.touch plist_path + allow(f_obj).to receive(:plist_path).and_return(plist_path) + allow(plist_path).to receive(:symlink?).and_return(true) + end + + it "tells command to run after upgrade" do + allow(Kernel).to receive(:system).with(any_args).and_return(true) + expect(caveats).to include("restart #{f.full_name} after an upgrade") + end + + it "tells command to run to start formula" do + expect(caveats).to include("To start #{f.full_name}:") + end + end + + 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 end context "when f.keg_only is not nil" do @@ -127,53 +201,5 @@ describe Caveats do 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 -- cgit v1.2.3 From ae02b9776a8e0d2456a71f1317218b73998779e7 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 23 Jul 2017 22:50:39 +0530 Subject: Added tests for python caveats --- Library/Homebrew/caveats.rb | 2 +- Library/Homebrew/test/caveats_spec.rb | 42 ++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 172d3c73f..1f9a09bec 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -196,7 +196,7 @@ class Caveats s << " #{f.plist_manual}" end - # pbpaste pastes the system clipboard tool on macOS and fails with `tmux` by default + # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default # check if this is being run under `tmux` to avoid failing if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") s << "" << "WARNING: brew services will fail when run under tmux." diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index e04e4eab3..53c90d60a 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -28,7 +28,7 @@ describe Caveats do end describe "#caveats" do - context "when f.plist is not nil" do + context "when f.plist is not nil", :needs_macos do it "prints plist startup information when f.plist_startup is not nil" do f = formula do url "foo-1.0" @@ -201,5 +201,45 @@ describe Caveats do expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") end end + + context "python caveats" do + before do + (f.prefix.resolved_path/"lib/python2.7/site-packages").mkpath + end + + context "when f is not keg_only" do + let(:f) { + formula do + url "foo-1.0" + end + } + let(:caveats) { described_class.new(f).caveats } + let(:user_site_packages) { Language::Python.user_site_packages("python") } + + it "give commands to run when Homebrew's site-packages is not in Python sys.path" do + expect(caveats).to include("Homebrew's site-packages is not\nin your Python sys.path") + expect(caveats).to include(user_site_packages) + expect(caveats).to include("import site") + end + + it "gives commands to run when python pth files are installed" do + allow(Homebrew).to receive(:_system).and_return(true) + allow(Dir).to receive(:[]).with(any_args).and_return(["blah.pth"]) + expect(caveats).to include(".pth files to Homebrew's site-packages and your\nPython isn't configured") + expect(caveats).to include(user_site_packages) + expect(caveats).to include("import site") + end + end + + it "gives commands to run when formula is keg_only" do + f = formula do + url "foo-1.0" + keg_only "some reason" + end + caveats = described_class.new(f).caveats + homebrew_site_packages = Language::Python.homebrew_site_packages + expect(caveats).to include("echo #{f.opt_prefix}/lib/python2.7/site-packages >> #{homebrew_site_packages/f.name}.pth") + end + end end end -- cgit v1.2.3