Last active
August 29, 2015 13:56
-
-
Save tedpennings/9148810 to your computer and use it in GitHub Desktop.
Find Homebrew Formulas that are missing tests!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# Find Homebrew formulas that are missing tests! | |
# Usage: run from checked out Homebrew repository root | |
# $ git clone [email protected]: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