Merge pull request #5660 from reitermarkus/save-cask-config

Save cask config for reinstall/uninstall/upgrade.
This commit is contained in:
Markus Reiter 2019-02-15 11:49:01 +01:00 committed by GitHub
commit e8a7592176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 323 additions and 211 deletions

View File

@ -94,11 +94,14 @@ module Cask
[executable, arguments]
end
attr_reader :cask, :config
attr_reader :cask
def initialize(cask)
@cask = cask
@config = cask.config
end
def config
cask.config
end
def to_s

View File

@ -31,15 +31,21 @@ module Cask
@tap
end
def initialize(token, sourcefile_path: nil, tap: nil, config: Config.global, &block)
def initialize(token, sourcefile_path: nil, tap: nil, &block)
@token = token
@sourcefile_path = sourcefile_path
@tap = tap
@config = config
@dsl = DSL.new(self)
return unless block_given?
@block = block
self.config = Config.for_cask(self)
end
@dsl.instance_eval(&block)
def config=(config)
@config = config
@dsl = DSL.new(self)
return unless @block
@dsl.instance_eval(&@block)
@dsl.language_eval
end
@ -77,6 +83,14 @@ module Cask
metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb")
end
def config_path
metadata_master_container_path/"config.json"
end
def caskroom_path
@caskroom_path ||= Caskroom.path.join(token)
end
def outdated?(greedy = false)
!outdated_versions(greedy).empty?
end

View File

@ -186,7 +186,10 @@ module Cask
end
def process_options(*args)
all_args = Shellwords.shellsplit(ENV["HOMEBREW_CASK_OPTS"] || "") + args
exclude_regex = /^\-\-#{Regexp.union(*Config::DEFAULT_DIRS.keys.map(&Regexp.public_method(:escape)))}=/
all_args = Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", ""))
.reject { |arg| arg.match?(exclude_regex) } + args
non_options = []

View File

@ -1,3 +1,5 @@
require "cask/config"
module Cask
class Cmd
class Upgrade < AbstractCommand
@ -44,13 +46,17 @@ module Cask
old_cask = CaskLoader.load(old_cask.installed_caskfile)
old_config = old_cask.config
old_cask_installer =
Installer.new(old_cask, binaries: binaries?,
verbose: verbose?,
force: force?,
upgrade: true)
new_cask = CaskLoader.load(old_cask.to_s)
new_cask = CaskLoader.load(old_cask.token)
new_cask.config = Config.global.merge(old_config)
new_cask_installer =
Installer.new(new_cask, binaries: binaries?,

View File

@ -1,12 +1,11 @@
require "json"
require "extend/hash_validator"
using HashValidator
module Cask
class Config
def self.global
@global ||= new
end
attr_reader :binarydir
def initialize(
DEFAULT_DIRS = {
appdir: "/Applications",
prefpanedir: "~/Library/PreferencePanes",
qlplugindir: "~/Library/QuickLook",
@ -19,47 +18,91 @@ module Cask
audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components",
vst_plugindir: "~/Library/Audio/Plug-Ins/VST",
vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3",
screen_saverdir: "~/Library/Screen Savers"
)
screen_saverdir: "~/Library/Screen Savers",
}.freeze
self.appdir = appdir
self.prefpanedir = prefpanedir
self.qlplugindir = qlplugindir
self.dictionarydir = dictionarydir
self.fontdir = fontdir
self.colorpickerdir = colorpickerdir
self.servicedir = servicedir
self.input_methoddir = input_methoddir
self.internet_plugindir = internet_plugindir
self.audio_unit_plugindir = audio_unit_plugindir
self.vst_plugindir = vst_plugindir
self.vst3_plugindir = vst3_plugindir
self.screen_saverdir = screen_saverdir
# `binarydir` is not customisable.
@binarydir = HOMEBREW_PREFIX/"bin"
def self.global
@global ||= new
end
[
:appdir,
:prefpanedir,
:qlplugindir,
:dictionarydir,
:fontdir,
:colorpickerdir,
:servicedir,
:input_methoddir,
:internet_plugindir,
:audio_unit_plugindir,
:vst_plugindir,
:vst3_plugindir,
:screen_saverdir,
].each do |dir|
attr_reader dir
def self.clear
@global = nil
end
def self.for_cask(cask)
if cask.config_path.exist?
from_file(cask.config_path)
else
global
end
end
def self.from_file(path)
config = begin
JSON.parse(File.read(path))
rescue JSON::ParserError => e
raise e, "Cannot parse #{path}: #{e}", e.backtrace
end
new(
default: config.fetch("default", {}),
env: config.fetch("env", {}),
explicit: config.fetch("explicit", {}),
)
end
def self.canonicalize(config)
config.map { |k, v| [k.to_sym, Pathname(v).expand_path] }.to_h
end
attr_accessor :explicit
def initialize(default: nil, env: nil, explicit: {})
@default = self.class.canonicalize(default) if default
@env = self.class.canonicalize(env) if env
@explicit = self.class.canonicalize(explicit)
@env&.assert_valid_keys!(*DEFAULT_DIRS.keys)
@explicit.assert_valid_keys!(*DEFAULT_DIRS.keys)
end
def default
@default ||= self.class.canonicalize(DEFAULT_DIRS)
end
def env
@env ||= self.class.canonicalize(
Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", ""))
.select { |arg| arg.include?("=") }
.map { |arg| arg.split("=", 2) }
.map { |(flag, value)| [flag.sub(/^\-\-/, ""), value] },
)
end
def binarydir
@binarydir ||= HOMEBREW_PREFIX/"bin"
end
DEFAULT_DIRS.keys.each do |dir|
define_method(dir) do
explicit.fetch(dir, env.fetch(dir, default.fetch(dir)))
end
define_method(:"#{dir}=") do |path|
instance_variable_set(:"@#{dir}", Pathname(path).expand_path)
explicit[dir] = Pathname(path).expand_path
end
end
def merge(other)
self.class.new(explicit: other.explicit.merge(explicit))
end
def to_json(*args)
{
default: default,
env: env,
explicit: explicit,
}.to_json(*args)
end
end
end

View File

@ -57,7 +57,6 @@ module Cask
:appcast,
:artifacts,
:auto_updates,
:caskroom_path,
:caveats,
:conflicts_with,
:container,
@ -226,7 +225,7 @@ module Cask
end
def caskroom_path
@caskroom_path ||= Caskroom.path.join(token)
@cask.caskroom_path
end
def staged_path

View File

@ -4,6 +4,7 @@ require "formula_installer"
require "unpack_strategy"
require "cask/cask_dependencies"
require "cask/config"
require "cask/download"
require "cask/staged"
require "cask/verify"
@ -39,7 +40,7 @@ module Cask
end
attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?,
:upgrade?, :verbose?, :installed_as_dependency?,
:reinstall?, :upgrade?, :verbose?, :installed_as_dependency?,
:quarantine?
def self.print_caveats(cask)
@ -79,7 +80,9 @@ module Cask
def install
odebug "Cask::Installer#install"
if @cask.installed? && !force? && !@reinstall && !upgrade?
old_config = @cask.config
if @cask.installed? && !force? && !reinstall? && !upgrade?
raise CaskAlreadyInstalledError, @cask
end
@ -87,11 +90,14 @@ module Cask
print_caveats
fetch
uninstall_existing_cask if @reinstall
uninstall_existing_cask if reinstall?
oh1 "Installing Cask #{Formatter.identifier(@cask)}"
opoo "macOS's Gatekeeper has been disabled for this Cask" unless quarantine?
stage
@cask.config = Config.global.merge(old_config)
install_artifacts
unless @cask.tap&.private?
@ -209,6 +215,8 @@ module Cask
artifact.install_phase(command: @command, verbose: verbose?, force: force?)
already_installed_artifacts.unshift(artifact)
end
save_config_file
rescue => e
begin
already_installed_artifacts.each do |artifact|
@ -382,13 +390,23 @@ module Cask
old_savedir&.rmtree
end
def save_config_file
@cask.config_path.atomic_write(@cask.config.to_json)
end
def uninstall
oh1 "Uninstalling Cask #{Formatter.identifier(@cask)}"
uninstall_artifacts(clear: true)
remove_config_file unless reinstall? || upgrade?
purge_versioned_files
purge_caskroom_path if force?
end
def remove_config_file
FileUtils.rm_f @cask.config_path
@cask.config_path.parent.rmdir_if_possible
end
def start_upgrade
oh1 "Starting upgrade for Cask #{Formatter.identifier(@cask)}"

View File

@ -11,7 +11,7 @@ describe Cask::Artifact::App, :cask do
}
let(:source_path) { cask.staged_path.join("Caffeine.app") }
let(:target_path) { Cask::Config.global.appdir.join("AnotherName.app") }
let(:target_path) { cask.config.appdir.join("AnotherName.app") }
before do
InstallHelper.install_without_artifacts(cask)
@ -58,7 +58,7 @@ describe Cask::Artifact::App, :cask do
expect(target_path).to be_a_directory
expect(source_path).not_to exist
expect(Cask::Config.global.appdir.join("Caffeine Deluxe.app")).not_to exist
expect(cask.config.appdir.join("Caffeine Deluxe.app")).not_to exist
expect(cask.staged_path.join("Caffeine Deluxe.app")).to be_a_directory
end

View File

@ -5,7 +5,7 @@ describe Cask::Artifact::App, :cask do
let(:app) { cask.artifacts.find { |a| a.is_a?(described_class) } }
let(:source_path) { cask.staged_path.join("Caffeine.app") }
let(:target_path) { Cask::Config.global.appdir.join("Caffeine.app") }
let(:target_path) { cask.config.appdir.join("Caffeine.app") }
let(:install_phase) { app.install_phase(command: command, force: force) }
let(:uninstall_phase) { app.uninstall_phase(command: command, force: force) }
@ -53,7 +53,7 @@ describe Cask::Artifact::App, :cask do
expect(target_path).to be_a_directory
expect(source_path).not_to exist
expect(Cask::Config.global.appdir.join("Caffeine Deluxe.app")).not_to exist
expect(cask.config.appdir.join("Caffeine Deluxe.app")).not_to exist
expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist
end

View File

@ -5,7 +5,7 @@ describe Cask::Artifact::Binary, :cask do
end
}
let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } }
let(:expected_path) { Cask::Config.global.binarydir.join("binary") }
let(:expected_path) { cask.config.binarydir.join("binary") }
after do
FileUtils.rm expected_path if expected_path.exist?
@ -38,7 +38,7 @@ describe Cask::Artifact::Binary, :cask do
end
}
let(:expected_path) { Cask::Config.global.binarydir.join("naked_non_executable") }
let(:expected_path) { cask.config.binarydir.join("naked_non_executable") }
it "makes the binary executable" do
expect(FileUtils).to receive(:chmod)

View File

@ -10,7 +10,7 @@ describe Cask::Artifact::Artifact, :cask do
}
let(:source_path) { cask.staged_path.join("Caffeine.app") }
let(:target_path) { Cask::Config.global.appdir.join("Caffeine.app") }
let(:target_path) { cask.config.appdir.join("Caffeine.app") }
before do
InstallHelper.install_without_artifacts(cask)

View File

@ -2,7 +2,7 @@ describe Cask::Artifact::Installer, :cask do
subject(:installer) { described_class.new(cask, **args) }
let(:staged_path) { mktmpdir }
let(:cask) { instance_double(Cask::Cask, staged_path: staged_path, config: nil) }
let(:cask) { instance_double(Cask::Cask, staged_path: staged_path) }
let(:command) { SystemCommand }

View File

@ -9,7 +9,7 @@ describe Cask::Artifact::Suite, :cask do
end
}
let(:target_path) { Cask::Config.global.appdir.join("Caffeine") }
let(:target_path) { cask.config.appdir.join("Caffeine") }
let(:source_path) { cask.staged_path.join("Caffeine") }
before do

View File

@ -11,10 +11,10 @@ describe Cask::Artifact::App, :cask do
}
let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") }
let(:target_path_mini) { Cask::Config.global.appdir.join("Caffeine Mini.app") }
let(:target_path_mini) { cask.config.appdir.join("Caffeine Mini.app") }
let(:source_path_pro) { cask.staged_path.join("Caffeine Pro.app") }
let(:target_path_pro) { Cask::Config.global.appdir.join("Caffeine Pro.app") }
let(:target_path_pro) { cask.config.appdir.join("Caffeine Pro.app") }
before do
InstallHelper.install_without_artifacts(cask)
@ -52,7 +52,7 @@ describe Cask::Artifact::App, :cask do
expect(target_path_mini).to be_a_directory
expect(source_path_mini).not_to exist
expect(Cask::Config.global.appdir.join("Caffeine Deluxe.app")).not_to exist
expect(cask.config.appdir.join("Caffeine Deluxe.app")).not_to exist
expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist
end

View File

@ -1,7 +1,7 @@
require_relative "shared_examples/invalid_option"
describe Cask::Cmd::Audit, :cask do
let(:cask) { Cask::Cask.new(nil) }
let(:cask) { Cask::Cask.new("cask") }
it_behaves_like "a command that handles invalid options"

View File

@ -21,11 +21,12 @@ describe Cask::Cmd::Install, :cask do
it "allows staging and activation of multiple Casks at once" do
described_class.run("local-transmission", "local-caffeine")
expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed
expect(Cask::Config.global.appdir.join("Transmission.app")).to be_a_directory
expect(Cask::CaskLoader.load(cask_path("local-caffeine"))).to be_installed
expect(Cask::Config.global.appdir.join("Caffeine.app")).to be_a_directory
transmission = Cask::CaskLoader.load(cask_path("local-transmission"))
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
expect(transmission).to be_installed
expect(transmission.config.appdir.join("Transmission.app")).to be_a_directory
expect(caffeine).to be_installed
expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory
end
it "skips double install (without nuking existing installation)" do

View File

@ -80,9 +80,9 @@ describe Cask::Cmd::List, :cask do
described_class.run("local-transmission", "local-caffeine")
}.to output(<<~EOS).to_stdout
==> Apps
#{Cask::Config.global.appdir.join("Transmission.app")} (#{Cask::Config.global.appdir.join("Transmission.app").abv})
#{transmission.config.appdir.join("Transmission.app")} (#{transmission.config.appdir.join("Transmission.app").abv})
==> Apps
Missing App: #{Cask::Config.global.appdir.join("Caffeine.app")}
Missing App: #{caffeine.config.appdir.join("Caffeine.app")}
EOS
end
end

View File

@ -1,15 +1,11 @@
describe Cask::Cmd, :cask do
it "supports setting the appdir" do
allow(Cask::Config.global).to receive(:appdir).and_call_original
described_class.new.process_options("help", "--appdir=/some/path/foo")
expect(Cask::Config.global.appdir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the appdir from ENV" do
allow(Cask::Config.global).to receive(:appdir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"
described_class.new.process_options("help")
@ -18,16 +14,12 @@ describe Cask::Cmd, :cask do
end
it "supports setting the prefpanedir" do
allow(Cask::Config.global).to receive(:prefpanedir).and_call_original
described_class.new.process_options("help", "--prefpanedir=/some/path/foo")
expect(Cask::Config.global.prefpanedir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the prefpanedir from ENV" do
allow(Cask::Config.global).to receive(:prefpanedir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"
described_class.new.process_options("help")
@ -36,16 +28,12 @@ describe Cask::Cmd, :cask do
end
it "supports setting the qlplugindir" do
allow(Cask::Config.global).to receive(:qlplugindir).and_call_original
described_class.new.process_options("help", "--qlplugindir=/some/path/foo")
expect(Cask::Config.global.qlplugindir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the qlplugindir from ENV" do
allow(Cask::Config.global).to receive(:qlplugindir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"
described_class.new.process_options("help")
@ -54,16 +42,12 @@ describe Cask::Cmd, :cask do
end
it "supports setting the colorpickerdir" do
allow(Cask::Config.global).to receive(:colorpickerdir).and_call_original
described_class.new.process_options("help", "--colorpickerdir=/some/path/foo")
expect(Cask::Config.global.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the colorpickerdir from ENV" do
allow(Cask::Config.global).to receive(:colorpickerdir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"
described_class.new.process_options("help")
@ -72,16 +56,12 @@ describe Cask::Cmd, :cask do
end
it "supports setting the dictionarydir" do
allow(Cask::Config.global).to receive(:dictionarydir).and_call_original
described_class.new.process_options("help", "--dictionarydir=/some/path/foo")
expect(Cask::Config.global.dictionarydir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the dictionarydir from ENV" do
allow(Cask::Config.global).to receive(:dictionarydir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"
described_class.new.process_options("help")
@ -90,16 +70,12 @@ describe Cask::Cmd, :cask do
end
it "supports setting the fontdir" do
allow(Cask::Config.global).to receive(:fontdir).and_call_original
described_class.new.process_options("help", "--fontdir=/some/path/foo")
expect(Cask::Config.global.fontdir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the fontdir from ENV" do
allow(Cask::Config.global).to receive(:fontdir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"
described_class.new.process_options("help")
@ -108,16 +84,12 @@ describe Cask::Cmd, :cask do
end
it "supports setting the servicedir" do
allow(Cask::Config.global).to receive(:servicedir).and_call_original
described_class.new.process_options("help", "--servicedir=/some/path/foo")
expect(Cask::Config.global.servicedir).to eq(Pathname.new("/some/path/foo"))
end
it "supports setting the servicedir from ENV" do
allow(Cask::Config.global).to receive(:servicedir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"
described_class.new.process_options("help")
@ -126,8 +98,6 @@ describe Cask::Cmd, :cask do
end
it "allows additional options to be passed through" do
allow(Cask::Config.global).to receive(:appdir).and_call_original
rest = described_class.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux")
expect(Cask::Config.global.appdir).to eq(Pathname.new("/some/path/qux"))

View File

@ -51,9 +51,9 @@ describe Cask::Cmd::Uninstall, :cask do
described_class.run("local-caffeine", "local-transmission")
expect(caffeine).not_to be_installed
expect(Cask::Config.global.appdir.join("Transmission.app")).not_to exist
expect(caffeine.config.appdir.join("Transmission.app")).not_to exist
expect(transmission).not_to be_installed
expect(Cask::Config.global.appdir.join("Caffeine.app")).not_to exist
expect(transmission.config.appdir.join("Caffeine.app")).not_to exist
end
it "calls `uninstall` before removing artifacts" do
@ -69,7 +69,7 @@ describe Cask::Cmd::Uninstall, :cask do
}.not_to raise_error
expect(cask).not_to be_installed
expect(Cask::Config.global.appdir.join("MyFancyApp.app")).not_to exist
expect(cask.config.appdir.join("MyFancyApp.app")).not_to exist
end
it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do
@ -79,7 +79,7 @@ describe Cask::Cmd::Uninstall, :cask do
expect(cask).to be_installed
Cask::Config.global.appdir.join("MyFancyApp.app").rmtree
cask.config.appdir.join("MyFancyApp.app").rmtree
expect { described_class.run("with-uninstall-script-app") }
.to raise_error(Cask::CaskError, /uninstall script .* does not exist/)

View File

@ -147,7 +147,7 @@ describe Cask::Cmd::Upgrade, :cask do
it 'does not include the Casks with "auto_updates true" when the version did not change' do
cask = Cask::CaskLoader.load("auto-updates")
cask_path = Cask::Config.global.appdir.join("MyFancyApp.app")
cask_path = cask.config.appdir.join("MyFancyApp.app")
expect(cask).to be_installed
expect(cask_path).to be_a_directory
@ -188,7 +188,7 @@ describe Cask::Cmd::Upgrade, :cask do
it "restores the old Cask if the upgrade failed" do
will_fail_if_upgraded = Cask::CaskLoader.load("will-fail-if-upgraded")
will_fail_if_upgraded_path = Cask::Config.global.appdir.join("container")
will_fail_if_upgraded_path = will_fail_if_upgraded.config.appdir.join("container")
expect(will_fail_if_upgraded).to be_installed
expect(will_fail_if_upgraded_path).to be_a_file
@ -206,7 +206,7 @@ describe Cask::Cmd::Upgrade, :cask do
it "does not restore the old Cask if the upgrade failed pre-install" do
bad_checksum = Cask::CaskLoader.load("bad-checksum")
bad_checksum_path = Cask::Config.global.appdir.join("Caffeine.app")
bad_checksum_path = bad_checksum.config.appdir.join("Caffeine.app")
expect(bad_checksum).to be_installed
expect(bad_checksum_path).to be_a_directory

View File

@ -23,8 +23,8 @@ describe Cask::Cmd::Zap, :cask do
described_class.run("local-caffeine", "local-transmission")
expect(caffeine).not_to be_installed
expect(Cask::Config.global.appdir.join("Caffeine.app")).not_to be_a_symlink
expect(caffeine.config.appdir.join("Caffeine.app")).not_to be_a_symlink
expect(transmission).not_to be_installed
expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_a_symlink
expect(transmission.config.appdir.join("Transmission.app")).not_to be_a_symlink
end
end

View File

@ -56,9 +56,7 @@ describe Cask::Cmd, :cask do
end
it "respects the env variable when choosing what appdir to create" do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--appdir=/custom/appdir")
allow(Cask::Config.global).to receive(:appdir).and_call_original
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/custom/appdir"
described_class.run("noop")

View File

@ -0,0 +1,51 @@
describe Cask::Config, :cask do
subject(:config) { described_class.new }
describe "#default" do
it "returns the default directories" do
expect(config.default[:appdir]).to eq(Pathname(TEST_TMPDIR).join("cask-appdir"))
end
end
describe "#appdir" do
it "returns the default value if no HOMEBREW_CASK_OPTS is unset" do
expect(config.appdir).to eq(Pathname(TEST_TMPDIR).join("cask-appdir"))
end
specify "environment overwrites default" do
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/path/to/apps"
expect(config.appdir).to eq(Pathname("/path/to/apps"))
end
specify "specific overwrites default" do
config = described_class.new(explicit: { appdir: "/explicit/path/to/apps" })
expect(config.appdir).to eq(Pathname("/explicit/path/to/apps"))
end
specify "explicit overwrites environment" do
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/path/to/apps"
config = described_class.new(explicit: { appdir: "/explicit/path/to/apps" })
expect(config.appdir).to eq(Pathname("/explicit/path/to/apps"))
end
end
describe "#env" do
it "returns directories specified with the HOMEBREW_CASK_OPTS variable" do
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/path/to/apps"
expect(config.env).to eq(appdir: Pathname("/path/to/apps"))
end
end
describe "#explicit" do
let(:config) { described_class.new(explicit: { appdir: "/explicit/path/to/apps" }) }
it "returns directories explicitly given as arguments" do
expect(config.explicit[:appdir]).to eq(Pathname("/explicit/path/to/apps"))
end
end
end

View File

@ -468,7 +468,7 @@ describe Cask::DSL, :cask do
let(:token) { "appdir-interpolation" }
it "is allowed" do
expect(cask.artifacts.first.source).to eq(Cask::Config.global.appdir/"some/path")
expect(cask.artifacts.first.source).to eq(cask.config.appdir/"some/path")
end
end

View File

@ -10,7 +10,7 @@ describe Cask::Installer, :cask do
Cask::Installer.new(caffeine).install
expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).to be_a_directory
expect(Cask::Config.global.appdir.join("Caffeine.app")).to be_a_directory
expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory
end
it "works with dmg-based Casks" do
@ -19,7 +19,7 @@ describe Cask::Installer, :cask do
Cask::Installer.new(asset).install
expect(Cask::Caskroom.path.join("container-dmg", asset.version)).to be_a_directory
expect(Cask::Config.global.appdir.join("container")).to be_a_file
expect(asset.config.appdir.join("container")).to be_a_file
end
it "works with tar-gz-based Casks" do
@ -28,7 +28,7 @@ describe Cask::Installer, :cask do
Cask::Installer.new(asset).install
expect(Cask::Caskroom.path.join("container-tar-gz", asset.version)).to be_a_directory
expect(Cask::Config.global.appdir.join("container")).to be_a_file
expect(asset.config.appdir.join("container")).to be_a_file
end
it "works with xar-based Casks" do
@ -37,7 +37,7 @@ describe Cask::Installer, :cask do
Cask::Installer.new(asset).install
expect(Cask::Caskroom.path.join("container-xar", asset.version)).to be_a_directory
expect(Cask::Config.global.appdir.join("container")).to be_a_file
expect(asset.config.appdir.join("container")).to be_a_file
end
it "works with pure bzip2-based Casks" do
@ -46,7 +46,7 @@ describe Cask::Installer, :cask do
Cask::Installer.new(asset).install
expect(Cask::Caskroom.path.join("container-bzip2", asset.version)).to be_a_directory
expect(Cask::Config.global.appdir.join("container")).to be_a_file
expect(asset.config.appdir.join("container")).to be_a_file
end
it "works with pure gzip-based Casks" do
@ -55,7 +55,7 @@ describe Cask::Installer, :cask do
Cask::Installer.new(asset).install
expect(Cask::Caskroom.path.join("container-gzip", asset.version)).to be_a_directory
expect(Cask::Config.global.appdir.join("container")).to be_a_file
expect(asset.config.appdir.join("container")).to be_a_file
end
it "blows up on a bad checksum" do

View File

@ -11,13 +11,11 @@ describe Cask::Quarantine, :cask do
it "quarantines a nice fresh Cask" do
Cask::Cmd::Install.run("local-transmission")
expect(
Cask::CaskLoader.load(cask_path("local-transmission")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("local-transmission"))
expect(
Cask::Config.global.appdir.join("Transmission.app"),
).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("Transmission.app")).to be_quarantined
end
it "quarantines Cask fetches" do
@ -42,83 +40,81 @@ describe Cask::Quarantine, :cask do
Cask::Cmd::Install.run("local-transmission")
expect(
Cask::CaskLoader.load(cask_path("local-transmission")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("local-transmission"))
expect(Cask::Config.global.appdir.join("Transmission.app")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("Transmission.app")).to be_quarantined
end
it "quarantines dmg-based Casks" do
Cask::Cmd::Install.run("container-dmg")
expect(
Cask::CaskLoader.load(cask_path("container-dmg")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-dmg"))
expect(Cask::Config.global.appdir.join("container")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).to be_quarantined
end
it "quarantines tar-gz-based Casks" do
Cask::Cmd::Install.run("container-tar-gz")
expect(
Cask::CaskLoader.load(cask_path("container-tar-gz")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-tar-gz"))
expect(Cask::Config.global.appdir.join("container")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).to be_quarantined
end
it "quarantines xar-based Casks" do
Cask::Cmd::Install.run("container-xar")
expect(
Cask::CaskLoader.load(cask_path("container-xar")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-xar"))
expect(Cask::Config.global.appdir.join("container")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).to be_quarantined
end
it "quarantines pure bzip2-based Casks" do
Cask::Cmd::Install.run("container-bzip2")
expect(
Cask::CaskLoader.load(cask_path("container-bzip2")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-bzip2"))
expect(Cask::Config.global.appdir.join("container")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).to be_quarantined
end
it "quarantines pure gzip-based Casks" do
Cask::Cmd::Install.run("container-gzip")
expect(
Cask::CaskLoader.load(cask_path("container-gzip")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-gzip"))
expect(Cask::Config.global.appdir.join("container")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).to be_quarantined
end
it "quarantines the pkg in naked-pkg-based Casks" do
Cask::Cmd::Install.run("container-pkg")
naked_pkg = Cask::CaskLoader.load(cask_path("container-pkg"))
cask = Cask::CaskLoader.load(cask_path("container-pkg"))
expect(naked_pkg).to be_installed
expect(cask).to be_installed
expect(
Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg"),
).to be_quarantined
expect(cask.staged_path/"container.pkg").to be_quarantined
end
it "quarantines a nested container" do
Cask::Cmd::Install.run("nested-app")
expect(
Cask::CaskLoader.load(cask_path("nested-app")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("nested-app"))
expect(Cask::Config.global.appdir.join("MyNestedApp.app")).to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("MyNestedApp.app")).to be_quarantined
end
end
@ -126,11 +122,11 @@ describe Cask::Quarantine, :cask do
it "does not quarantine even a nice, fresh Cask" do
Cask::Cmd::Install.run("local-transmission", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("local-transmission")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("local-transmission"))
expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("Transmission.app")).not_to be_quarantined
end
it "does not quarantine Cask fetches" do
@ -155,61 +151,61 @@ describe Cask::Quarantine, :cask do
Cask::Cmd::Install.run("local-transmission", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("local-transmission")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("local-transmission"))
expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("Transmission.app")).not_to be_quarantined
end
it "does not quarantine dmg-based Casks" do
Cask::Cmd::Install.run("container-dmg", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("container-dmg")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-dmg"))
expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).not_to be_quarantined
end
it "does not quarantine tar-gz-based Casks" do
Cask::Cmd::Install.run("container-tar-gz", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("container-tar-gz")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-tar-gz"))
expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).not_to be_quarantined
end
it "does not quarantine xar-based Casks" do
Cask::Cmd::Install.run("container-xar", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("container-xar")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-xar"))
expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).not_to be_quarantined
end
it "does not quarantine pure bzip2-based Casks" do
Cask::Cmd::Install.run("container-bzip2", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("container-bzip2")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-bzip2"))
expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).not_to be_quarantined
end
it "does not quarantine pure gzip-based Casks" do
Cask::Cmd::Install.run("container-gzip", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("container-gzip")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("container-gzip"))
expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("container")).not_to be_quarantined
end
it "does not quarantine the pkg in naked-pkg-based Casks" do
@ -227,11 +223,11 @@ describe Cask::Quarantine, :cask do
it "does not quarantine a nested container" do
Cask::Cmd::Install.run("nested-app", "--no-quarantine")
expect(
Cask::CaskLoader.load(cask_path("nested-app")),
).to be_installed
cask = Cask::CaskLoader.load(cask_path("nested-app"))
expect(Cask::Config.global.appdir.join("MyNestedApp.app")).not_to be_quarantined
expect(cask).to be_installed
expect(cask.config.appdir.join("MyNestedApp.app")).not_to be_quarantined
end
end
end

View File

@ -4,25 +4,34 @@ require "test/support/helper/cask/fake_system_command"
require "test/support/helper/cask/install_helper"
require "test/support/helper/cask/never_sudo_system_command"
HOMEBREW_CASK_DIRS = {
appdir: Pathname.new(TEST_TMPDIR).join("cask-appdir"),
prefpanedir: Pathname.new(TEST_TMPDIR).join("cask-prefpanedir"),
qlplugindir: Pathname.new(TEST_TMPDIR).join("cask-qlplugindir"),
servicedir: Pathname.new(TEST_TMPDIR).join("cask-servicedir"),
}.freeze
module Cask
class Config
remove_const :DEFAULT_DIRS
DEFAULT_DIRS = {
appdir: Pathname(TEST_TMPDIR)/"cask-appdir",
prefpanedir: Pathname(TEST_TMPDIR)/"cask-prefpanedir",
qlplugindir: Pathname(TEST_TMPDIR)/"cask-qlplugindir",
dictionarydir: Pathname(TEST_TMPDIR)/"cask-dictionarydir",
fontdir: Pathname(TEST_TMPDIR)/"cask-fontdir",
colorpickerdir: Pathname(TEST_TMPDIR)/"cask-colorpickerdir",
servicedir: Pathname(TEST_TMPDIR)/"cask-servicedir",
input_methoddir: Pathname(TEST_TMPDIR)/"cask-input_methoddir",
internet_plugindir: Pathname(TEST_TMPDIR)/"cask-internet_plugindir",
audio_unit_plugindir: Pathname(TEST_TMPDIR)/"cask-audio_unit_plugindir",
vst_plugindir: Pathname(TEST_TMPDIR)/"cask-vst_plugindir",
vst3_plugindir: Pathname(TEST_TMPDIR)/"cask-vst3_plugindir",
screen_saverdir: Pathname(TEST_TMPDIR)/"cask-screen_saverdir",
}.freeze
end
end
RSpec.shared_context "Homebrew Cask", :needs_macos do
before do
HOMEBREW_CASK_DIRS.each do |method, path|
allow(Cask::Config.global).to receive(method).and_return(path)
end
end
around do |example|
third_party_tap = Tap.fetch("third-party", "tap")
begin
HOMEBREW_CASK_DIRS.values.each(&:mkpath)
begin
Cask::Config::DEFAULT_DIRS.values.each(&:mkpath)
Cask::Config.global.binarydir.mkpath
Tap.default_cask_tap.tap do |tap|
@ -37,11 +46,12 @@ RSpec.shared_context "Homebrew Cask", :needs_macos do
example.run
ensure
FileUtils.rm_rf HOMEBREW_CASK_DIRS.values
FileUtils.rm_rf Cask::Config::DEFAULT_DIRS.values
FileUtils.rm_rf [Cask::Config.global.binarydir, Cask::Caskroom.path, Cask::Cache.path]
Tap.default_cask_tap.path.unlink
third_party_tap.path.unlink
FileUtils.rm_rf third_party_tap.path.parent
Cask::Config.clear
end
end
end