Skip to content

Commit

Permalink
brew audit - refactor text checks to make easier to test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamv committed Aug 9, 2010
1 parent fc4f545 commit 65b3f4b
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions Library/Contributions/examples/brew-audit.rb
Expand Up @@ -6,12 +6,9 @@ def ff
return ARGV.formulae
end

ff.each do |f|
text = ""
def audit_formula_text text
problems = []

File.open(f.path, "r") { |afile| text = afile.read }

# Commented-out cmake support from default template
if text =~ /# depends_on 'cmake'/
problems << " * Commented cmake support found."
Expand Down Expand Up @@ -42,8 +39,8 @@ def ff
problems << " * \"#{$1}\" should be \"\#{#{$2}}\""
end

if text =~ %r[(\#\{prefix\}/share/man/(man[1-8]))]
problems << " * \"#{$1}\" should be \"\#{#{$2}}\""
if text =~ %r[((\#\{prefix\}/share/man/|\#\{man\}/)(man[1-8]))]
problems << " * \"#{$1}\" should be \"\#{#{$3}}\""
end

if text =~ %r[(\#\{prefix\}/share/(info|man))]
Expand All @@ -66,15 +63,30 @@ def ff
problems << " * Trailing whitespace was found."
end

# Don't depend_on aliases; use full name
aliases = Formula.aliases
f.deps.select {|d| aliases.include? d}.each do |d|
problems << " * Dep #{d} is an alias; switch to the real name."
end
return problems
end

def audit_some_formulae
ff.each do |f|
problems = []

unless problems.empty?
puts "#{f.name}:"
puts problems * "\n"
puts
# Don't depend_on aliases; use full name
aliases = Formula.aliases
f.deps.select {|d| aliases.include? d}.each do |d|
problems << " * Dep #{d} is an alias; switch to the real name."
end

text = ""
File.open(f.path, "r") { |afile| text = afile.read }

problems += audit_formula_text(text)

unless problems.empty?
puts "#{f.name}:"
puts problems * "\n"
puts
end
end
end

audit_some_formulae

0 comments on commit 65b3f4b

Please sign in to comment.