summaryrefslogtreecommitdiff
path: root/ext/coverage
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-01 14:58:52 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-01 14:58:52 +0000
commit95d949d5717301fec39b8b2e5b817b64761afdf1 (patch)
treed9654f0a108b7002a815bf2137a6782de52cf798 /ext/coverage
parent3d46d51c45b608000d1de02fffa80f0901959e67 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/coverage')
-rw-r--r--ext/coverage/coverage.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c
index 9a9011a..d2077a9 100644
--- a/ext/coverage/coverage.c
+++ b/ext/coverage/coverage.c
@@ -75,6 +75,20 @@ rb_coverage_result(VALUE klass)
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)
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);
}