Skip to content

Commit

Permalink
audit: add tests for patches
Browse files Browse the repository at this point in the history
  • Loading branch information
adamv committed Mar 20, 2012
1 parent 7cafbf9 commit edc8d46
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions Library/Homebrew/cmd/audit.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -330,6 +355,17 @@ def audit_formula_instance f
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
Expand All @@ -338,22 +374,21 @@ def audit
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*$/)
Expand Down

0 comments on commit edc8d46

Please sign in to comment.