diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula.rb | 18 | ||||
| -rwxr-xr-x | Library/Homebrew/unittest.rb | 6 |
2 files changed, 16 insertions, 8 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index ff4516777..5eeadddf0 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -32,14 +32,14 @@ end # Derive and define at least @url, see Library/Formula for examples class Formula # Homebrew determines the name - def initialize name=nil + def initialize name='__UNKNOWN__' @url=self.class.url unless @url raise if @url.nil? @name=name - raise if @name =~ /\s/ + validate_variable :name @version=self.class.version unless @version @version=Pathname.new(@url).version unless @version - raise if @version =~ /\s/ + validate_variable :version if @version @homepage=self.class.homepage unless @homepage @md5=self.class.md5 unless @md5 @sha1=self.class.sha1 unless @sha1 @@ -53,8 +53,8 @@ class Formula end def prefix - raise "Invalid @name" if @name.nil? or @name.empty? - raise "Invalid @version" if @version.nil? or @version.empty? + validate_variable :name + validate_variable :version HOMEBREW_CELLAR+@name+@version end @@ -100,6 +100,9 @@ class Formula # yields self with current working directory set to the uncompressed tarball def brew + validate_variable :name + validate_variable :version + stage do begin patch @@ -238,6 +241,11 @@ private end end + def validate_variable name + v=eval("@#{name}") + raise "Invalid @#{name}" if v.nil? or v.empty? or v =~ /\s/ + end + def method_added method raise 'You cannot override Formula.brew' if method == 'brew' end diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb index 3bc0b6f61..c4d2a118d 100755 --- a/Library/Homebrew/unittest.rb +++ b/Library/Homebrew/unittest.rb @@ -281,10 +281,10 @@ class BeerTasting <Test::Unit::TestCase end def test_abstract_formula - f=MostlyAbstractFormula.new '' - assert_equal '', f.name + f=MostlyAbstractFormula.new + assert_equal '__UNKNOWN__', f.name assert_raises(RuntimeError) { f.prefix } - nostdout { assert_raises(ExecutionError) { f.brew } } + nostdout { assert_raises(RuntimeError) { f.brew } } end def test_zip |
