rename Cask::outdated_versions

This commit is contained in:
hyuraku 2023-06-19 22:09:01 +09:00
parent e986264a3e
commit de7152b7a3
2 changed files with 31 additions and 32 deletions

View File

@ -210,43 +210,42 @@ module Cask
end end
def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false) def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false)
!outdated_versions(greedy: greedy, greedy_latest: greedy_latest, !outdated_version(greedy: greedy, greedy_latest: greedy_latest,
greedy_auto_updates: greedy_auto_updates).empty? greedy_auto_updates: greedy_auto_updates).nil?
end end
# TODO: Rename to `outdated_version` and only return one version. def outdated_version(greedy: false, greedy_latest: false, greedy_auto_updates: false)
def outdated_versions(greedy: false, greedy_latest: false, greedy_auto_updates: false)
# special case: tap version is not available # special case: tap version is not available
return [] if version.nil? return if version.nil?
if version.latest? if version.latest?
return [installed_version] if (greedy || greedy_latest) && outdated_download_sha? return installed_version if (greedy || greedy_latest) && outdated_download_sha?
return [] return
elsif auto_updates && !greedy && !greedy_auto_updates elsif auto_updates && !greedy && !greedy_auto_updates
return [] return
end end
# not outdated unless there is a different version on tap # not outdated unless there is a different version on tap
return [] if installed_version == version return if installed_version == version
[installed_version] installed_version
end end
def outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates) def outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates)
return token if !verbose && !json return token if !verbose && !json
installed_versions = outdated_versions(greedy: greedy, greedy_latest: greedy_latest, installed_version = outdated_version(greedy: greedy, greedy_latest: greedy_latest,
greedy_auto_updates: greedy_auto_updates).join(", ") greedy_auto_updates: greedy_auto_updates).to_s
if json if json
{ {
name: token, name: token,
installed_versions: installed_versions, installed_versions: [installed_version],
current_version: version, current_version: version,
} }
else else
"#{token} (#{installed_versions}) != #{version}" "#{token} (#{installed_version}) != #{version}"
end end
end end

View File

@ -89,17 +89,17 @@ describe Cask::Cask, :cask do
it "ignores the Casks that have auto_updates true (without --greedy)" do it "ignores the Casks that have auto_updates true (without --greedy)" do
c = Cask::CaskLoader.load("auto-updates") c = Cask::CaskLoader.load("auto-updates")
expect(c).not_to be_outdated expect(c).not_to be_outdated
expect(c.outdated_versions).to be_empty expect(c.outdated_version).to be_nil
end end
it "ignores the Casks that have version :latest (without --greedy)" do it "ignores the Casks that have version :latest (without --greedy)" do
c = Cask::CaskLoader.load("version-latest-string") c = Cask::CaskLoader.load("version-latest-string")
expect(c).not_to be_outdated expect(c).not_to be_outdated
expect(c.outdated_versions).to be_empty expect(c.outdated_version).to be_nil
end end
describe "versioned casks" do describe "versioned casks" do
subject { cask.outdated_versions } subject { cask.outdated_version }
let(:cask) { described_class.new("basic-cask") } let(:cask) { described_class.new("basic-cask") }
@ -109,7 +109,7 @@ describe Cask::Cask, :cask do
it { it {
allow(cask).to receive(:installed_version).and_return(installed_version) allow(cask).to receive(:installed_version).and_return(installed_version)
allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version)) allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version))
expect(cask).to receive(:outdated_versions).and_call_original expect(cask).to receive(:outdated_version).and_call_original
expect(subject).to eq expected_output expect(subject).to eq expected_output
} }
end end
@ -118,13 +118,13 @@ describe Cask::Cask, :cask do
describe "installed version is equal to tap version => not outdated" do describe "installed version is equal to tap version => not outdated" do
include_examples "versioned casks", "1.2.3", include_examples "versioned casks", "1.2.3",
"1.2.3" => [] "1.2.3" => nil
end end
describe "installed version is different than tap version => outdated" do describe "installed version is different than tap version => outdated" do
include_examples "versioned casks", "1.2.4", include_examples "versioned casks", "1.2.4",
"1.2.3" => ["1.2.3"], "1.2.3" => "1.2.3",
"1.2.4" => [] "1.2.4" => nil
end end
end end
@ -136,13 +136,13 @@ describe Cask::Cask, :cask do
context "when versions #{installed_version} are installed and the " \ context "when versions #{installed_version} are installed and the " \
"tap version is #{tap_version}, #{"not " unless greedy}greedy " \ "tap version is #{tap_version}, #{"not " unless greedy}greedy " \
"and sha is #{"not " unless outdated_sha}outdated" do "and sha is #{"not " unless outdated_sha}outdated" do
subject { cask.outdated_versions(greedy: greedy) } subject { cask.outdated_version(greedy: greedy) }
it { it {
allow(cask).to receive(:installed_version).and_return(installed_version) allow(cask).to receive(:installed_version).and_return(installed_version)
allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version)) allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version))
allow(cask).to receive(:outdated_download_sha?).and_return(outdated_sha) allow(cask).to receive(:outdated_download_sha?).and_return(outdated_sha)
expect(cask).to receive(:outdated_versions).and_call_original expect(cask).to receive(:outdated_version).and_call_original
expect(subject).to eq expected_output expect(subject).to eq expected_output
} }
end end
@ -151,29 +151,29 @@ describe Cask::Cask, :cask do
describe ":latest version installed, :latest version in tap" do describe ":latest version installed, :latest version in tap" do
include_examples ":latest cask", false, false, "latest", include_examples ":latest cask", false, false, "latest",
"latest" => [] "latest" => nil
include_examples ":latest cask", true, false, "latest", include_examples ":latest cask", true, false, "latest",
"latest" => [] "latest" => nil
include_examples ":latest cask", true, true, "latest", include_examples ":latest cask", true, true, "latest",
"latest" => ["latest"] "latest" => "latest"
end end
describe "numbered version installed, :latest version in tap" do describe "numbered version installed, :latest version in tap" do
include_examples ":latest cask", false, false, "latest", include_examples ":latest cask", false, false, "latest",
"1.2.3" => [] "1.2.3" => nil
include_examples ":latest cask", true, false, "latest", include_examples ":latest cask", true, false, "latest",
"1.2.3" => [] "1.2.3" => nil
include_examples ":latest cask", true, true, "latest", include_examples ":latest cask", true, true, "latest",
"1.2.3" => ["1.2.3"] "1.2.3" => "1.2.3"
end end
describe "latest version installed, numbered version in tap" do describe "latest version installed, numbered version in tap" do
include_examples ":latest cask", false, false, "1.2.3", include_examples ":latest cask", false, false, "1.2.3",
"latest" => ["latest"] "latest" => "latest"
include_examples ":latest cask", true, false, "1.2.3", include_examples ":latest cask", true, false, "1.2.3",
"latest" => ["latest"] "latest" => "latest"
include_examples ":latest cask", true, true, "1.2.3", include_examples ":latest cask", true, true, "1.2.3",
"latest" => ["latest"] "latest" => "latest"
end end
end end
end end