зеркало из https://github.com/github/ruby.git
Add `eval: true/false` flag to `Coverage.setup`.
This commit is contained in:
Родитель
ac56e5c1ab
Коммит
9dd902b831
|
@ -25,10 +25,10 @@ static VALUE me2counter = Qnil;
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* Coverage.setup => nil
|
||||
* Coverage.setup(:all) => nil
|
||||
* Coverage.setup(lines: bool, branches: bool, methods: bool) => nil
|
||||
* Coverage.setup(oneshot_lines: true) => nil
|
||||
* Coverage.setup => nil
|
||||
* Coverage.setup(:all) => nil
|
||||
* Coverage.setup(lines: bool, branches: bool, methods: bool, eval: bool) => nil
|
||||
* Coverage.setup(oneshot_lines: true) => nil
|
||||
*
|
||||
* Set up the coverage measurement.
|
||||
*
|
||||
|
@ -53,7 +53,7 @@ rb_coverage_setup(int argc, VALUE *argv, VALUE klass)
|
|||
mode = 0; /* compatible mode */
|
||||
}
|
||||
else if (opt == ID2SYM(rb_intern("all"))) {
|
||||
mode = COVERAGE_TARGET_LINES | COVERAGE_TARGET_BRANCHES | COVERAGE_TARGET_METHODS;
|
||||
mode = COVERAGE_TARGET_LINES | COVERAGE_TARGET_BRANCHES | COVERAGE_TARGET_METHODS | COVERAGE_TARGET_EVAL;
|
||||
}
|
||||
else {
|
||||
mode = 0;
|
||||
|
@ -71,6 +71,8 @@ rb_coverage_setup(int argc, VALUE *argv, VALUE klass)
|
|||
mode |= COVERAGE_TARGET_LINES;
|
||||
mode |= COVERAGE_TARGET_ONESHOT_LINES;
|
||||
}
|
||||
if (RTEST(rb_hash_lookup(opt, ID2SYM(rb_intern("eval")))))
|
||||
mode |= COVERAGE_TARGET_EVAL;
|
||||
}
|
||||
|
||||
if (mode & COVERAGE_TARGET_METHODS) {
|
||||
|
@ -93,7 +95,6 @@ rb_coverage_setup(int argc, VALUE *argv, VALUE klass)
|
|||
rb_raise(rb_eRuntimeError, "cannot change the measuring target during coverage measurement");
|
||||
}
|
||||
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
@ -124,10 +125,10 @@ rb_coverage_resume(VALUE klass)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* Coverage.start => nil
|
||||
* Coverage.start(:all) => nil
|
||||
* Coverage.start(lines: bool, branches: bool, methods: bool) => nil
|
||||
* Coverage.start(oneshot_lines: true) => nil
|
||||
* Coverage.start => nil
|
||||
* Coverage.start(:all) => nil
|
||||
* Coverage.start(lines: bool, branches: bool, methods: bool, eval: bool) => nil
|
||||
* Coverage.start(oneshot_lines: true) => nil
|
||||
*
|
||||
* Enables the coverage measurement.
|
||||
* See the documentation of Coverage class in detail.
|
||||
|
|
|
@ -20,6 +20,7 @@ struct rb_thread_struct; /* in vm_core.h */
|
|||
#define COVERAGE_TARGET_BRANCHES 2
|
||||
#define COVERAGE_TARGET_METHODS 4
|
||||
#define COVERAGE_TARGET_ONESHOT_LINES 8
|
||||
#define COVERAGE_TARGET_EVAL 16
|
||||
|
||||
VALUE rb_obj_is_mutex(VALUE obj);
|
||||
VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
|
||||
|
|
8
iseq.c
8
iseq.c
|
@ -929,9 +929,11 @@ rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_
|
|||
rb_iseq_t *
|
||||
rb_iseq_new_eval(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth)
|
||||
{
|
||||
VALUE coverages = rb_get_coverages();
|
||||
if (RTEST(coverages) && RTEST(path) && !RTEST(rb_hash_has_key(coverages, path))) {
|
||||
iseq_setup_coverage(coverages, path, ast, first_lineno - 1);
|
||||
if (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) {
|
||||
VALUE coverages = rb_get_coverages();
|
||||
if (RTEST(coverages) && RTEST(path) && !RTEST(rb_hash_has_key(coverages, path))) {
|
||||
iseq_setup_coverage(coverages, path, ast, first_lineno - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return rb_iseq_new_with_opt(ast, name, path, realpath, first_lineno,
|
||||
|
|
|
@ -147,11 +147,11 @@ class TestCoverage < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
assert_in_out_err(%w[-W0 -rcoverage], <<-"end;", ["[1, 1, 1, 400, nil, nil, nil, nil, nil, nil, nil]"], [], bug13305)
|
||||
Coverage.start
|
||||
Coverage.start(:all)
|
||||
tmp = Dir.pwd
|
||||
require tmp + '/test.rb'
|
||||
add_method(Class.new)
|
||||
p Coverage.result[tmp + "/test.rb"]
|
||||
p Coverage.result[tmp + "/test.rb"][:lines]
|
||||
end;
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ class TestCoverage < Test::Unit::TestCase
|
|||
|
||||
def test_eval_coverage
|
||||
assert_in_out_err(%w[-rcoverage], <<-"end;", ["[1, nil, 1, nil]"], [])
|
||||
Coverage.start
|
||||
Coverage.start(eval: true, lines: true)
|
||||
|
||||
eval(<<-RUBY, TOPLEVEL_BINDING, "test.rb")
|
||||
s = String.new
|
||||
|
@ -168,7 +168,7 @@ class TestCoverage < Test::Unit::TestCase
|
|||
bar".freeze; end
|
||||
RUBY
|
||||
|
||||
p Coverage.result["test.rb"]
|
||||
p Coverage.result["test.rb"][:lines]
|
||||
end;
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче