Skip to content

Instantly share code, notes, and snippets.

@vdinovi
Last active March 26, 2020 16:46
Show Gist options
  • Select an option

  • Save vdinovi/22c5955c64076ea27918b611d595fa88 to your computer and use it in GitHub Desktop.

Select an option

Save vdinovi/22c5955c64076ea27918b611d595fa88 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'terminal-table'
FORMAT = /([\w\:]+)\#(test_[\w]*)[\s\:]*(.*)\s*=\s*(\d+\.\d+)\s*.*=\s*(.*)\s*/
IGNORE = [
/\{\"message\".*\n?\}/,
/Run\soptions\:/,
/\#\sRunning\:/,
/\*\sDEFERRED/,
/^\s*$/
].freeze
RESULTS = {
'.' => :success,
'F' => :failure,
'E' => :error
}.freeze
def parse_float(string)
Float(string)
rescue ArgumentError
end
def parse(content, regex)
distribution = {}
content.split("\n").map do |line|
next if regex && !line.match(regex)
next if IGNORE.any? { |ignore| line.match(ignore) }
if !(capture = line.match(FORMAT))
puts "failed to capture line: #{line}"
elsif !(name = capture[1])
puts "failed parse name from line: #{line}"
elsif !(test = capture[3] || capture[2])
puts "failed parse name from line: #{line}"
elsif !(timing = parse_float(capture[4]))
puts "failed to parse timing from line: #{line}"
elsif !(result = RESULTS[capture[5]])
puts "failed to parse result from line: #{line}"
else
key = regex ? test[0..40] : name
distribution[key] ||= { count: 0, timing: 0.0, success: 0, failure: 0, error: 0 }
distribution[key][:count] += 1
distribution[key][result] += 1
distribution[key][:timing] += timing
end
end
distribution
end
path = File.expand_path(ARGV[0])
content = File.read(path).gsub(/\{\"message\".*\}?\n/, '')
distribution = parse(content, (Regexp.new(ARGV[1]) if ARGV[1]))
sorted = distribution
.map { |key, value| [key, value] }
.sort_by { |_key, value| -value[:timing] }
table = Terminal::Table.new do |t|
t << ['Test', 'Timing', 'Count', 'Success', 'Failure', 'Error', 'Avg Test Timing']
t << :separator
sorted.each do |key, value|
t << [
key,
value[:timing].round(4),
value[:count],
value[:success],
value[:failure],
value[:error],
(value[:timing] / value[:count].to_f).round(4)
]
end
end
puts table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment