Skip to content

Instantly share code, notes, and snippets.

@tedpennings
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedpennings/9148810 to your computer and use it in GitHub Desktop.
Save tedpennings/9148810 to your computer and use it in GitHub Desktop.
Find Homebrew Formulas that are missing tests!
#! /usr/bin/env ruby
# Find Homebrew formulas that are missing tests!
# Usage: run from checked out Homebrew repository root
# $ git clone git@github.com:Homebrew/homebrew.git && cd homebrew
# $ curl https://gist.githubusercontent.com/tedpennings/9148810/raw/ > missing_tests.rb
# $ chmod +x missing_tests.rb
# $ ./missing_tests.rb
min_commits = 25
def lacks_test?(path_to_formula)
File.readable?(path_to_formula) && !file_contains_test?(File.read(path_to_formula))
end
def file_contains_test?(contents)
contents.include?('def test') || contents.include?('test do')
end
def formulas_with_commits
results = {}
cmd = `git rev-list --objects --all | awk '$2' | sort -k2 | uniq -cf1 | sort -rn | grep Library/Formula/`
cmd.split("\n").map(&:strip).each do |line|
s = line.split(' ')
formula, commits = s.last, s.first.to_i
results[formula]= commits
end
results
end
formulas_with_commits.each_pair do |formula, commits|
break if commits < min_commits
puts "#{formula} with #{commits} lacks tests!" if lacks_test?(formula)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment