Skip to content

Instantly share code, notes, and snippets.

@tehviking
Created September 15, 2015 15:40
Show Gist options
  • Save tehviking/ca7955506f01073dcba9 to your computer and use it in GitHub Desktop.
Save tehviking/ca7955506f01073dcba9 to your computer and use it in GitHub Desktop.
Find failures & errors and their count in test output
class Parser
attr_reader :files
def initialize
@read_file_mode = false
@files = {}
end
def feed(line)
if scan_mode? && scan_match(line)
@read_file_mode = true
elsif @read_file_mode
read_file_name line
end
end
def scan_mode?
!@read_file_mode
end
def scan_match(line)
line =~ /\d+\) (Error|Failure)/
end
def read_file_name(line)
if line =~ /\[*desktop\/(.*test.rb)/
@files[$1] ||= 0
@files[$1] += 1
@read_file_mode = false
end
end
end
File.open("functionals2.txt") do |file|
p = Parser.new
file.each_line do |line|
p.feed line
end
p.files.each {|k, v| puts "#{k}: #{v}"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment