Skip to content

Commit b229e9d

Browse files
committed
Improve bin/compare
* Handle unreadable files (some uploaded gems have wrong permissions) * Add warnings to things that get compared. They are part of the dumped content
1 parent 27edbaf commit b229e9d

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

bin/compare

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ def create_prism(ref)
2626
when "dump"
2727
begin
2828
child_socket.puts(Prism.dump_file(path).hash)
29-
rescue Errno::EISDIR
29+
rescue Errno::EISDIR, Errno::EACCES
3030
# Folder might end with `.rb` and get caught by the glob
31+
# Some gems may contain files that are not readable by the current user
3132
child_socket.puts("")
3233
end
3334
when "details"
3435
parse_result = Prism.parse_file(path)
3536
child_socket.puts({
3637
valid: parse_result.success?,
37-
errors: parse_result.errors_format.hash,
38+
errors: parse_result.errors.map(&:inspect).hash,
39+
warnings: parse_result.warnings.map(&:inspect).hash,
3840
ast: parse_result.value.inspect.hash,
3941
}.to_json)
4042
else
@@ -64,14 +66,15 @@ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
6466

6567
def what_changed(baseline, compare, source_path)
6668
if baseline[:valid] != compare[:valid]
67-
"#{source_path} changed from valid(#{baseline[:valid]}) to valid(#{compare[:valid]})"
68-
elsif baseline[:valid] && compare[:valid] && baseline[:ast] != compare[:ast]
69-
"#{source_path} is syntax valid with changed ast}"
70-
elsif !baseline[:valid] && !compare[:valid] && baseline[:errors] != compare[:errors]
71-
"#{source_path} is syntax invalid with changed errors"
72-
else
73-
raise "Unknown condition for #{source_path}"
69+
return "#{source_path} changed from valid(#{baseline[:valid]}) to valid(#{compare[:valid]})"
7470
end
71+
72+
changed = []
73+
%i[ast errors warnings].each do |type|
74+
changed << type if baseline[type] != compare[type]
75+
end
76+
raise "Unknown changes for #{source_path}" if changed.empty?
77+
"#{source_path} is valid(#{baseline[:valid]}) with changed #{changed.join(", ")}"
7578
end
7679

7780
files.each_with_index do |source_path, i|

0 commit comments

Comments
 (0)