Add Version#detected_from_url?

This commit is contained in:
Jack Nagel 2012-07-10 16:10:16 -05:00
parent 329f0a8490
commit e57122780e
4 changed files with 15 additions and 16 deletions

View File

@ -217,8 +217,8 @@ class FormulaAuditor
if s.version.to_s.empty? if s.version.to_s.empty?
problem "Invalid or missing #{spec} version" problem "Invalid or missing #{spec} version"
else else
version_text = s.version if s.explicit_version? version_text = s.version unless s.version.detected_from_url?
version_url = Pathname.new(s.url).version version_url = Version.parse(s.url)
if version_url == version_text if version_url == version_text
problem "#{spec} version #{version_text} is redundant with version scanned from URL" problem "#{spec} version #{version_text} is redundant with version scanned from URL"
end end

View File

@ -11,11 +11,6 @@ class SoftwareSpec
@mirrors = [] @mirrors = []
end end
# Was the version defined in the DSL, or detected from the URL?
def explicit_version?
@explicit_version || false
end
def download_strategy def download_strategy
@download_strategy ||= DownloadStrategyDetector.new(@url, @using).detect @download_strategy ||= DownloadStrategyDetector.new(@url, @using).detect
end end
@ -63,7 +58,6 @@ class SoftwareSpec
@version ||= Version.parse(@url) @version ||= Version.parse(@url)
else else
@version = Version.new(val) @version = Version.new(val)
@explicit_version = true
end end
end end

View File

@ -122,9 +122,9 @@ class FormulaTests < Test::Unit::TestCase
assert_equal 1, f.devel.mirrors.length assert_equal 1, f.devel.mirrors.length
assert f.head.mirrors.empty? assert f.head.mirrors.empty?
assert !f.stable.explicit_version? assert f.stable.version.detected_from_url?
assert !f.bottle.explicit_version? assert f.bottle.version.detected_from_url?
assert !f.devel.explicit_version? assert f.devel.version.detected_from_url?
assert_version_equal '0.1', f.stable.version assert_version_equal '0.1', f.stable.version
assert_version_equal '0.1', f.bottle.version assert_version_equal '0.1', f.bottle.version
assert_version_equal '0.2', f.devel.version assert_version_equal '0.2', f.devel.version
@ -159,8 +159,8 @@ class FormulaTests < Test::Unit::TestCase
assert_version_equal '0.3', f.version assert_version_equal '0.3', f.version
assert_version_equal '0.3', f.stable.version assert_version_equal '0.3', f.stable.version
assert_version_equal '0.4', f.devel.version assert_version_equal '0.4', f.devel.version
assert f.stable.explicit_version? assert !f.stable.version.detected_from_url?
assert f.devel.explicit_version? assert !f.devel.version.detected_from_url?
end end
def test_old_bottle_specs def test_old_bottle_specs
@ -182,7 +182,7 @@ class FormulaTests < Test::Unit::TestCase
assert_nil f.bottle.md5 assert_nil f.bottle.md5
assert_nil f.bottle.sha256 assert_nil f.bottle.sha256
assert !f.bottle.explicit_version? assert f.bottle.version.detected_from_url?
assert_equal 0, f.bottle.revision assert_equal 0, f.bottle.revision
assert_version_equal '0.1', f.bottle.version assert_version_equal '0.1', f.bottle.version
else else

View File

@ -1,9 +1,14 @@
class Version class Version
include Comparable include Comparable
def initialize val def initialize val, detected=false
return val if val.is_a? Version or val.nil? return val if val.is_a? Version or val.nil?
@version = val.to_s @version = val.to_s
@detected_from_url = detected
end
def detected_from_url?
@detected_from_url
end end
def head? def head?
@ -39,7 +44,7 @@ class Version
def self.parse spec def self.parse spec
version = _parse(spec) version = _parse(spec)
Version.new(version) unless version.nil? Version.new(version, true) unless version.nil?
end end
private private