5 ext = ENV["COVERUBY_EXT"] || ".cov"
6 accum = ENV["COVERUBY_ACCUM"]
7 accum = !accum || accum == "" || !(%w(f n 0).include?(accum[0]))
12 Coverage.result.each do |sfile, covs|
15 writable = proc do |f|
16 File.writable?(f) || File.writable?(File.dirname(f))
18 unless writable[cfile]
19 cfile = cfile.gsub(File.PATH_SEPARATOR, "#")
20 next unless writable[cfile]
23 readlines = proc do |f|
24 File.read(f).force_encoding("ASCII-8BIT").lines.to_a
27 sources = (readlines[sfile] rescue [])
31 pcovs = (readlines[cfile] rescue []).map.with_index do |line, idx|
32 if line[/^\s*(?:(#####)|(\d+)|-):\s*\d+:(.*)$/n]
33 cov, line = $1 ? 0 : ($2 ? $2.to_i : nil), $3
34 if !sources[idx] || sources[idx].chomp != line.chomp
35 warn("source file changed, ignoring: `#{ cfile }'")
41 warn("coverage file corrupted, ignoring: #{ cfile }")
45 unless pcovs.empty? || pcovs.size == covs.size
46 warn("coverage file changed, ignoring: `#{ cfile }'")
51 open(cfile, "w") do |out|
52 covs.zip(sources, pcovs).each_with_index do |(cov, line, pcov), idx|
53 cov += pcov || 0 if cov
54 cov = (cov ? (cov == 0 ? "#####" : cov.to_s) : "-").rjust(9)
55 out.puts("%s:% 5d:%s" % [cov, idx + 1, line])