mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
ecccd9f42c
commit
a86eacf552
4 changed files with 69 additions and 8 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Sat Feb 14 00:49:37 2015 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Fri Feb 13 21:52:05 2015 Yusuke Endoh <mame@tsg.ne.jp>
|
Fri Feb 13 21:52:05 2015 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* string.c (str_discard): does not free for STR_NOFREE string.
|
* string.c (str_discard): does not free for STR_NOFREE string.
|
||||||
|
|
4
NEWS
4
NEWS
|
@ -44,6 +44,10 @@ with all sufficient information, see the ChangeLog file.
|
||||||
* Base64.urlsafe_decode64: now it accepts not only correctly-padded
|
* Base64.urlsafe_decode64: now it accepts not only correctly-padded
|
||||||
input but also unpadded input.
|
input but also unpadded input.
|
||||||
|
|
||||||
|
* ext/coverage/coverage.c
|
||||||
|
* Coverage.peek_result: new method to allow coverage to be captured without
|
||||||
|
stopping the coverage tool.
|
||||||
|
|
||||||
=== Built-in global variables compatibility issues
|
=== Built-in global variables compatibility issues
|
||||||
|
|
||||||
=== C API updates
|
=== C API updates
|
||||||
|
|
|
@ -33,18 +33,44 @@ rb_coverage_start(VALUE klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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 path = (VALUE)key;
|
||||||
VALUE coverage = (VALUE)val;
|
VALUE coverage = (VALUE)val;
|
||||||
VALUE coverages = (VALUE)h;
|
VALUE coverages = (VALUE)h;
|
||||||
coverage = rb_ary_dup(coverage);
|
coverage = rb_ary_dup(coverage);
|
||||||
rb_ary_clear((VALUE)val);
|
|
||||||
rb_ary_freeze(coverage);
|
rb_ary_freeze(coverage);
|
||||||
rb_hash_aset(coverages, path, coverage);
|
rb_hash_aset(coverages, path, coverage);
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* Coverage.peek_result => hash
|
||||||
|
*
|
||||||
|
* Returns a hash that contains filename as key and coverage array as value.
|
||||||
|
*/
|
||||||
|
static VALUE
|
||||||
|
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_peek_result_i, ncoverages);
|
||||||
|
rb_hash_freeze(ncoverages);
|
||||||
|
return ncoverages;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* Coverage.result => hash
|
* Coverage.result => hash
|
||||||
|
@ -55,13 +81,9 @@ coverage_result_i(st_data_t key, st_data_t val, st_data_t h)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_coverage_result(VALUE klass)
|
rb_coverage_result(VALUE klass)
|
||||||
{
|
{
|
||||||
|
VALUE ncoverages = rb_coverage_peek_result(klass);
|
||||||
VALUE coverages = rb_get_coverages();
|
VALUE coverages = rb_get_coverages();
|
||||||
VALUE ncoverages = rb_hash_new();
|
st_foreach(RHASH_TBL(coverages), coverage_clear_result_i, ncoverages);
|
||||||
if (!RTEST(coverages)) {
|
|
||||||
rb_raise(rb_eRuntimeError, "coverage measurement is not enabled");
|
|
||||||
}
|
|
||||||
st_foreach(RHASH_TBL(coverages), coverage_result_i, ncoverages);
|
|
||||||
rb_hash_freeze(ncoverages);
|
|
||||||
rb_reset_coverages();
|
rb_reset_coverages();
|
||||||
return ncoverages;
|
return ncoverages;
|
||||||
}
|
}
|
||||||
|
@ -105,5 +127,6 @@ Init_coverage(void)
|
||||||
VALUE rb_mCoverage = rb_define_module("Coverage");
|
VALUE rb_mCoverage = rb_define_module("Coverage");
|
||||||
rb_define_module_function(rb_mCoverage, "start", rb_coverage_start, 0);
|
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, "result", rb_coverage_result, 0);
|
||||||
|
rb_define_module_function(rb_mCoverage, "peek_result", rb_coverage_peek_result, 0);
|
||||||
rb_gc_register_address(&rb_coverages);
|
rb_gc_register_address(&rb_coverages);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,32 @@ class TestCoverage < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_coverage_snapshot
|
||||||
|
loaded_features = $".dup
|
||||||
|
|
||||||
|
Dir.mktmpdir {|tmp|
|
||||||
|
Dir.chdir(tmp) {
|
||||||
|
File.open("test.rb", "w") do |f|
|
||||||
|
f.puts <<-EOS
|
||||||
|
def coverage_test_method
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
Coverage.start
|
||||||
|
require tmp + '/test.rb'
|
||||||
|
cov = Coverage.peek_result[tmp + '/test.rb']
|
||||||
|
coverage_test_method
|
||||||
|
cov2 = Coverage.peek_result[tmp + '/test.rb']
|
||||||
|
assert_equal cov[1] + 1, cov2[1]
|
||||||
|
assert_equal cov2, Coverage.result[tmp + '/test.rb']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ensure
|
||||||
|
$".replace loaded_features
|
||||||
|
end
|
||||||
|
|
||||||
def test_restarting_coverage
|
def test_restarting_coverage
|
||||||
loaded_features = $".dup
|
loaded_features = $".dup
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue