Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Hbc | ||
class CLI | ||
class Outdated < Base | ||
def self.run(*args) | ||
greedy = args.include?("--greedy") | ||
verbose = ($stdout.tty? || CLI.verbose?) && !args.include?("--quiet") | ||
|
||
cask_tokens = cask_tokens_from(args) | ||
casks_to_check = if cask_tokens.empty? | ||
Hbc.installed | ||
else | ||
cask_tokens.map { |token| Hbc.load(token) } | ||
end | ||
|
||
casks_to_check.each do |cask| | ||
odebug "Checking update info of Cask #{cask}" | ||
list_if_outdated(cask, greedy, verbose) | ||
end | ||
end | ||
|
||
def self.list_if_outdated(cask, greedy, verbose) | ||
return unless cask.outdated?(greedy) | ||
|
||
if verbose | ||
outdated_versions = cask.outdated_versions(greedy) | ||
outdated_info = "#{cask.token} (#{outdated_versions.join(", ")})" | ||
current_version = cask.version.to_s | ||
puts "#{outdated_info} != #{current_version}" | ||
else | ||
puts cask.token | ||
end | ||
end | ||
|
||
def self.help | ||
"list the outdated installed Casks" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
describe Hbc::CLI::Outdated, :cask do | ||
let(:installed) do | ||
[ | ||
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb"), | ||
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-caffeine.rb"), | ||
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-transmission.rb"), | ||
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/version-latest-string.rb"), | ||
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/auto-updates.rb"), | ||
] | ||
end | ||
|
||
before do | ||
shutup do | ||
installed.each { |cask| InstallHelper.install_with_caskfile(cask) } | ||
end | ||
allow(Hbc::CLI).to receive(:verbose?).and_return(true) | ||
end | ||
|
||
describe 'without --greedy it ignores the Casks with "vesion latest" or "auto_updates true"' do | ||
it "checks all the installed Casks when no token is provided" do | ||
expect { | ||
Hbc::CLI::Outdated.run | ||
}.to output(<<-EOS.undent).to_stdout | ||
local-caffeine (1.2.2) != 1.2.3 | ||
local-transmission (2.60) != 2.61 | ||
EOS | ||
end | ||
|
||
it "checks only the tokens specified in the command line" do | ||
expect { | ||
Hbc::CLI::Outdated.run("local-caffeine") | ||
}.to output(<<-EOS.undent).to_stdout | ||
local-caffeine (1.2.2) != 1.2.3 | ||
EOS | ||
end | ||
|
||
it 'ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do | ||
expect { | ||
Hbc::CLI::Outdated.run("local-caffeine", "auto-updates", "version-latest-string") | ||
}.to output(<<-EOS.undent).to_stdout | ||
local-caffeine (1.2.2) != 1.2.3 | ||
EOS | ||
end | ||
end | ||
|
||
it "lists only the names (no versions) of the outdated Casks with --quiet" do | ||
expect { | ||
Hbc::CLI::Outdated.run("--quiet") | ||
}.to output(<<-EOS.undent).to_stdout | ||
local-caffeine | ||
local-transmission | ||
EOS | ||
end | ||
|
||
describe "with --greedy it checks additional Casks" do | ||
it 'includes the Casks with "auto_updates true" or "version latest" with --greedy' do | ||
expect { | ||
Hbc::CLI::Outdated.run("--greedy") | ||
}.to output(<<-EOS.undent).to_stdout | ||
auto-updates (2.57) != 2.61 | ||
local-caffeine (1.2.2) != 1.2.3 | ||
local-transmission (2.60) != 2.61 | ||
version-latest-string (latest) != latest | ||
EOS | ||
end | ||
|
||
it 'does not include the Casks with "auto_updates true" when the version did not change' do | ||
cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") | ||
InstallHelper.install_with_caskfile(cask) | ||
|
||
expect { | ||
Hbc::CLI::Outdated.run("--greedy") | ||
}.to output(<<-EOS.undent).to_stdout | ||
local-caffeine (1.2.2) != 1.2.3 | ||
local-transmission (2.60) != 2.61 | ||
version-latest-string (latest) != latest | ||
EOS | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
Library/Homebrew/test/support/fixtures/cask/Casks/outdated/auto-updates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cask 'auto-updates' do | ||
version '2.57' | ||
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68' | ||
|
||
url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg" | ||
homepage 'http://example.com/auto-updates' | ||
|
||
auto_updates true | ||
|
||
app 'Transmission.app' | ||
end |
9 changes: 9 additions & 0 deletions
9
Library/Homebrew/test/support/fixtures/cask/Casks/outdated/local-caffeine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cask 'local-caffeine' do | ||
version '1.2.2' | ||
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' | ||
|
||
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" | ||
homepage 'http://example.com/local-caffeine' | ||
|
||
app 'Caffeine.app' | ||
end |
9 changes: 9 additions & 0 deletions
9
Library/Homebrew/test/support/fixtures/cask/Casks/outdated/local-transmission.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cask 'local-transmission' do | ||
version '2.60' | ||
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68' | ||
|
||
url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg" | ||
homepage 'http://example.com/local-transmission' | ||
|
||
app 'Transmission.app' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters