summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-13 15:53:47 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-13 15:53:47 +0000
commita86eacf552c0f3a7862d6891cf174007d96f656a (patch)
tree9e2bd8acbd7907eb7816acf63c55d4d11b09a71a /ext
parentecccd9f42ce9b75d5a3fc742e81f1dc79bf03abd (diff)
* ext/coverage/coverage.c: Add Coverage.peek_result. Allows you to
capture coverage information without stopping the coverage tool. [ruby-core:67940] [Feature #10816] * test/coverage/test_coverage.rb: test for change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/coverage/coverage.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c
index 93cb2a5..af0cb87 100644
--- a/ext/coverage/coverage.c
+++ b/ext/coverage/coverage.c
@@ -33,13 +33,20 @@ rb_coverage_start(VALUE klass)
}
static int
-coverage_result_i(st_data_t key, st_data_t val, st_data_t h)
+coverage_clear_result_i(st_data_t key, st_data_t val, st_data_t h)
+{
+ VALUE coverage = (VALUE)val;
+ rb_ary_clear((VALUE)val);
+ return ST_CONTINUE;
+}
+
+static int
+coverage_peek_result_i(st_data_t key, st_data_t val, st_data_t h)
{
VALUE path = (VALUE)key;
VALUE coverage = (VALUE)val;
VALUE coverages = (VALUE)h;
coverage = rb_ary_dup(coverage);
- rb_ary_clear((VALUE)val);
rb_ary_freeze(coverage);
rb_hash_aset(coverages, path, coverage);
return ST_CONTINUE;
@@ -47,21 +54,36 @@ coverage_result_i(st_data_t key, st_data_t val, st_data_t h)
/*
* call-seq:
- * Coverage.result => hash
+ * Coverage.peek_result => hash
*
- * Returns a hash that contains filename as key and coverage array as value
- * and disables coverage measurement.
+ * Returns a hash that contains filename as key and coverage array as value.
*/
static VALUE
-rb_coverage_result(VALUE klass)
+rb_coverage_peek_result(VALUE klass)
{
VALUE coverages = rb_get_coverages();
VALUE ncoverages = rb_hash_new();
if (!RTEST(coverages)) {
rb_raise(rb_eRuntimeError, "coverage measurement is not enabled");
}
- st_foreach(RHASH_TBL(coverages), coverage_result_i, ncoverages);
+ st_foreach(RHASH_TBL(coverages), coverage_peek_result_i, ncoverages);
rb_hash_freeze(ncoverages);
+ return ncoverages;
+}
+
+/*
+ * call-seq:
+ * Coverage.result => hash
+ *
+ * Returns a hash that contains filename as key and coverage array as value
+ * and disables coverage measurement.
+ */
+static VALUE
+rb_coverage_result(VALUE klass)
+{
+ VALUE ncoverages = rb_coverage_peek_result(klass);
+ VALUE coverages = rb_get_coverages();
+ st_foreach(RHASH_TBL(coverages), coverage_clear_result_i, ncoverages);
rb_reset_coverages();
return ncoverages;
}
@@ -105,5 +127,6 @@ Init_coverage(void)
VALUE rb_mCoverage = rb_define_module("Coverage");
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_gc_register_address(&rb_coverages);
}