Bug #19026
closedAdd `Coverage.supported?(x)` to detect support for `eval` coverage flag.
Description
Introduce the following interface:
Coverage.supported?(eval) -> true/false
We can also check lines
branches
and methods
?
Updated by mame (Yusuke Endoh) about 2 years ago
Note: This API does determine if the mode is available, not enabled. So Coverage.supported?(:eval)
will always returns true
in Ruby 3.2 regardless of whether Coverage.start(eval: true)
is called.
In my first impression, it is okay, but I'd like to hear opinions. @jeremyevans0 (Jeremy Evans) Do you have any opinion?
Updated by ioquatix (Samuel Williams) about 2 years ago
Commit is currently part of https://github.com/ruby/ruby/pull/6462
Updated by mame (Yusuke Endoh) about 2 years ago
I think it is reasonable to have this feature to determine if Coverage.start(eval: true)
is available. (Note that Coverage.start(eval: true)
just ignores the keyword in Ruby 3.1 or before.)
@ioquatix (Samuel Williams) I would like you to merge the PR to restore the continuous coverage measurement.
If there is anyone who has an opinion against this feature, feel free to add a comment.
Updated by Dan0042 (Daniel DeLorme) about 2 years ago
Isn't there a general mechanism for feature support? Like RbConfig.support?(:eval_coverage)
or something?
Updated by jeremyevans0 (Jeremy Evans) about 2 years ago
mame (Yusuke Endoh) wrote in #note-1:
Note: This API does determine if the mode is available, not enabled. So
Coverage.supported?(:eval)
will always returnstrue
in Ruby 3.2 regardless of whetherCoverage.start(eval: true)
is called.In my first impression, it is okay, but I'd like to hear opinions. @jeremyevans0 (Jeremy Evans) Do you have any opinion?
I think having Coverage.supported?
return true when it is supported is fine. However, it would be useful to have an API such as Coverage.activated?
that only returns true when the specific coverage feature is currently enabled.
Updated by mame (Yusuke Endoh) about 2 years ago
Dan0042 (Daniel DeLorme) wrote in #note-4:
Isn't there a general mechanism for feature support? Like
RbConfig.support?(:eval_coverage)
or something?
I don't think it makes sense because this doesn't change depending on the ruby config.
jeremyevans0 (Jeremy Evans) wrote in #note-5:
I think having
Coverage.supported?
return true when it is supported is fine. However, it would be useful to have an API such asCoverage.activated?
that only returns true when the specific coverage feature is currently enabled.
Thank you for your comment.
@ioquatix (Samuel Williams) didn't write the use case. He wants to use his own coverage measurement based on TracePoint if "coverage for eval" feature is not supported (i.e., in Ruby 3.1 or before). TBH I am not sure if this is a common use case. @ioquatix (Samuel Williams) isn't RUBY_VERSION > "3.1"
enough for your case?
I am not so positive to have Coverage.activated?(:eval or something)
because I don't allow users to write code that changes behavior depending on whether/which coverage is enabled or not. But we already have Coverage.running?
, so I am okay if there is a common use case for Coverage.activated?
.
Updated by Eregon (Benoit Daloze) about 2 years ago
mame (Yusuke Endoh) wrote in #note-6:
@ioquatix (Samuel Williams) isn't
RUBY_VERSION > "3.1"
enough for your case?
Please no. For instance other Ruby implementations might already support eval Coverage trivially or can't support it easily, it should be a feature detection, not a hardcoded version check.
+1 for Coverage.supported?(:eval)
.
Updated by Dan0042 (Daniel DeLorme) about 2 years ago
Isn't there a general mechanism for feature support? Like
RbConfig.support?(:eval_coverage)
or something?I don't think it makes sense because this doesn't change depending on the ruby config.
I didn't mean RbConfig per se, just any kind of general mechanism. It seems there isn't.
Eregon (Benoit Daloze) wrote in #note-7:
+1 for
Coverage.supported?(:eval)
.
But then to use this API you need to do
Coverage.respond_to?(:supported?) && Coverage.supported?(:eval)
or shorten it to just
Coverage.respond_to?(:supported?)
Updated by ioquatix (Samuel Williams) about 2 years ago
- Status changed from Open to Closed
I agree, for the existing Ruby implementations, it's a little clumsy but easily worked around using respond_to?
. Going forward, this is a simple and good interface.
Merged PR.