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
|
# File 'lib/deep_cover/tools/dump_covered_code.rb', line 14
def dump_covered_code(source_path, coverage: raise, dest_path: Dir.mktmpdir, root_path: source_path)
source_path = File.join(File.expand_path(source_path), '')
dest_path = File.join(File.expand_path(dest_path), '')
root_path = Pathname.new(root_path)
skipped = []
file_paths = Dir.glob("#{source_path}**/*.rb").select { |p| File.file?(p) }
file_paths.each.with_progress(title: 'Rewriting') do |path|
new_path = Pathname(path.gsub(source_path, dest_path))
begin
covered_code = coverage.covered_code(path, name: new_path.relative_path_from(root_path))
rescue Parser::SyntaxError
skipped << path
next
end
new_path.dirname.mkpath
new_path.write(covered_code.covered_source)
end
unless skipped.empty?
warn [
"#{skipped.size} files could not be instrumented because of syntax errors:",
*skipped.first(3),
('...' if skipped.size > 3),
].compact.join("\n")
end
dest_path
end
|