ruby-changes:6684
From: mame <ko1@a...>
Date: Fri, 25 Jul 2008 02:47:53 +0900 (JST)
Subject: [ruby-changes:6684] Ruby:r18200 (trunk): * sample/coverage.rb: move from lib/coverage.rb because this remains in
mame 2008-07-25 02:47:34 +0900 (Fri, 25 Jul 2008) New Revision: 18200 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18200 Log: * sample/coverage.rb: move from lib/coverage.rb because this remains in an early phase of development. Added files: trunk/sample/coverage.rb Removed files: trunk/lib/coverage.rb Modified files: trunk/ChangeLog Index: ChangeLog =================================================================== --- ChangeLog (revision 18199) +++ ChangeLog (revision 18200) @@ -1,3 +1,8 @@ +Fri Jul 25 02:43:11 2008 Yusuke Endoh <mame@t...> + + * sample/coverage.rb: move from lib/coverage.rb because this remains in + an early phase of development. + Fri Jul 25 00:10:23 2008 Nobuyoshi Nakada <nobu@r...> * file.c (rb_find_file_ext, rb_find_file): converts Windows style path Index: sample/coverage.rb =================================================================== --- sample/coverage.rb (revision 0) +++ sample/coverage.rb (revision 18200) @@ -0,0 +1,60 @@ +require "coverage.so" + +Coverage.start + +ext = ENV["COVERUBY_EXT"] || ".cov" +accum = ENV["COVERUBY_ACCUM"] +accum = !accum || accum == "" || !(%w(f n 0).include?(accum[0])) +pwd = Dir.pwd + +at_exit do + Dir.chdir(pwd) do + Coverage.result.each do |sfile, covs| + cfile = sfile + ext + + writable = proc do |f| + File.writable?(f) || File.writable?(File.dirname(f)) + end + unless writable[cfile] + cfile = cfile.gsub(File.PATH_SEPARATOR, "#") + next unless writable[cfile] + end + + readlines = proc do |f| + File.read(f).force_encoding("ASCII-8BIT").lines.to_a + end + + sources = (readlines[sfile] rescue []) + + pcovs = [] + if accum + pcovs = (readlines[cfile] rescue []).map.with_index do |line, idx| + if line[/^\s*(?:(#####)|(\d+)|-):\s*\d+:(.*)$/n] + cov, line = $1 ? 0 : ($2 ? $2.to_i : nil), $3 + if !sources[idx] || sources[idx].chomp != line.chomp + warn("source file changed, ignoring: `#{ cfile }'") + break [] + end + cov + else + p line + warn("coverage file corrupted, ignoring: #{ cfile }") + break [] + end + end + unless pcovs.empty? || pcovs.size == covs.size + warn("coverage file changed, ignoring: `#{ cfile }'") + pcovs = [] + end + end + + open(cfile, "w") do |out| + covs.zip(sources, pcovs).each_with_index do |(cov, line, pcov), idx| + cov += pcov || 0 if cov + cov = (cov ? (cov == 0 ? "#####" : cov.to_s) : "-").rjust(9) + out.puts("%s:% 5d:%s" % [cov, idx + 1, line]) + end + end + end + end +end Property changes on: sample/coverage.rb ___________________________________________________________________ Name: svn:eol-style + LF Index: lib/coverage.rb =================================================================== --- lib/coverage.rb (revision 18199) +++ lib/coverage.rb (revision 18200) @@ -1,58 +0,0 @@ -require "coverage.so" - -ext = ENV["COVERUBY_EXT"] || ".cov" -accum = ENV["COVERUBY_ACCUM"] -accum = !accum || accum == "" || !(%w(f n 0).include?(accum[0])) -pwd = Dir.pwd - -at_exit do - Dir.chdir(pwd) do - Coverage.result.each do |sfile, covs| - cfile = sfile + ext - - writable = proc do |f| - File.writable?(f) || File.writable?(File.dirname(f)) - end - unless writable[cfile] - cfile = cfile.gsub(File.PATH_SEPARATOR, "#") - next unless writable[cfile] - end - - readlines = proc do |f| - File.read(f).force_encoding("ASCII-8BIT").lines.to_a - end - - sources = (readlines[sfile] rescue []) - - pcovs = [] - if accum - pcovs = (readlines[cfile] rescue []).map.with_index do |line, idx| - if line[/^\s*(?:(#####)|(\d+)|-):\s*\d+:(.*)$/n] - cov, line = $1 ? 0 : ($2 ? $2.to_i : nil), $3 - if !sources[idx] || sources[idx].chomp != line.chomp - warn("source file changed, ignoring: `#{ cfile }'") - break [] - end - cov - else - p line - warn("coverage file corrupted, ignoring: #{ cfile }") - break [] - end - end - unless pcovs.empty? || pcovs.size == covs.size - warn("coverage file changed, ignoring: `#{ cfile }'") - pcovs = [] - end - end - - open(cfile, "w") do |out| - covs.zip(sources, pcovs).each_with_index do |(cov, line, pcov), idx| - cov += pcov || 0 if cov - cov = (cov ? (cov == 0 ? "#####" : cov.to_s) : "-").rjust(9) - out.puts("%s:% 5d:%s" % [cov, idx + 1, line]) - end - end - end - end -end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/