brew/Library/Homebrew/test/cask/cmd/list_spec.rb

278 lines
7.8 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2018-09-06 08:29:14 +02:00
describe Cask::Cmd::List, :cask do
2016-08-18 22:11:42 +03:00
it "lists the installed Casks in a pretty fashion" do
2018-09-06 08:29:14 +02:00
casks = %w[local-caffeine local-transmission].map { |c| Cask::CaskLoader.load(c) }
2016-08-18 22:11:42 +03:00
casks.each do |c|
2017-02-08 12:37:45 +01:00
InstallHelper.install_with_caskfile(c)
2016-08-18 22:11:42 +03:00
end
2017-02-08 12:37:45 +01:00
expect {
2017-10-03 10:49:58 +02:00
described_class.run
2017-10-15 02:28:32 +02:00
}.to output(<<~EOS).to_stdout
2016-08-18 22:11:42 +03:00
local-caffeine
local-transmission
EOS
end
2020-07-09 22:58:48 +02:00
it "lists oneline" do
casks = %w[
local-caffeine
third-party/tap/third-party-cask
local-transmission
].map { |c| Cask::CaskLoader.load(c) }
casks.each do |c|
InstallHelper.install_with_caskfile(c)
end
expect {
described_class.run("-1")
}.to output(<<~EOS).to_stdout
local-caffeine
local-transmission
third-party-cask
EOS
end
it "lists full names" do
casks = %w[
local-caffeine
third-party/tap/third-party-cask
local-transmission
2018-09-06 08:29:14 +02:00
].map { |c| Cask::CaskLoader.load(c) }
casks.each do |c|
InstallHelper.install_with_caskfile(c)
end
expect {
2017-10-03 10:49:58 +02:00
described_class.run("--full-name")
2017-10-15 02:28:32 +02:00
}.to output(<<~EOS).to_stdout
local-caffeine
local-transmission
third-party/tap/third-party-cask
EOS
end
2016-08-18 22:11:42 +03:00
describe "lists versions" do
let(:casks) { ["local-caffeine", "local-transmission"] }
2017-02-08 12:37:45 +01:00
let(:expected_output) {
2017-10-15 02:28:32 +02:00
<<~EOS
2016-08-18 22:11:42 +03:00
local-caffeine 1.2.3
local-transmission 2.61
EOS
}
before do
2018-09-06 08:29:14 +02:00
casks.map(&Cask::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
2016-08-18 22:11:42 +03:00
end
it "of all installed Casks" do
2017-02-08 12:37:45 +01:00
expect {
2017-10-03 10:49:58 +02:00
described_class.run("--versions")
2017-02-08 12:37:45 +01:00
}.to output(expected_output).to_stdout
2016-08-18 22:11:42 +03:00
end
it "of given Casks" do
2017-02-08 12:37:45 +01:00
expect {
2017-10-03 10:49:58 +02:00
described_class.run("--versions", "local-caffeine", "local-transmission")
2020-07-09 22:58:48 +02:00
}.to output(expected_output).to_stdout
end
end
describe "lists json" do
let(:casks) { ["local-caffeine", "local-transmission", "multiple-versions", "third-party/tap/third-party-cask"] }
2020-07-09 22:58:48 +02:00
let(:expected_output) {
<<~EOS
[
{
"token": "local-caffeine",
"full_token": "local-caffeine",
"tap": "homebrew/cask",
"name": [
],
"desc": null,
"homepage": "https://brew.sh/",
2021-06-15 20:47:20 -07:00
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip",
"appcast": null,
"version": "1.2.3",
"versions": {
},
"installed": "1.2.3",
"outdated": false,
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
"artifacts": [
[
"Caffeine.app"
cask/reinstall: Support `--zap` for entirely purging cask files - The `brew uninstall` command has `--zap`, so let's make `brew reinstall` have parity here for a better user experience. (Requested in issue 12983.) - It feels weird that to get my new reinstall test to pass I had to add `--zap` to `cask/cmd/install.rb`, not `cask/cmd/reinstall.rb` to get the tests to pass. But the `brew reinstall --cask caffeine --zap` command worked fine all the time. The CLI argument parser from the test run was complaining about not knowing what `zap` was. As a result, `--zap` now shows up as a switch in `brew install --help` which I'm not 100% convinced is the desired UX. But I've edited the description accordingly to specify that it will only work on `reinstall` operations (and `--zap` on `install` is a no-op). ``` issyl0 at pictor in /opt/homebrew on reinstall-cask-zap ❯ brew reinstall --cask caffeine --zap ==> Downloading https://github.com/IntelliScape/caffeine/releases/download/1.1.3/Caffeine.dmg Already downloaded: /Users/issyl0/Library/Caches/Homebrew/downloads/3d6ccfdd3b8d0ab37d1c2468d6e69078c2d31d3b12bf51947c4db21e5f376af2--Caffeine.dmg ==> Implied `brew uninstall --cask caffeine` ==> Backing App 'Caffeine.app' up to '/opt/homebrew/Caskroom/caffeine/1.1.3/Caffeine.app' ==> Removing App '/Applications/Caffeine.app' ==> Dispatching zap stanza ==> Trashing files: ~/Library/Application Support/com.intelliscapesolutions.caffeine ~/Library/Preferences/com.intelliscapesolutions.caffeine.plist ~/Library/Caches/com.intelliscapesolutions.caffeine ~/Library/HTTPStoages/com.intelliscapesolutions.caffeine.binarycookies ==> Removing all staged versions of Cask 'caffeine' ==> Installing Cask caffeine ==> Moving App 'Caffeine.app' to '/Applications/Caffeine.app' 🍺 caffeine was successfully installed! ```
2022-04-05 00:57:33 +01:00
],
{
"trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist",
"signal": {
}
}
],
"caveats": null,
"depends_on": {
},
"conflicts_with": null,
"container": null,
2022-07-21 16:41:23 +02:00
"auto_updates": null
},
{
"token": "local-transmission",
"full_token": "local-transmission",
"tap": "homebrew/cask",
"name": [
"Transmission"
],
"desc": "BitTorrent client",
"homepage": "https://transmissionbt.com/",
2021-06-15 20:47:20 -07:00
"url": "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg",
"appcast": null,
"version": "2.61",
"versions": {
},
"installed": "2.61",
"outdated": false,
"sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68",
"artifacts": [
[
"Transmission.app"
]
],
"caveats": null,
"depends_on": {
},
"conflicts_with": null,
"container": null,
2022-07-21 16:41:23 +02:00
"auto_updates": null
},
{
"token": "multiple-versions",
"full_token": "multiple-versions",
"tap": "homebrew/cask",
"name": [
],
"desc": null,
"homepage": "https://brew.sh/",
2022-08-09 11:34:52 -04:00
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin-arm64/1.2.3/arm.zip",
"appcast": null,
"version": "1.2.3",
"versions": {
"big_sur": "1.2.0",
"catalina": "1.0.0",
"mojave": "1.0.0"
},
"installed": "1.2.3",
"outdated": false,
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
"artifacts": [
[
"Caffeine.app"
]
],
"caveats": null,
"depends_on": {
},
"conflicts_with": null,
"container": null,
2022-07-21 16:41:23 +02:00
"auto_updates": null
},
{
"token": "third-party-cask",
"full_token": "third-party/tap/third-party-cask",
"tap": "third-party/tap",
"name": [
],
"desc": null,
"homepage": "https://brew.sh/",
"url": "https://brew.sh/ThirdParty.dmg",
"appcast": null,
"version": "1.2.3",
"versions": {
},
"installed": "1.2.3",
"outdated": false,
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b",
"artifacts": [
[
"ThirdParty.app"
]
],
"caveats": null,
"depends_on": {
},
"conflicts_with": null,
"container": null,
2022-07-21 16:41:23 +02:00
"auto_updates": null
}
]
2020-07-09 22:58:48 +02:00
EOS
}
let!(:original_macos_version) { MacOS.full_version.to_s }
2020-07-09 22:58:48 +02:00
before do
# Use a more limited symbols list to shorten the variations hash
symbols = {
monterey: "12",
big_sur: "11",
catalina: "10.15",
mojave: "10.14",
}
2022-06-29 11:29:46 -04:00
stub_const("MacOSVersions::SYMBOLS", symbols)
# For consistency, always run on Monterey and ARM
MacOS.full_version = "12"
allow(Hardware::CPU).to receive(:type).and_return(:arm)
2022-06-24 17:20:03 -04:00
casks.map(&Cask::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
end
after do
MacOS.full_version = original_macos_version
2020-07-09 22:58:48 +02:00
end
it "of all installed Casks" do
expect {
described_class.run("--json")
}.to output(expected_output).to_stdout
end
it "of given Casks" do
expect {
described_class.run("--json", "local-caffeine", "local-transmission", "multiple-versions",
"third-party/tap/third-party-cask")
2017-02-08 12:37:45 +01:00
}.to output(expected_output).to_stdout
2016-08-18 22:11:42 +03:00
end
end
describe "given a set of installed Casks" do
2018-09-06 08:29:14 +02:00
let(:caffeine) { Cask::CaskLoader.load(cask_path("local-caffeine")) }
let(:transmission) { Cask::CaskLoader.load(cask_path("local-transmission")) }
2016-08-18 22:11:42 +03:00
let(:casks) { [caffeine, transmission] }
it "lists the installed files for those Casks" do
2017-02-08 12:37:45 +01:00
casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile))
2016-08-18 22:11:42 +03:00
2018-09-06 08:29:14 +02:00
transmission.artifacts.select { |a| a.is_a?(Cask::Artifact::App) }.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
2016-08-18 22:11:42 +03:00
2017-02-08 12:37:45 +01:00
expect {
2017-10-03 10:49:58 +02:00
described_class.run("local-transmission", "local-caffeine")
2017-10-15 02:28:32 +02:00
}.to output(<<~EOS).to_stdout
2020-08-14 23:12:17 +02:00
==> App
2019-02-02 17:11:37 +01:00
#{transmission.config.appdir.join("Transmission.app")} (#{transmission.config.appdir.join("Transmission.app").abv})
2020-08-14 23:12:17 +02:00
==> App
2019-02-02 17:11:37 +01:00
Missing App: #{caffeine.config.appdir.join("Caffeine.app")}
EOS
2016-08-18 22:11:42 +03:00
end
end
end