aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorAdam Vandenberg2012-03-17 19:49:49 -0700
committerAdam Vandenberg2012-03-19 18:50:17 -0700
commit9c28138889055f8a3af5e32bab4059b6a9a8a87f (patch)
tree92ff3a844d635d024ac2fdff8260b098954d79d5 /Library/Homebrew
parent7c5002082273d57f8f4a386aee5da2383283974a (diff)
downloadbrew-9c28138889055f8a3af5e32bab4059b6a9a8a87f.tar.bz2
audit: add tests for patches
Diffstat (limited to 'Library/Homebrew')
-rwxr-xr-xLibrary/Homebrew/cmd/audit.rb49
1 files changed, 42 insertions, 7 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index 9bffe7db4..8c604ba56 100755
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -1,5 +1,17 @@
require 'formula'
require 'utils'
+require 'extend/ENV'
+
+# Some formulae use ENV in patches, so set up an environment
+ENV.extend(HomebrewEnvExtension)
+ENV.setup_build_environment
+
+class Module
+ def redefine_const(name, value)
+ __send__(:remove_const, name) if const_defined?(name)
+ const_set(name, value)
+ end
+end
def ff
return Formula.all if ARGV.named.empty?
@@ -194,6 +206,19 @@ def audit_formula_version f, text
return []
end
+def audit_formula_patches f
+ problems = []
+ patches = Patches.new(f.patches)
+ patches.each do |p|
+ next unless p.external?
+ if p.url =~ %r[raw\.github\.com]
+ problems << " * Using raw GitHub URLs is not recommended:"
+ problems << " * #{p.url}"
+ end
+ end
+ return problems
+end
+
def audit_formula_urls f
problems = []
@@ -330,6 +355,17 @@ EOS
return problems
end
+# Formula extensions for auditing
+class Formula
+ def head_only?
+ @unstable and @standard.nil?
+ end
+
+ def formula_text
+ File.open(@path, "r") { |afile| return afile.read }
+ end
+end
+
module Homebrew extend self
def audit
errors = false
@@ -338,22 +374,21 @@ module Homebrew extend self
problem_count = 0
ff.each do |f|
- problems = []
-
- if f.unstable and f.standard.nil?
- problems += [' * head-only formula']
- end
+ # We need to do this in case the formula defines a patch that uses DATA.
+ f.class.redefine_const :DATA, ""
+ problems = []
+ problems += [' * head-only formula'] if f.head_only?
problems += audit_formula_instance f
problems += audit_formula_urls f
+ problems += audit_formula_patches f
perms = File.stat(f.path).mode
if perms.to_s(8) != "100644"
problems << " * permissions wrong; chmod 644 #{f.path}"
end
- text = ""
- File.open(f.path, "r") { |afile| text = afile.read }
+ text = f.formula_text
# DATA with no __END__
if (text =~ /\bDATA\b/) and not (text =~ /^\s*__END__\s*$/)