summaryrefslogtreecommitdiff
path: root/ext/coverage/lib
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-20 05:33:04 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-20 05:33:04 +0000
commit47ea999b4689fc591478a05da1670d2008a4a705 (patch)
treebdc3770f0bbf8975189e1422cc18c545150e5dab /ext/coverage/lib
parentfadde099e637e875d382d9182651e4d7f23dcc76 (diff)
ext/coverage/: add the oneshot mode
This patch introduces "oneshot_lines" mode for `Coverage.start`, which checks "whether each line was executed at least once or not", instead of "how many times each line was executed". A hook for each line is fired at most once, and after it is fired, the hook flag was removed; it runs with zero overhead. See [Feature #15022] in detail. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/coverage/lib')
-rw-r--r--ext/coverage/lib/coverage.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/coverage/lib/coverage.rb b/ext/coverage/lib/coverage.rb
new file mode 100644
index 0000000000..7a6ef0e100
--- /dev/null
+++ b/ext/coverage/lib/coverage.rb
@@ -0,0 +1,14 @@
+require "coverage.so"
+
+module Coverage
+ def self.line_stub(file)
+ lines = File.foreach(file).map { nil }
+ iseqs = [RubyVM::InstructionSequence.compile_file(file)]
+ until iseqs.empty?
+ iseq = iseqs.pop
+ iseq.trace_points.each {|n, _| lines[n - 1] = 0 }
+ iseq.each_child {|child| iseqs << child }
+ end
+ lines
+ end
+end