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,28 +123,33 @@ 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
cask = Cask::CaskLoader.load("local-transmission") mktmpdir do |caskroom|
time = 1_720_189_863 FileUtils.mkdir caskroom/"2.61"
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_version).and_return("2.61")
expect(Cask::Tab).to receive(:for_cask).with(cask).and_return(tab)
expect do cask = Cask::CaskLoader.load("local-transmission")
described_class.info(cask) time = 1_720_189_863
end.to output(<<~EOS).to_stdout tab = Cask::Tab.new(loaded_from_api: true, tabfile: TEST_FIXTURE_DIR/"cask_receipt.json", time:)
==> local-transmission: 2.61 expect(cask).to receive(:installed?).and_return(true)
https://transmissionbt.com/ expect(cask).to receive(:caskroom_path).and_return(caskroom)
Installed expect(cask).to receive(:installed_version).and_return("2.61")
#{HOMEBREW_PREFIX}/Caskroom/local-transmission/2.61 (does not exist) expect(Cask::Tab).to receive(:for_cask).with(cask).and_return(tab)
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 expect do
==> Name described_class.info(cask)
Transmission end.to output(<<~EOS).to_stdout
==> Description ==> local-transmission: 2.61
BitTorrent client https://transmissionbt.com/
==> Artifacts Installed
Transmission.app (App) #{caskroom}/2.61 (0B)
EOS 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
==> Name
Transmission
==> Description
BitTorrent client
==> Artifacts
Transmission.app (App)
EOS
end
end end
end end