Initial small fixes

- Skip blank lines in watchlist
- Initialize Livecheck#version as nil
- Simplify livecheck_version logic
- Make test a bit more understandable
This commit is contained in:
Seeker 2020-09-03 20:09:56 -07:00 committed by Sam Ford
parent bf03893227
commit 4b87da4da9
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
4 changed files with 13 additions and 15 deletions

View File

@ -67,7 +67,9 @@ module Homebrew
args.named.to_formulae_and_casks
elsif File.exist?(WATCHLIST_PATH)
begin
names = Pathname.new(WATCHLIST_PATH).read.lines.reject { |line| line.start_with?("#") }.map(&:strip)
names = Pathname.new(WATCHLIST_PATH).read.lines
.reject { |line| line.start_with?("#") || line.blank? }
.map(&:strip)
CLI::NamedArgs.new(*names).to_formulae_and_casks
rescue Errno::ENOENT => e
onoe e

View File

@ -20,6 +20,7 @@ class Livecheck
@skip_msg = nil
@strategy = nil
@url = nil
@version = nil
end
# Sets the `@regex` instance variable to the provided `Regexp` or returns the
@ -88,10 +89,10 @@ class Livecheck
@url = case val
when nil
return @url
when :cask_url
@formula_or_cask.url.to_s
when :appcast
@formula_or_cask.appcast.to_s
when :cask_url
@formula_or_cask.url.to_s
when :head, :stable
@formula_or_cask.send(val).url
when :homepage

View File

@ -115,9 +115,11 @@ module Homebrew
# comparison.
livecheck_version = formula_or_cask.livecheck.version
current = if livecheck_version.is_a?(String)
livecheck_version
else
version = if formula
Version.new(livecheck_version)
elsif livecheck_version.is_a?(Array)
separator, method = livecheck_version
Version.new(formula_or_cask.version.to_s.split(separator, 2).try(method))
elsif formula
if formula.head_only?
formula.any_installed_version.version.commit
else
@ -125,13 +127,6 @@ module Homebrew
end
else
Version.new(formula_or_cask.version)
end
if livecheck_version.is_a?(Array)
separator, method = livecheck_version
Version.new(version.to_s.split(separator, 2).try(method))
else
version
end
end
latest = if formula&.stable? || cask

View File

@ -113,8 +113,8 @@ describe Livecheck do
end
it "returns value if set" do
livecheckable.version("foo")
expect(livecheckable.version).to eq("foo")
livecheckable.version("1.2.3")
expect(livecheckable.version).to eq("1.2.3")
livecheckable.version(:before_comma)
expect(livecheckable.version).to eq([",", :first])