ruby-changes:47600
From: mame <ko1@a...>
Date: Fri, 1 Sep 2017 23:58:57 +0900 (JST)
Subject: [ruby-changes:47600] mame:r59716 (trunk): ext/coverage/coverage.c: add Coverage.enabled?
mame 2017-09-01 23:58:52 +0900 (Fri, 01 Sep 2017) New Revision: 59716 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59716 Log: ext/coverage/coverage.c: add Coverage.enabled? * ext/coverage/coverage.c (rb_coverage_running): add to quickly check if coverage is enabled. patched by Burke Libbey <burke AT libbey.me> in [ruby-core:81726]. [Feature #13667] Modified files: trunk/ext/coverage/coverage.c trunk/test/coverage/test_coverage.rb Index: test/coverage/test_coverage.rb =================================================================== --- test/coverage/test_coverage.rb (revision 59715) +++ test/coverage/test_coverage.rb (revision 59716) @@ -23,6 +23,16 @@ class TestCoverage < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/coverage/test_coverage.rb#L23 end end + def test_coverage_running? + refute Coverage.running? + Coverage.start + assert Coverage.running? + Coverage.peek_result + assert Coverage.running? + Coverage.result + refute Coverage.running? + end + def test_coverage_snapshot loaded_features = $".dup Index: ext/coverage/coverage.c =================================================================== --- ext/coverage/coverage.c (revision 59715) +++ ext/coverage/coverage.c (revision 59716) @@ -75,6 +75,20 @@ rb_coverage_result(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/coverage/coverage.c#L75 return ncoverages; } +/* + * call-seq: + * Coverage.running? => bool + * + * Returns true if coverage stats are currently being collected (after + * Coverage.start call, but before Coverage.result call) + */ +static VALUE +rb_coverage_running(VALUE klass) +{ + VALUE coverages = rb_get_coverages(); + return RTEST(coverages) ? Qtrue : Qfalse; +} + /* Coverage provides coverage measurement feature for Ruby. * This feature is experimental, so these APIs may be changed in future. * @@ -115,4 +129,5 @@ Init_coverage(void) https://github.com/ruby/ruby/blob/trunk/ext/coverage/coverage.c#L129 rb_define_module_function(rb_mCoverage, "start", rb_coverage_start, 0); rb_define_module_function(rb_mCoverage, "result", rb_coverage_result, 0); rb_define_module_function(rb_mCoverage, "peek_result", rb_coverage_peek_result, 0); + rb_define_module_function(rb_mCoverage, "running?", rb_coverage_running, 0); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/