Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3.0 does not include Coverage.setup #14

Closed
mschwager opened this issue Mar 25, 2024 · 0 comments
Closed

Ruby 3.0 does not include Coverage.setup #14

mschwager opened this issue Mar 25, 2024 · 0 comments

Comments

@mschwager
Copy link
Member

For reasons related to #9, Ruzzy requires calling Coverage.setup for its coverage support:

ruzzy/ext/cruzzy/cruzzy.c

Lines 195 to 211 in 0f554e6

static void enable_branch_coverage_hooks()
{
// Call Coverage.setup(branches: true) to activate branch coverage hooks.
// Branch coverage hooks will not be activated without this call despite
// adding the event hooks. I suspect rb_set_coverages must be called
// first, which initializes some global state that we do not have direct
// access to. Calling setup initializes coverage state here:
// https://github.com/ruby/ruby/blob/v3_3_0/ext/coverage/coverage.c#L112-L120
// If rb_set_coverages is not called, then rb_get_coverages returns a NULL
// pointer, which appears to effectively disable coverage collection here:
// https://github.com/ruby/ruby/blob/v3_3_0/iseq.c
rb_require("coverage");
VALUE coverage_mod = rb_const_get(rb_cObject, rb_intern("Coverage"));
VALUE hash_arg = rb_hash_new();
rb_hash_aset(hash_arg, ID2SYM(rb_intern("branches")), Qtrue);
rb_funcall(coverage_mod, rb_intern("setup"), 1, hash_arg);
}

Unfortunately, Coverage.setup was not added until Ruby 3.1.0:

Notably, Ubuntu 22.04 is still using Ruby 3.0.X. Coverage.start is available in 3.0, and should achieve the same effect. We need to either unconditionally call Coverage.start, or find a way to conditionally call start vs. setup, and test that this works on Ubuntu 22.04.

mschwager added a commit that referenced this issue Mar 26, 2024
Fix #14, support for Ruby back to 3.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant