Merge pull request #7451 from claui/fix-cask-loading-this-time-for-real
Cask loader: add missing canonicalisation
This commit is contained in:
commit
223b66bcdc
@ -34,15 +34,15 @@ module Cask
|
|||||||
|
|
||||||
def self.for_cask(cask)
|
def self.for_cask(cask)
|
||||||
if cask.config_path.exist?
|
if cask.config_path.exist?
|
||||||
from_file(cask.config_path)
|
from_json(File.read(cask.config_path))
|
||||||
else
|
else
|
||||||
global
|
global
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_file(path)
|
def self.from_json(json)
|
||||||
config = begin
|
config = begin
|
||||||
JSON.parse(File.read(path))
|
JSON.parse(json)
|
||||||
rescue JSON::ParserError => e
|
rescue JSON::ParserError => e
|
||||||
raise e, "Cannot parse #{path}: #{e}", e.backtrace
|
raise e, "Cannot parse #{path}: #{e}", e.backtrace
|
||||||
end
|
end
|
||||||
@ -69,7 +69,7 @@ module Cask
|
|||||||
attr_accessor :explicit
|
attr_accessor :explicit
|
||||||
|
|
||||||
def initialize(default: nil, env: nil, 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
|
@env = self.class.canonicalize(env) if env
|
||||||
@explicit = self.class.canonicalize(explicit)
|
@explicit = self.class.canonicalize(explicit)
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,21 @@
|
|||||||
describe Cask::Config, :cask do
|
describe Cask::Config, :cask do
|
||||||
subject(:config) { described_class.new }
|
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
|
describe "#default" do
|
||||||
it "returns the default directories" do
|
it "returns the default directories" do
|
||||||
expect(config.default[:appdir]).to eq(Pathname(TEST_TMPDIR).join("cask-appdir"))
|
expect(config.default[:appdir]).to eq(Pathname(TEST_TMPDIR).join("cask-appdir"))
|
||||||
@ -52,7 +67,18 @@ describe Cask::Config, :cask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "when installing a cask and then adding a global default dir" do
|
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
|
describe "#appdir" do
|
||||||
it "honors metadata of the installed cask" do
|
it "honors metadata of the installed cask" do
|
||||||
|
|||||||
@ -10,7 +10,7 @@ module Cask
|
|||||||
class Config
|
class Config
|
||||||
remove_const :DEFAULT_DIRS
|
remove_const :DEFAULT_DIRS
|
||||||
|
|
||||||
DEFAULT_DIRS = {
|
DEFAULT_DIRS_PATHNAMES = {
|
||||||
appdir: Pathname(TEST_TMPDIR)/"cask-appdir",
|
appdir: Pathname(TEST_TMPDIR)/"cask-appdir",
|
||||||
prefpanedir: Pathname(TEST_TMPDIR)/"cask-prefpanedir",
|
prefpanedir: Pathname(TEST_TMPDIR)/"cask-prefpanedir",
|
||||||
qlplugindir: Pathname(TEST_TMPDIR)/"cask-qlplugindir",
|
qlplugindir: Pathname(TEST_TMPDIR)/"cask-qlplugindir",
|
||||||
@ -26,6 +26,8 @@ module Cask
|
|||||||
vst3_plugindir: Pathname(TEST_TMPDIR)/"cask-vst3_plugindir",
|
vst3_plugindir: Pathname(TEST_TMPDIR)/"cask-vst3_plugindir",
|
||||||
screen_saverdir: Pathname(TEST_TMPDIR)/"cask-screen_saverdir",
|
screen_saverdir: Pathname(TEST_TMPDIR)/"cask-screen_saverdir",
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
DEFAULT_DIRS = DEFAULT_DIRS_PATHNAMES.transform_values(&:to_s).freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ RSpec.shared_context "Homebrew Cask", :needs_macos do
|
|||||||
third_party_tap = Tap.fetch("third-party", "tap")
|
third_party_tap = Tap.fetch("third-party", "tap")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Cask::Config::DEFAULT_DIRS.values.each(&:mkpath)
|
Cask::Config::DEFAULT_DIRS_PATHNAMES.values.each(&:mkpath)
|
||||||
Cask::Config.global.binarydir.mkpath
|
Cask::Config.global.binarydir.mkpath
|
||||||
|
|
||||||
Tap.default_cask_tap.tap do |tap|
|
Tap.default_cask_tap.tap do |tap|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user