brew/Library/Homebrew/test/cask/reinstall_spec.rb

71 lines
2.4 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
require "cask/installer"
require "cask/reinstall"
describe Cask::Reinstall, :cask do
it "displays the reinstallation progress" do
2018-09-06 08:29:14 +02:00
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
2018-09-06 08:29:14 +02:00
Cask::Installer.new(caffeine).install
2017-10-15 02:28:32 +02:00
output = Regexp.new <<~EOS
==> Downloading file:.*caffeine.zip
2018-04-29 05:34:32 +02:00
Already downloaded: .*--caffeine.zip
==> Uninstalling Cask local-caffeine
2021-01-26 15:21:24 -05:00
==> Backing App 'Caffeine.app' up to '.*Caffeine.app'
==> Removing App '.*Caffeine.app'
2017-11-10 10:05:18 -03:00
==> Purging files for version 1.2.3 of Cask local-caffeine
==> Installing Cask local-caffeine
2021-01-26 15:21:24 -05:00
==> Moving App 'Caffeine.app' to '.*Caffeine.app'
.*local-caffeine was successfully installed!
EOS
expect do
described_class.reinstall_casks(Cask::CaskLoader.load("local-caffeine"))
end.to output(output).to_stdout
end
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
it "displays the reinstallation progress with zapping" do
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
Cask::Installer.new(caffeine).install
output = Regexp.new <<~EOS
==> Downloading file:.*caffeine.zip
Already downloaded: .*--caffeine.zip
==> Implied `brew uninstall --cask local-caffeine`
==> Backing App 'Caffeine.app' up to '.*Caffeine.app'
==> Removing App '.*Caffeine.app'
==> Dispatching zap stanza
==> Trashing files:
2022-12-13 10:54:22 +00:00
.*org.example.caffeine.plist
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
==> Removing all staged versions of Cask 'local-caffeine'
==> Installing Cask local-caffeine
==> Moving App 'Caffeine.app' to '.*Caffeine.app'
.*local-caffeine was successfully installed!
EOS
expect do
described_class.reinstall_casks(Cask::CaskLoader.load("local-caffeine"), zap: true)
end.to output(output).to_stdout
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
end
2017-02-08 13:29:46 +01:00
it "allows reinstalling a Cask" do
2018-09-06 08:29:14 +02:00
Cask::Cmd::Install.run("local-transmission")
2017-07-29 19:55:05 +02:00
2018-09-06 08:29:14 +02:00
expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed
2017-02-08 13:29:46 +01:00
described_class.reinstall_casks(Cask::CaskLoader.load("local-transmission"))
2018-09-06 08:29:14 +02:00
expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed
2017-02-08 13:29:46 +01:00
end
it "allows reinstalling a non installed Cask" do
2018-09-06 08:29:14 +02:00
expect(Cask::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed
2017-02-08 13:29:46 +01:00
described_class.reinstall_casks(Cask::CaskLoader.load("local-transmission"))
2018-09-06 08:29:14 +02:00
expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed
2017-02-08 13:29:46 +01:00
end
end