Skip to content
Snippets Groups Projects
Commit 8575034f authored by Jack Nagel's avatar Jack Nagel
Browse files

Unroll validation loop

parent 1bdeeefb
No related branches found
No related tags found
No related merge requests found
......@@ -93,7 +93,7 @@ class Formula
set_spec :head
@active_spec = determine_active_spec(spec)
validate_attributes :url, :name, :version
validate_attributes!
@pkg_version = PkgVersion.new(version, revision)
@build = active_spec.build
@pin = FormulaPin.new(self)
......@@ -114,11 +114,18 @@ class Formula
spec or raise FormulaSpecificationError, "formulae require at least a URL"
end
def validate_attributes(*attrs)
attrs.each do |attr|
if (value = send(attr).to_s).empty? || value =~ /\s/
raise FormulaValidationError.new(attr, value)
end
def validate_attributes!
if name.nil? || name.empty? || name =~ /\s/
raise FormulaValidationError.new(:name, name)
end
if url.nil? || url.empty? || url =~ /\s/
raise FormulaValidationError.new(:url, url)
end
val = version.respond_to?(:to_str) ? version.to_str : version
if val.nil? || val.empty? || val =~ /\s/
raise FormulaValidationError.new(:version, val)
end
end
......
......@@ -44,6 +44,13 @@ class FormulaValidationTests < Homebrew::TestCase
version ""
end
end
assert_invalid :version do
formula do
url "foo"
version nil
end
end
end
def test_devel_only_valid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment