-
Notifications
You must be signed in to change notification settings - Fork 553
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
Ensure branches Hash is present when supported #972
base: main
Are you sure you want to change the base?
Ensure branches Hash is present when supported #972
Conversation
Hi there, thanks for your contribution. 🎉 I'm a bit torn about this. We don't support Ruby 2.3. So, consuming Ruby 2.3 in Ruby 2.5+ seems odd... I can see where you're coming from though. It sets a bit of a dangerous precedent though for the direction of the project - should we always assume that we must be able to consume coverage reports generated by a ruby version that supports a feature set different from our own? How and where are you doing the merge of the coverage reports? Are you product the resultset and then merging them via I know it's very little code right now, but if we took this in I wonder if it'd be in the best place for it. Anyhow, have a bunny picture: |
@@ -101,6 +101,10 @@ | |||
it "has proper results for three.rb" do | |||
expect(subject[source_fixture("three.rb")]["lines"]).to eq([nil, 3, 7]) | |||
end | |||
|
|||
it "always returns a Hash object for branches" do | |||
expect(subject[source_fixture("three.rb")]["branches"]).to eq({}) if SimpleCov.branch_coverage_supported? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can filter on the spec level: https://relishapp.com/rspec/rspec-core/v/3-10/docs/filtering/conditional-filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL, thank you for that! Addressed.
As for if we wanted to support this I'm thinking where the best place for it would be... putting it into simplecov/lib/simplecov/combine.rb Lines 26 to 28 in 75e1c63
on the other hand, the code you linked deals specifically with building branches - why would we invoke this with empty data rather than avoid doing it? Maybe that'd be the better move if we don't have branch data. simplecov/lib/simplecov/source_file.rb Lines 268 to 269 in dd35066
Like if we did something like:
Would that also solve the problem or just lead to more problems as If you get Interesting case 🤔 |
I'm semi sure the bug was introduced by bundler upgrade, but `bundler update pry` then removed the pry-java version but everything still seems to be working so... 🤷 Errornous build: https://github.com/simplecov-ruby/simplecov/pull/972/checks?check_run_id=1841431350 PR in which this occured: #972
The JRuby CI failure should hopefully be fixed in #973 |
I'm semi sure the bug was introduced by bundler upgrade, but `bundler update pry` then removed the pry-java version but everything still seems to be working so... 🤷 Errornous build: https://github.com/simplecov-ruby/simplecov/pull/972/checks?check_run_id=1841431350 PR in which this occured: #972
👋 @PragTob, thank you for the bunny! We are collating the coverage results running our test suite with multiple versions of Ruby (2.0 to 3.0 + latest JRuby): https://github.com/DataDog/dd-trace-rb/blob/d6e0e934fa97330ed4934853aa2442649d070e84/Rakefile#L942-L956. We collate the results under Ruby 2.7. We do this because some code paths are exclusive to a specific version of Ruby, so the combined coverage is what we are after. We also keep a separate report per language, but that one is not affected by this issue. The error is triggered when SimpleCov processes files that are only loaded by versions of Ruby that do not support branch coverage (e.g. Rails 4.0 tests run on Ruby 2.3, but are not even loaded in Ruby 3.0). Files that are loaded in all Ruby versions are merged correctly across all versions of Ruby, regardless of their branch coverage support. Our Regarding possible solutions: Making the change in simplecov/lib/simplecov/combine.rb Lines 26 to 28 in 75e1c63
has the complication of SimpleCov::Combine being used for both arrays (for line coverage) and hash (for branch coverage). We would have to have distinct empty default values for each case. Nothing that can't be achieved with an extra argument, but I thought that leaving this responsibility to the caller made more sense when I was writing this patch.
I interpreted this line, Because this error happens in my gem when we do expect branch coverage to be reported, I'm not sure if interpreting the lack of Overall, I agree with your sentiment that this might not be the very best solution to the issue at hand. The change I introduced, in the place it was introduced, wasn't my first option, but it seem like themost reasonable one after browsing the code base for a while. I'm more than willing to make any changes required here, if you have a suggestion. Thank you so much for such a detailed review so far! 🙇 |
33cbb8e
to
574b45c
Compare
Hi folks. I attempted to remove usage of this patch from dd-trace-rb since we now require at least Ruby 2.5 (DataDog/dd-trace-rb#3977). While all MRI versions pass CI without the changes in this PR, JRuby 9.3 and 9.4 are failing. I am not very familiar with the change itself, but it seems like JRuby does not support branch coverage in any released version? Would you consider merging this PR for JRuby? |
While working on a project that supports both Ruby 2.3 and 2.5, we merge our coverage results across all versions.
While trying to enable branch, coverage we came across an issue with merging coverage results.
From
lib/simplecov/source_file.rb:269
:simplecov/lib/simplecov/source_file.rb
Lines 268 to 269 in dd35066
This issue happens because merging coverage results that don't include "branches" data inside a Ruby process that supports branch coverage can lead to a uninitialized
combination["branches"
(valuenil
) here:simplecov/lib/simplecov/combine/files_combiner.rb
Line 19 in dd35066
This
nil
value then causes the issue mentioned earlier, whencoverage_data.fetch("branches", {}).flat_map
gets invoked.This PR changes the
FilesCombiner
to ensure that, whenSimpleCov.branch_coverage?
is supported,branches
is always a Hash.