-
Notifications
You must be signed in to change notification settings - Fork 73
/
ruby_simplecov_diff.rb
51 lines (44 loc) · 1.26 KB
/
ruby_simplecov_diff.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
#
# Given two Ruby simplecov output directories, show the differences
#
require 'json'
if ARGV.length != 2
STDERR.puts "USAGE: ruby ruby_simplecov_diff.rb /path/to/old/dir /path/to/new/dir"
exit 1
end
old_path = ARGV[0]
new_path = ARGV[1]
old_json = JSON.parse(File.read(File.join(old_path, '.resultset.json')))
new_json = JSON.parse(File.read(File.join(new_path, '.resultset.json')))
old_cov = old_json['RSpec']['coverage']
new_cov = new_json['RSpec']['coverage']
def get_line_percent(linearr)
not_covered = 0
linearr.each do |val|
next if val.nil?
not_covered += 1 if val < 1
end
return (((linearr.length - not_covered) * 1.0) / (linearr.length * 1.0)) * 100.0
end
def show_line_differences(old_linearr, new_linearr)
old_pct = get_line_percent(old_linearr)
new_pct = get_line_percent(new_linearr)
if old_pct == new_pct
return "coverage stayed the same"
elsif old_pct < new_pct
c = new_pct - old_pct
return "coverage increased by #{c}%"
else
c = old_pct - new_pct
return "coverage DECREASED by #{c}%"
end
end
old_cov.each do |fpath, linearr|
if ! new_cov.include?(fpath)
puts "#{fpath} - missing in new"
next
end
r = show_line_differences(linearr, new_cov[fpath])
puts "#{fpath} - #{r}"
end