Merge pull request #7451 from claui/fix-cask-loading-this-time-for-real

Cask loader: add missing canonicalisation
This commit is contained in:
Mike McQuaid 2020-04-27 16:19:01 +01:00 committed by GitHub
commit 223b66bcdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 7 deletions

View File

@ -34,15 +34,15 @@ module Cask
def self.for_cask(cask)
if cask.config_path.exist?
from_file(cask.config_path)
from_json(File.read(cask.config_path))
else
global
end
end
def self.from_file(path)
def self.from_json(json)
config = begin
JSON.parse(File.read(path))
JSON.parse(json)
rescue JSON::ParserError => e
raise e, "Cannot parse #{path}: #{e}", e.backtrace
end
@ -69,7 +69,7 @@ module Cask
attr_accessor :explicit
def initialize(default: nil, env: nil, explicit: {})
@default = DEFAULT_DIRS.merge(self.class.canonicalize(default)) if default
@default = self.class.canonicalize(DEFAULT_DIRS.merge(default)) if default
@env = self.class.canonicalize(env) if env
@explicit = self.class.canonicalize(explicit)

View File

@ -3,6 +3,21 @@
describe Cask::Config, :cask do
subject(:config) { described_class.new }
describe "::from_json" do
it "deserializes a configuration in JSON format" do
config = described_class.from_json <<~EOS
{
"default": {
"appdir": "/path/to/apps"
},
"env": {},
"explicit": {}
}
EOS
expect(config.appdir).to eq(Pathname("/path/to/apps"))
end
end
describe "#default" do
it "returns the default directories" do
expect(config.default[:appdir]).to eq(Pathname(TEST_TMPDIR).join("cask-appdir"))
@ -52,7 +67,18 @@ describe Cask::Config, :cask do
end
context "when installing a cask and then adding a global default dir" do
let(:config) { described_class.new(default: { appdir: "/default/path/before/adding/fontdir" }) }
let(:config) {
json = <<~EOS
{
"default": {
"appdir": "/default/path/before/adding/fontdir"
},
"env": {},
"explicit": {}
}
EOS
described_class.from_json(json)
}
describe "#appdir" do
it "honors metadata of the installed cask" do

View File

@ -10,7 +10,7 @@ module Cask
class Config
remove_const :DEFAULT_DIRS
DEFAULT_DIRS = {
DEFAULT_DIRS_PATHNAMES = {
appdir: Pathname(TEST_TMPDIR)/"cask-appdir",
prefpanedir: Pathname(TEST_TMPDIR)/"cask-prefpanedir",
qlplugindir: Pathname(TEST_TMPDIR)/"cask-qlplugindir",
@ -26,6 +26,8 @@ module Cask
vst3_plugindir: Pathname(TEST_TMPDIR)/"cask-vst3_plugindir",
screen_saverdir: Pathname(TEST_TMPDIR)/"cask-screen_saverdir",
}.freeze
DEFAULT_DIRS = DEFAULT_DIRS_PATHNAMES.transform_values(&:to_s).freeze
end
end
@ -34,7 +36,7 @@ RSpec.shared_context "Homebrew Cask", :needs_macos do
third_party_tap = Tap.fetch("third-party", "tap")
begin
Cask::Config::DEFAULT_DIRS.values.each(&:mkpath)
Cask::Config::DEFAULT_DIRS_PATHNAMES.values.each(&:mkpath)
Cask::Config.global.binarydir.mkpath
Tap.default_cask_tap.tap do |tap|