From 0a6816ecd79fac5dfb32eb237f4c31bb45c9460d Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 5 Dec 2017 07:16:42 +0000 Subject: Revamp method coverage to support define_method Traditionally, method coverage measurement was implemented by inserting `trace2` instruction to the head of method iseq. So, it just measured methods defined by `def` keyword. This commit drastically changes the measuring mechanism of method coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t* to runs (i.e., it counts the runs per method entry), and at `Coverage.result`, it creates the result hash by enumerating all `rb_method_entry_t*` objects (by `ObjectSpace.each_object`). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/test-coverage.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tool/test-coverage.rb') diff --git a/tool/test-coverage.rb b/tool/test-coverage.rb index 0719e5e703..d1c324af0d 100644 --- a/tool/test-coverage.rb +++ b/tool/test-coverage.rb @@ -41,6 +41,15 @@ def add_count(h, key, count) end def save_coverage_data(res1) + res1.each do |_path, cov| + if cov[:methods] + h = {} + cov[:methods].each do |(klass, *key), count| + h[[klass.inspect, *key]] = count + end + cov[:methods].replace h + end + end File.open(TEST_COVERAGE_DATA_FILE, File::RDWR | File::CREAT | File::BINARY) do |f| f.flock(File::LOCK_EX) s = f.read -- cgit v1.2.3