Project

General

Profile

Actions

Bug #19026

closed

Add `Coverage.supported?(x)` to detect support for `eval` coverage flag.

Added by ioquatix (Samuel Williams) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:110119]

Description

Introduce the following interface:

Coverage.supported?(eval) -> true/false

We can also check lines branches and methods?

Updated by mame (Yusuke Endoh) over 1 year 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 mame (Yusuke Endoh) over 1 year 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) over 1 year ago

Isn't there a general mechanism for feature support? Like RbConfig.support?(:eval_coverage) or something?

Updated by jeremyevans0 (Jeremy Evans) over 1 year 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 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?

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) over 1 year 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 as Coverage.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) over 1 year 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) over 1 year 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) over 1 year 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0