-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalyze_per_file.rb
More file actions
225 lines (202 loc) · 7.8 KB
/
Copy pathanalyze_per_file.rb
File metadata and controls
225 lines (202 loc) · 7.8 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
require 'yaml'
KINDS = [:examples, :errors, :failures, :tagged, :time]
DETAILS = ARGV.delete('--details')
USE_MRI_TOTALS = ARGV.delete('--mri-totals')
HTML = ARGV.delete('--html')
longest_group = "total_no_capi".size
processed = {}
ARGV.each { |results_file|
results_file =~ /^(\w+)\/(.+)\.yml$/ or raise results_file
ruby, group = $1, $2
data = YAML.load_file(results_file, symbolize_names: true)
processed[ruby] ||= {}
processed[ruby][group] = data
}
mri_summary = processed.find { |ruby,| ruby.start_with?('ruby') }[1]
# Fix up data
processed.each_pair do |ruby, summary|
mri_summary.each_pair do |group,|
unless summary.include?(group)
STDERR.puts "#{ruby} has no #{group} specs"
summary[group] = KINDS.map { |kind| [kind, 0] }.to_h
end
end
summary.each_pair do |group, totals|
if totals[:examples] == 0
STDERR.puts "Correcting examples for #{group} for #{ruby}"
totals[:examples] = mri_summary[group][:examples]
totals[:errors] = totals[:examples]
end
end
end
if USE_MRI_TOTALS
processed.each_pair do |ruby, summary|
summary.each_pair do |group, totals|
mri = mri_summary[group]
diff = mri[:examples] - totals[:examples]
if diff > 0
totals[:examples] += diff
totals[:errors] += diff
elsif diff < 0
STDERR.puts "More examples for #{group} on #{ruby}: #{totals[:examples]} vs #{mri[:examples]}"
# raise totals.inspect
end
end
end
end
examples_per_group = Hash.new { |h,k| h[k] = [] }
processed.each_pair do |ruby, summary|
summary.each_pair do |group, totals|
examples_per_group[group] << totals[:examples]
end
end
same_number_of_specs = examples_per_group.to_h { |group, examples| [group, examples.uniq.size == 1] }
# Compute totals
processed.each_pair do |ruby, summary|
summary["total"] = KINDS.map { |kind| [kind, summary.sum { |_, totals| totals[kind] }] }.to_h
summary_no_capi = summary.reject { |key, _| key == 'capi' or key == 'total' }.to_h
summary["total_no_capi"] = KINDS.map { |kind| [kind, summary_no_capi.sum { |_, totals| totals[kind] }] }.to_h
summary.each_value do |totals|
totals[:passing] = totals[:examples] - totals[:errors] - totals[:failures] - totals[:tagged]
end
end
if HTML
# https://medium.com/@pppped/how-to-code-a-responsive-circular-percentage-chart-with-svg-and-css-3632f8cd7705
circle = -> percents {
text = percents == 100.0 ? "100" : "%.1f" % percents
<<-SVG
<svg viewBox="0 0 36 36" class="circular-chart">
<path class="circle-bg"
d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"/>
<path class="circle"
stroke-dasharray="#{percents}, 100"
d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"/>
<text x="18" y="20.35" class="percentage">#{text}%</text>
</svg>
SVG
}
puts <<~HTML
<html>
<head>
<title>Passing Specs per Ruby Implementation</title>
<link rel="stylesheet" href="https://eregon.me/blog/assets/main.css?v=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Libre+Baskerville:400,400i,700">
<link rel="stylesheet" href="https://eregon.me/blog/assets/custom.css?v=1">
<link rel="stylesheet" href="https://eregon.me/blog/assets/syntax.css?v=1">
<link rel="stylesheet" href="https://eregon.me/blog/assets/table.css?v=1">
<link rel="stylesheet" href="https://eregon.me/blog/assets/circle.css?v=1">
</head>
<body><main><div class="post">
<h1 class="post-title">Passing Specs per Ruby Implementation</h1>
<p>
This page shows the number of passing <a href="https://github.com/ruby/spec">ruby/spec</a> specs per Ruby implementation.
This page is updated daily and automatically with GitHub Actions on <a href="https://github.com/eregon/rubyspec-stats">this repository</a>.
</p>
<p>
Specs excluded by a Ruby implementation (via tags) are not run, as those may cause a fatal error and abort the process, and also they are not run in that implementation's CI.
Specs are run on a Ruby implementation with no extra options, i.e., with the default behavior a user would see.
The only exception is using <code>--dev</code> on JRuby so it runs specs slightly faster.
More details are available in this related <a href="https://eregon.me/blog/2020/06/27/ruby-spec-compatibility-report.html">blog post</a>.
</p>
<p>
More Ruby implementations are welcome via PRs.
See <a href="https://github.com/eregon/rubyspec-stats/blob/master/.github/workflows/ci.yml">this workflow</a> for how it works.
</p>
<table style="width: 100%">
HTML
puts "<colgroup>"
group_width = 16
puts %Q{<col span="1" style="width: #{group_width}%;">}
processed.each_key do
puts %Q{<col span="1" style="width: #{((100 - group_width) / processed.size)}%">}
end
puts "</colgroup>"
puts "<thead>"
puts "<th>Group</th>"
processed.each_key do |ruby|
# ruby_name = ruby.sub(/-/, ' ').sub(/^ruby/, 'cruby').capitalize.sub('ruby', 'Ruby')
ruby_name = ruby.sub(/-/, ' ').sub(/^ruby/, 'cruby').split.first.capitalize.sub('ruby', 'Ruby')
if ruby_name == 'CRuby'
ruby_version_file = "#{ruby}/RUBY_VERSION"
major_minor = File.read(ruby_version_file)[/^\d+\.\d+/]
ruby_name = "CRuby #{major_minor}"
else
ruby_name = "#{ruby_name} dev"
end
puts %Q{<th style="text-align: center">#{ruby_name}</th>}
end
puts "</thead>"
groups = mri_summary.keys.sort_by { |group|
%w[command_line language core library security total_no_capi capi total].index(group) || raise(group)
}
puts "<tbody>"
puts '<tr>'
puts '<td>RUBY_VERSION</td>'
processed.each_key do |ruby|
ruby_version_file = "#{ruby}/RUBY_VERSION"
ruby_version = File.exist?(ruby_version_file) ? File.read(ruby_version_file) : '?'
puts %Q{<td style="text-align: center">#{ruby_version}</th>}
end
puts '</tr>'
groups.each do |group|
case group
when 'total'
group_name = '<b>TOTAL</b>'
when 'total_no_capi'
group_name = '<b>TOTAL without C-API specs</b>'
else
group_name = group.gsub('_', '-').capitalize
group_name = group_name.sub('Capi', 'C-API').sub('Library', 'Standard Library').sub('Core', 'Core Library')
link = group == 'capi' ? 'optional/capi' : group
group_name = %Q{<a href="https://github.com/ruby/spec/tree/master/#{link}">#{group_name}</a>}
# group_name += " specs"
end
puts group.start_with?('total') ? '<tr style="border-top: 2px solid black">' : '<tr>'
if same_number_of_specs[group]
puts "<td>#{group_name}<br/>\n#{mri_summary[group][:examples]} specs</td>"
else
puts "<td>#{group_name}</td>"
end
processed.each_pair do |ruby, summary|
totals = summary[group]
ratio = totals[:passing].to_f / totals[:examples]
puts '<td style="text-align: center">'
puts circle[ratio * 100]
if group.start_with?('total')
puts %Q{<span style="font-size: 95%">#{totals[:passing]} passing<br/>in #{totals[:time].to_i.divmod(60).join('min ')}s</span>}
else
unless same_number_of_specs[group]
puts %Q{<span style="font-size: 95%">of #{totals[:examples]} specs</span>}
end
end
puts "</td>"
end
puts "</tr>"
end
puts <<~HTML
</tbody>
</table>
</div></main>
<footer><span>© #{Time.now.year} Benoit Daloze.</span></footer>
</body>
HTML
else
processed.each_pair do |ruby, summary|
puts nil, ruby
if DETAILS
summary.each_pair do |group, totals|
puts "#{group.ljust(longest_group)} #{totals}"
end
puts
end
summary.each_pair do |group, totals|
f = "%5d"
ratio = totals[:passing].to_f / totals[:examples]
puts "#{group.ljust(longest_group)} #{f % totals[:passing]}/#{f % totals[:examples]} = #{"%6.2f" % (ratio * 100)}%"
end
end
end