From 1d27c5f79a1884cca8ce7fb0de702d44050d67fe Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 9 Jun 2018 11:32:49 +0200 Subject: [PATCH] Don't create `Caskroom.path` for tests. --- Library/Homebrew/cask/lib/hbc/caskroom.rb | 6 ++++-- Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 4 +--- .../support/helper/spec/shared_context/homebrew_cask.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb index ac6bf8e3f0..cd3e1d52b9 100644 --- a/Library/Homebrew/cask/lib/hbc/caskroom.rb +++ b/Library/Homebrew/cask/lib/hbc/caskroom.rb @@ -9,10 +9,12 @@ module Hbc def ensure_caskroom_exists return if path.exist? - ohai "Creating Caskroom at #{path}" if $stdout.tty? sudo = !path.parent.writable? - ohai "We'll set permissions properly so we won't need sudo in the future" if $stdout.tty? && sudo + if sudo && !ENV.key?("SUDO_ASKPASS") && $stdout.tty? + ohai "Creating Caskroom at #{path}" + ohai "We'll set permissions properly so we won't need sudo in the future." + end SystemCommand.run("/bin/mkdir", args: ["-p", path], sudo: sudo) SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo: sudo) diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index e60103d290..63edf2d55c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -62,9 +62,7 @@ module Hbc path = Pathname.new(user_tilde(Caskroom.path.to_s)) - if !path.exist? - add_error "The staging path #{path} does not exist." - elsif !path.writable? + if path.exist? && !path.writable? add_error "The staging path #{path} is not writable by the current user." end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index 62613fcf1a..e021eb3f7e 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -23,7 +23,7 @@ RSpec.shared_context "Homebrew-Cask" do begin HOMEBREW_CASK_DIRS.values.each(&:mkpath) - [Hbc::Config.global.binarydir, Hbc::Caskroom.path].each(&:mkpath) + [Hbc::Config.global.binarydir].each(&:mkpath) Tap.default_cask_tap.tap do |tap| FileUtils.mkdir_p tap.path.dirname