Repository navigation
Conversation
7f21245 to
52d21e0
Compare
126b662 to
5bf996a
Compare
|
Not sure if it helps, but I just found this Ruby gem which has some utilities for working with Ruby branch coverage data. |
5bf996a to
91c185b
Compare
| # lines coverage report on not supportable versions. | ||
| # | ||
| def target_capability(target) | ||
| if (RUBY_VERSION.to_f < 2.5) && target |
There was a problem hiding this comment.
is there another way to check for this, maybe just Coverage.method(:start).arity ?
There was a problem hiding this comment.
Yes, using arity looks nicer.
|
Thanks |
|
Done, updated the ruby version check using |
|
I need this feature; is anyone ever going to pick this up? I've tried running it on Ruby 2.6 with RSpec, it doesn't seem to work, I just get the exact same HTML I'd get with vanilla simplecov. |
|
@pelletencate |
magneland
left a comment
There was a problem hiding this comment.
I've been interested in using this feature for a while now, so I'm reviewing it. Hopefully it will be well received. Please excuse any comments that are too uninformed. In general I am concerned about correctness and performance, but I don't have a way to test performance myself. I have also commented on wording and typos, but feel free to ignore those.
| SimpleCov.refuse_coverage_drop | ||
| ``` | ||
|
|
||
| ## Branch coverage (ruby '~> 2.5') |
There was a problem hiding this comment.
I'll start my code review here by summarizing the (not always documented) feature in Ruby core.
There are many possible types of code coverage now thanks to mame's work.
Ruby < 2.5:
https://github.com/ruby/ruby/blob/v1_9_3_374/ext/coverage/coverage.c
traditional mode (Array)
Ruby 2.5:
https://bugs.ruby-lang.org/issues/13901
https://github.com/ruby/ruby/blob/v2_5_3/ext/coverage/coverage.c
default: traditional/compatible mode (Array)
:lines - like traditional mode but using Hash
:branches
:methods
:all - same as lines + branches + methods
Ruby >= 2.6:
https://bugs.ruby-lang.org/issues/15022
https://github.com/ruby/ruby/blob/v2_6_3/ext/coverage/coverage.c
default: traditional/compatible mode (Array)
:lines - like traditional mode but using Hash
:branches
:methods
:oneshot_lines - can not be combined with lines
:all - same as lines + branches + methods
So my first question is: can the flexibility of multiple modes be exposed in Simplecov as well?
It would seem that this PR currently exposes 2 modes:
default: traditional/compatible mode (Array)
:all - same as lines + branches + methods
Since I am personally interested in :oneshot_lines in the (near) future, I wonder how that can be made compatible using a similar syntax. Or perhaps Simplecov could reflect the syntax of coverage.c?
There was a problem hiding this comment.
@magneland hi there! Sorry for all the tardyness, hard at work trying to get in. I fail to find documentation for oneshot_lines in the metioned files? Can you point me somewhere?
| # | ||
| def self.start(source_file_path) | ||
| return {} unless SimpleCov.branchable_report | ||
| Coverage.start(:all) |
There was a problem hiding this comment.
Should this be Coverage.start(:lines, :branches)? It seems :methods is not being used for anything in this PR?
There was a problem hiding this comment.
I will handle it in the scope of change used option name.
|
|
||
| branch1.each do |(condition, branches_inside)| | ||
| branches_inside.each do |(branch_key, branch_coverage_value)| | ||
| compared_branch_coverage = branch2[condition][branch_key] |
There was a problem hiding this comment.
Does it need a guard clause for handling missing condition in branch2? Default value should be 0 I think. Also - does it make sense to replace this code with merge_branches here? https://github.com/mame/coverage-helpers/blob/4d2a33d3dec8c8bbf51bb21a3cdaf57d2481472e/lib/coverage/helpers.rb#L24
There was a problem hiding this comment.
Yep, you are right, I think .to_i will be ok
first_coverage.merge(second_coverage) do |_condition, first_matrices, second_matrices|
first_matrices.merge(second_matrices) do |_condition, first_run, second_run|
first_run + second_run.to_i
end
end
| groups[group_name] = parse_filter(filter_argument, &filter_proc) | ||
| end | ||
|
|
||
| # Define if the report should include any other standarts of coverage measurement except |
| end | ||
|
|
||
| # Manage symbolize the keys of coverage hash. | ||
| # JSON.prase gives coverage hash with stringified keys what breaks some logics |
| expect(subject.root_branches.size).to eq(2) | ||
| end | ||
|
|
||
| it "Has branch on line number 7 with report pr line" do |
| end | ||
|
|
||
| it "Has coverage report" do | ||
| expect(subject.branches_report).to eq(17 => [[3, "+"]], 19 => [[0, "-"]], 29 => [[3, "+"]], 31 => [[0, "-"]]) |
There was a problem hiding this comment.
19 and 31 should be 20 and 32? See earlier comment about zero-based keys.
There was a problem hiding this comment.
this case is a multi-line branch if, else.., these branches should have badges on the line of the condition definition, that's why I have done branch.start_line - 1, otherwise, the badge statistics would appear on the first line of the branch body which is misleading from my point of view.
| expect(subject.branches_report).to eq(17 => [[3, "+"]], 19 => [[0, "-"]], 29 => [[3, "+"]], 31 => [[0, "-"]]) | ||
| end | ||
|
|
||
| it "Hash line 31 with missed branches" do |
| expect(subject.branches_report[18]).to eq([[3, "+"], [0, "-"]]) | ||
| end | ||
|
|
||
| it "Has branches coverage precent 50.00" do |
| end | ||
|
|
||
| it "Has branches coverage precent 50.00" do | ||
| expect(subject.branches_coverage_precent).to eq(50.00) |
There was a problem hiding this comment.
I just followed the standard definition of percentage for line coverage calculation.
| source_fixture("three.rb") => [nil, 1, 1], | ||
| source_fixture("sample.rb") => { | ||
| :lines => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil], | ||
| :branches => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}, |
There was a problem hiding this comment.
Was there supposed to be a corresponding fixture change in this PR? Or is this intended to be fake branch data?
magneland
left a comment
There was a problem hiding this comment.
One more general comment: I am taking a look at the corresponding HTML report change here: simplecov-ruby/simplecov-html#64 The interesting / unfortunate thing is that the tests for the HTML reports actually are in this repo.
|
See my comment in the other PR Basically!
Thanks, have a bunny: |
|
@magneland Thank you 👍 |

Add branch coverage measurement statistics (ruby ~> 2.5)
In this PR:
If config is set for ruby versions which are < 2.5, It will shows notify message and produce only lines coverage report.
{:lines => ..., :branches => ..}.Branchclass with related support methods toSourceFile[0, '-'] => [passing count, branch sign]Condition with missed branch will be marked similar to line 70.
Benefits:
Frankly, the first time I developed this feature it was a PR with 1300 diff lines, I thought it will be quite hard to review it. So this one is about 760 lines and hopes it will be approved.