Support LCOV visualization for both C and Ruby code
`./configure --enable-gcov && make exam && make lcov` will create `lcov-c-out/index.html` for coverage of C code of the interpreter. `make exam COVERAGE=true && make lcov` will create `lcov-rb-out/index.html` for coverage of Ruby stdlib code. Using both `--enable-gcov` and `COVERAGE=true` will create `lcov-out/index.html` for total coverage. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
19ae6bc70d
commit
0919c05501
2
.gitignore
vendored
2
.gitignore
vendored
@ -82,6 +82,8 @@ lcov*.info
|
|||||||
/goruby
|
/goruby
|
||||||
/id.[ch]
|
/id.[ch]
|
||||||
/largefile.h
|
/largefile.h
|
||||||
|
/lcov-c-out
|
||||||
|
/lcov-rb-out
|
||||||
/lcov-out
|
/lcov-out
|
||||||
/lex.c
|
/lex.c
|
||||||
/libruby*.*
|
/libruby*.*
|
||||||
|
@ -500,7 +500,6 @@ gcov:
|
|||||||
|
|
||||||
lcov:
|
lcov:
|
||||||
$(Q) $(BASERUBY) $(srcdir)/tool/run-lcov.rb
|
$(Q) $(BASERUBY) $(srcdir)/tool/run-lcov.rb
|
||||||
$(Q) genhtml --ignore-errors source lcov-c-all.info -o lcov-out
|
|
||||||
|
|
||||||
update-doclie:
|
update-doclie:
|
||||||
$(Q) $(srcdir)/tool/git-refresh -C $(srcdir)/coverage $(Q1:0=-q) \
|
$(Q) $(srcdir)/tool/git-refresh -C $(srcdir)/coverage $(Q1:0=-q) \
|
||||||
|
@ -24,18 +24,59 @@ def run_lcov(dir, info)
|
|||||||
system("lcov", "-c", "-d", dir, "--rc", "lcov_branch_coverage=1", "-o", info)
|
system("lcov", "-c", "-d", dir, "--rc", "lcov_branch_coverage=1", "-o", info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gen_rb_lcov(file)
|
||||||
|
res = Marshal.load(File.binread(file))
|
||||||
|
|
||||||
|
open("lcov-rb-all.info", "w") do |f|
|
||||||
|
f.puts "TN:" # no test name
|
||||||
|
base_dir = File.dirname(__dir__)
|
||||||
|
res.each do |path, cov|
|
||||||
|
next unless path.start_with?(base_dir)
|
||||||
|
next if path.start_with?(File.join(base_dir, "test"))
|
||||||
|
f.puts "SF:#{ path }"
|
||||||
|
|
||||||
|
total = covered = 0
|
||||||
|
cov.each_with_index do |count, lineno|
|
||||||
|
next unless count
|
||||||
|
f.puts "DA:#{ lineno + 1 },#{ count }"
|
||||||
|
total += 1
|
||||||
|
covered += 1 if count > 0
|
||||||
|
end
|
||||||
|
f.puts "LF:#{ total }"
|
||||||
|
f.puts "LH:#{ covered }"
|
||||||
|
|
||||||
|
f.puts "end_of_record"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
gcda_files = Pathname.glob("**/*.gcda")
|
gcda_files = Pathname.glob("**/*.gcda")
|
||||||
ext_gcda_files = gcda_files.select {|f| f.fnmatch("ext/*") }
|
ext_gcda_files = gcda_files.select {|f| f.fnmatch("ext/*") }
|
||||||
rubyspec_temp_gcda_files = gcda_files.select {|f| f.fnmatch("rubyspec_temp/*") }
|
rubyspec_temp_gcda_files = gcda_files.select {|f| f.fnmatch("rubyspec_temp/*") }
|
||||||
|
|
||||||
backup_gcda_files(rubyspec_temp_gcda_files) do
|
backup_gcda_files(rubyspec_temp_gcda_files) do
|
||||||
backup_gcda_files(ext_gcda_files) do
|
if ext_gcda_files != []
|
||||||
info = "lcov-root.info"
|
backup_gcda_files(ext_gcda_files) do
|
||||||
run_lcov(".", info)
|
info = "lcov-root.info"
|
||||||
|
run_lcov(".", info)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ext_gcda_files.group_by {|f| f.descend.to_a[1] }.each do |key, files|
|
ext_gcda_files.group_by {|f| f.descend.to_a[1] }.each do |key, files|
|
||||||
info = "lcov-#{ key.to_s.gsub(File::Separator, "-") }.info"
|
info = "lcov-#{ key.to_s.gsub(File::Separator, "-") }.info"
|
||||||
run_lcov(key.to_s, info)
|
run_lcov(key.to_s, info)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
system("lcov", *$info_files.flat_map {|f| ["-a", f] }, "-o", "lcov-c-all.info")
|
if $info_files != []
|
||||||
|
system("lcov", *$info_files.flat_map {|f| ["-a", f] }, "-o", "lcov-c-all.info")
|
||||||
|
system("genhtml", "--ignore-errors", "source", "lcov-c-all.info", "-o", "lcov-c-out")
|
||||||
|
end
|
||||||
|
|
||||||
|
if File.readable?("test-coverage.dat")
|
||||||
|
gen_rb_lcov("test-coverage.dat")
|
||||||
|
system("genhtml", "--ignore-errors", "source", "lcov-rb-all.info", "-o", "lcov-rb-out")
|
||||||
|
end
|
||||||
|
|
||||||
|
if File.readable?("lcov-c-all.info") && File.readable?("lcov-rb-all.info")
|
||||||
|
system("lcov", "-a", "lcov-c-all.info", "-a", "lcov-rb-all.info", "-o", "lcov-all.info") || raise
|
||||||
|
system("genhtml", "--ignore-errors", "source", "lcov-all.info", "-o", "lcov-out")
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user