diff options
| author | Markus Reiter | 2017-11-27 23:41:03 +0100 |
|---|---|---|
| committer | GitHub | 2017-11-27 23:41:03 +0100 |
| commit | f50ae449800c85b53910bf294b9271c45c25da01 (patch) | |
| tree | e07111b8e02a4e2005faae4195af6743a5a9f88c /Library/Homebrew/test/cask/cli | |
| parent | f7baa3b380c1ed38d78da054c99b1b5f3678a645 (diff) | |
| parent | 8abe60d2dc3f010112aa671a82e4dceb22c11e5b (diff) | |
| download | brew-f50ae449800c85b53910bf294b9271c45c25da01.tar.bz2 | |
Merge pull request #3396 from amyspark/hacktoberfest-upgrade
Implement `brew cask upgrade`
Diffstat (limited to 'Library/Homebrew/test/cask/cli')
| -rw-r--r-- | Library/Homebrew/test/cask/cli/reinstall_spec.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/uninstall_spec.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/upgrade_spec.rb | 211 |
3 files changed, 215 insertions, 2 deletions
diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb index 5e551e5b5..3737a7a70 100644 --- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb @@ -13,7 +13,8 @@ describe Hbc::CLI::Reinstall, :cask do Already downloaded: .*local-caffeine--1.2.3.zip ==> Verifying checksum for Cask local-caffeine ==> Uninstalling Cask local-caffeine - ==> Removing App '.*Caffeine.app'. + ==> Moving App 'Caffeine.app' back to '.*Caffeine.app'. + ==> Purging files for version 1.2.3 of Cask local-caffeine ==> Installing Cask local-caffeine ==> Moving App 'Caffeine.app' to '.*Caffeine.app'. .*local-caffeine was successfully installed! diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 1ab8f7e4d..345e1b9f2 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -12,7 +12,8 @@ describe Hbc::CLI::Uninstall, :cask do output = Regexp.new <<~EOS ==> Uninstalling Cask local-caffeine - ==> Removing App '.*Caffeine.app'. + ==> Moving App 'Caffeine.app' back to '.*Caffeine.app'. + ==> Purging files for version 1.2.3 of Cask local-caffeine EOS expect { diff --git a/Library/Homebrew/test/cask/cli/upgrade_spec.rb b/Library/Homebrew/test/cask/cli/upgrade_spec.rb new file mode 100644 index 000000000..5f389d695 --- /dev/null +++ b/Library/Homebrew/test/cask/cli/upgrade_spec.rb @@ -0,0 +1,211 @@ +require_relative "shared_examples/invalid_option" + +describe Hbc::CLI::Upgrade, :cask do + it_behaves_like "a command that handles invalid options" + + context "successful upgrade" do + let(:installed) { + [ + "outdated/local-caffeine", + "outdated/local-transmission", + "outdated/auto-updates", + ] + } + + before(:example) do + installed.each { |cask| Hbc::CLI::Install.run(cask) } + + allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) + end + + describe 'without --greedy it ignores the Casks with "version latest" or "auto_updates true"' do + it "updates all the installed Casks when no token is provided" do + local_caffeine = Hbc::CaskLoader.load("local-caffeine") + local_caffeine_path = Hbc.appdir.join("Caffeine.app") + local_transmission = Hbc::CaskLoader.load("local-transmission") + local_transmission_path = Hbc.appdir.join("Transmission.app") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.2") + + expect(local_transmission).to be_installed + expect(local_transmission_path).to be_a_directory + expect(local_transmission.versions).to include("2.60") + + described_class.run + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.3") + + expect(local_transmission).to be_installed + expect(local_transmission_path).to be_a_directory + expect(local_transmission.versions).to include("2.61") + end + + it "updates only the Casks specified in the command line" do + local_caffeine = Hbc::CaskLoader.load("local-caffeine") + local_caffeine_path = Hbc.appdir.join("Caffeine.app") + local_transmission = Hbc::CaskLoader.load("local-transmission") + local_transmission_path = Hbc.appdir.join("Transmission.app") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.2") + + expect(local_transmission).to be_installed + expect(local_transmission_path).to be_a_directory + expect(local_transmission.versions).to include("2.60") + + described_class.run("local-caffeine") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.3") + + expect(local_transmission).to be_installed + expect(local_transmission_path).to be_a_directory + expect(local_transmission.versions).to include("2.60") + end + + it 'updates "auto_updates" and "latest" Casks when their tokens are provided in the command line' do + local_caffeine = Hbc::CaskLoader.load("local-caffeine") + local_caffeine_path = Hbc.appdir.join("Caffeine.app") + auto_updates = Hbc::CaskLoader.load("auto-updates") + auto_updates_path = Hbc.appdir.join("MyFancyApp.app") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.2") + + expect(auto_updates).to be_installed + expect(auto_updates_path).to be_a_directory + expect(auto_updates.versions).to include("2.57") + + described_class.run("local-caffeine", "auto-updates") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.3") + + expect(auto_updates).to be_installed + expect(auto_updates_path).to be_a_directory + expect(auto_updates.versions).to include("2.61") + end + end + + describe "with --greedy it checks additional Casks" do + it 'includes the Casks with "auto_updates true" or "version latest"' do + local_caffeine = Hbc::CaskLoader.load("local-caffeine") + local_caffeine_path = Hbc.appdir.join("Caffeine.app") + auto_updates = Hbc::CaskLoader.load("auto-updates") + auto_updates_path = Hbc.appdir.join("MyFancyApp.app") + local_transmission = Hbc::CaskLoader.load("local-transmission") + local_transmission_path = Hbc.appdir.join("Transmission.app") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.2") + + expect(auto_updates).to be_installed + expect(auto_updates_path).to be_a_directory + expect(auto_updates.versions).to include("2.57") + + expect(local_transmission).to be_installed + expect(local_transmission_path).to be_a_directory + expect(local_transmission.versions).to include("2.60") + + described_class.run("--greedy") + + expect(local_caffeine).to be_installed + expect(local_caffeine_path).to be_a_directory + expect(local_caffeine.versions).to include("1.2.3") + + expect(auto_updates).to be_installed + expect(auto_updates_path).to be_a_directory + expect(auto_updates.versions).to include("2.61") + + expect(local_transmission).to be_installed + expect(local_transmission_path).to be_a_directory + expect(local_transmission.versions).to include("2.61") + end + + it 'does not include the Casks with "auto_updates true" when the version did not change' do + cask = Hbc::CaskLoader.load("auto-updates") + cask_path = Hbc.appdir.join("MyFancyApp.app") + + expect(cask).to be_installed + expect(cask_path).to be_a_directory + expect(cask.versions).to include("2.57") + + described_class.run("auto-updates", "--greedy") + + expect(cask).to be_installed + expect(cask_path).to be_a_directory + expect(cask.versions).to include("2.61") + + described_class.run("auto-updates", "--greedy") + + expect(cask).to be_installed + expect(cask_path).to be_a_directory + expect(cask.versions).to include("2.61") + end + end + end + + context "failed upgrade" do + let(:installed) { + [ + "outdated/bad-checksum", + "outdated/will-fail-if-upgraded", + ] + } + + before(:example) do + installed.each { |cask| Hbc::CLI::Install.run(cask) } + + allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) + end + + output_reverted = Regexp.new <<~EOS + Warning: Reverting upgrade for Cask .* + EOS + + it "restores the old Cask if the upgrade failed" do + will_fail_if_upgraded = Hbc::CaskLoader.load("will-fail-if-upgraded") + will_fail_if_upgraded_path = Hbc.appdir.join("container") + + expect(will_fail_if_upgraded).to be_installed + expect(will_fail_if_upgraded_path).to be_a_file + expect(will_fail_if_upgraded.versions).to include("1.2.2") + + expect { + described_class.run("will-fail-if-upgraded") + }.to raise_error(Hbc::CaskError).and output(output_reverted).to_stderr + + expect(will_fail_if_upgraded).to be_installed + expect(will_fail_if_upgraded_path).to be_a_file + expect(will_fail_if_upgraded.versions).to include("1.2.2") + expect(will_fail_if_upgraded.staged_path).to_not exist + end + + it "does not restore the old Cask if the upgrade failed pre-install" do + bad_checksum = Hbc::CaskLoader.load("bad-checksum") + bad_checksum_path = Hbc.appdir.join("Caffeine.app") + + expect(bad_checksum).to be_installed + expect(bad_checksum_path).to be_a_directory + expect(bad_checksum.versions).to include("1.2.2") + + expect { + described_class.run("bad-checksum") + }.to raise_error(Hbc::CaskSha256MismatchError).and(not_to_output(output_reverted).to_stderr) + + expect(bad_checksum).to be_installed + expect(bad_checksum_path).to be_a_directory + expect(bad_checksum.versions).to include("1.2.2") + expect(bad_checksum.staged_path).to_not exist + end + end +end |
