Merge pull request #17757 from krehel/fix-cask-info

This commit is contained in:
Rylan Polster 2024-07-15 14:07:25 -04:00 committed by GitHub
commit d4910cc490
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 28 deletions

View File

@ -42,16 +42,15 @@ module Cask
return "Not installed" unless cask.installed? return "Not installed" unless cask.installed?
versioned_staged_path = cask.caskroom_path.join(cask.installed_version) versioned_staged_path = cask.caskroom_path.join(cask.installed_version)
path_details = if versioned_staged_path.exist?
versioned_staged_path.abv return "Installed\n#{versioned_staged_path} (#{Formatter.error("does not exist")})\n" unless versioned_staged_path.exist?
else
Formatter.error("does not exist") path_details = versioned_staged_path.children.sum(&:disk_usage)
end
tab = Tab.for_cask(cask) tab = Tab.for_cask(cask)
info = ["Installed"] info = ["Installed"]
info << "#{versioned_staged_path} (#{path_details})" info << "#{versioned_staged_path} (#{disk_usage_readable(path_details)})"
info << " #{tab}" if tab.tabfile&.exist? info << " #{tab}" if tab.tabfile&.exist?
info.join("\n") info.join("\n")
end end

View File

@ -123,10 +123,14 @@ RSpec.describe Cask::Info, :cask do
end end
it "prints install information for an installed Cask" do it "prints install information for an installed Cask" do
mktmpdir do |caskroom|
FileUtils.mkdir caskroom/"2.61"
cask = Cask::CaskLoader.load("local-transmission") cask = Cask::CaskLoader.load("local-transmission")
time = 1_720_189_863 time = 1_720_189_863
tab = Cask::Tab.new(loaded_from_api: true, tabfile: TEST_FIXTURE_DIR/"cask_receipt.json", time:) tab = Cask::Tab.new(loaded_from_api: true, tabfile: TEST_FIXTURE_DIR/"cask_receipt.json", time:)
expect(cask).to receive(:installed?).and_return(true) expect(cask).to receive(:installed?).and_return(true)
expect(cask).to receive(:caskroom_path).and_return(caskroom)
expect(cask).to receive(:installed_version).and_return("2.61") expect(cask).to receive(:installed_version).and_return("2.61")
expect(Cask::Tab).to receive(:for_cask).with(cask).and_return(tab) expect(Cask::Tab).to receive(:for_cask).with(cask).and_return(tab)
@ -136,7 +140,7 @@ RSpec.describe Cask::Info, :cask do
==> local-transmission: 2.61 ==> local-transmission: 2.61
https://transmissionbt.com/ https://transmissionbt.com/
Installed Installed
#{HOMEBREW_PREFIX}/Caskroom/local-transmission/2.61 (does not exist) #{caskroom}/2.61 (0B)
Installed using the formulae.brew.sh API on #{Time.at(time).strftime("%Y-%m-%d at %H:%M:%S")} Installed using the formulae.brew.sh API on #{Time.at(time).strftime("%Y-%m-%d at %H:%M:%S")}
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/l/local-transmission.rb From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/l/local-transmission.rb
==> Name ==> Name
@ -147,4 +151,5 @@ RSpec.describe Cask::Info, :cask do
Transmission.app (App) Transmission.app (App)
EOS EOS
end end
end
end end