Skip to content

Feature/branches coverage support - #694

Merged
PragTob merged 4 commits into
simplecov-ruby:masterfrom
som4ik:feature/branches-coverage-support
Dec 5, 2019
Merged

PragTob merged 4 commits into
simplecov-ruby:masterfrom
som4ik:feature/branches-coverage-support

Conversation

@som4ik

@som4ik som4ik commented Sep 3, 2018 •

Copy link
Copy Markdown
Contributor

Add branch coverage measurement statistics (ruby ~> 2.5)
In this PR:

  • Add configuration needed to trigger this new functionality.
SimpleCov.start do
  use_branchable_report true
end

If config is set for ruby versions which are < 2.5, It will shows notify message and produce only lines coverage report.

  • Unite the results no matter what coverage version used to be there. Now always the coverage result is a hash with keys represents the type of coverage and values represents the coverage result for each type ex: {:lines => ..., :branches => ..}.
  • Add Branch class with related support methods to SourceFile
  • Replace RawCoverage with RunResultsCombiner, which breaks logic of combining different results into file, line and branch combining level, this new structure adds more readability and makes it open for modification (ex: adding methods coverage or any other coverage in future)
  • Remove useless files from the coverage result before any operation on it, as Coverage.start take in case all loaded files including required gems, which files are not inside the project directory.
  • On simplecov-html side we will have this visual statistics:
    branch1
    [0, '-'] => [passing count, branch sign]
    Condition with missed branch will be marked similar to line 70.

Benefits:

  • Coverage report gives more information about conditions especially the inline conditions similar to the case specified above.

@som4ik
som4ik force-pushed the feature/branches-coverage-support branch 2 times, most recently from f42b76f to 93b11c9 Compare September 3, 2018 14:14
@som4ik
som4ik force-pushed the feature/branches-coverage-support branch from 5fdbcdd to 52827cb Compare September 5, 2018 10:14
paulsonkoly added a commit to paulsonkoly/mealy that referenced this pull request Oct 4, 2018
This branch was never covered, detected by
simplecov-ruby/simplecov#694. Now all branches are
covered
@fwininger

Copy link
Copy Markdown

Could we consider this PR ? It's very usefull for our project.

@klyonrad

klyonrad commented Oct 19, 2018 •

Copy link
Copy Markdown

Hey @som4ik , I got very excited after your comments in the issue and tried out your branch in my current work project.

Sadly I encountered an exception after the test suite ran. Maybe the simple CallTrace can help you already; next week I might have a deeper insight with debugging. I hope that is not one specific file that caused this exception 🤣

Our docker base image is phusion passenger ruby25

EDIT:

Are you sure that the require for all the files is stable? I am receiving a loooot of LoadError errors when this is executed.

For me this happens because when modules are defined in the non-nested style like this
module ClassName::Modulename. I don't think that the code should be loaded in ruby - For example when you define a constant and cause an exception this should not completely break the test suite

..../usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov/branches_per_file.rb:17:in `start': undefined method `[]' for nil:NilClass (NoMethodError)
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov/run_file_coverage.rb:26:in `call'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov/run_file_coverage.rb:9:in `start'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:265:in `block in add_not_loaded_files'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:263:in `each'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:263:in `add_not_loaded_files'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:299:in `result_with_not_loaded_files'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:310:in `process_coverage_result'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:70:in `result'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov/configuration.rb:191:in `block in at_exit'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:182:in `run_exit_tasks!'
	from /usr/local/rvm/gems/ruby-2.5.1/bundler/gems/simplecov-52827cb42b93/lib/simplecov/defaults.rb:27:in `block in <top (required)>'


Finished in 1394.358260s, 2.3889 runs/s, 4.2851 assertions/s.
3331 runs, 5975 assertions, 0 failures, 0 errors, 0 skips

Comment thread lib/simplecov/branches_per_file.rb Outdated
def self.start(source_file_path)
return {} unless SimpleCov.branchable_report
Coverage.start(:all)
require source_file_path

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the require is stable? I am receiving a loooot of LoadError errors when this is executed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, thank you for being interested in this PR :), l had a look on your comments:
1 - In line 16 require is called on the absolute file path so it's safe for the file to be required. require can through and LoadError if file/module target is not located in global load path constant.
2 - About the non-nested style of defining modules, it should through another type of errors NameError.
3 - The logs that provided me with is branches_per_file.rb:17:in start': undefined method []' the line 17. This type of error is a result of totally empty ruby file which it's coverage report return an empty hash {}, I will fix it.
4 - Are you using track_file configuration on simplecov? could you please try to require the file that you have and with absolute path of it in the irb console? (This will help me to better understand the issue)
5- BranchesPerFile concern the files that are missing any coverage report (not covered by applied tests), so it will return just the branches with zero coverage result.
As a part of the solution on this case, is to write something similar to LinesClassifier that will parse the lines and give the report of branches, but this will make this PR very complicated to review. Better to have a simple solution that will return empty hash for now, and make a new PR with the new functionality of text parsing after this one will be accepted.
I appreciate your interest in this PR, hope our collaboration will make SimpleCov have this feature soon.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1:

require is called on the absolute file path so it's safe

I do not quite understand what the file path has to do with safety of the file. My point was that with this change there is an unexpected eager loading on the execution of the test suite

3: This error appears also in a different case: execution of only a specified test or a specified directory

Example:

rspec spec/models

Randomized with seed 24924
..................................................

Finished in 1.89 seconds (files took 2.47 seconds to load)
50 examples, 0 failures

Randomized with seed 24924

Traceback (most recent call last):
	11: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/defaults.rb:27:in `block in <top (required)>'
	10: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:182:in `run_exit_tasks!'
	 9: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/configuration.rb:191:in `block in at_exit'
	 8: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:70:in `result'
	 7: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:310:in `process_coverage_result'
	 6: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:299:in `result_with_not_loaded_files'
	 5: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:263:in `add_not_loaded_files'
	 4: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:263:in `each'
	 3: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:265:in `block in add_not_loaded_files'
	 2: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/run_file_coverage.rb:9:in `start'
	 1: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/run_file_coverage.rb:26:in `call'
/Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/branches_per_file.rb:17:in `start': undefined method `[]' for nil:NilClass (NoMethodError)

4: No, am not using track_file

Sorry, I don't have time for this at the day-to-day work anymore; so I cannot get more into the details what is wrong there.

However, I made some of the problematic examples that came to my mind in my (much simple) pet project.

Have a look at https://github.com/klyonrad/lazybar/commits/simplecov-branch-cov

the full rspec run actually works fine with the edge cases that I wrote but the the execution of a directory or a single file breaks - with a different error then what I copied in my previous example:

rspec spec/models/cocktail_recipe_spec.rb

Randomized with seed 20614
..................

Top 2 slowest examples (1.15 seconds, 55.6% of total time):
  CocktailRecipe validations is not valid with only one ingredient
    1.05 seconds ./spec/models/cocktail_recipe_spec.rb:21
  CocktailRecipe methods about liking can show the users that like it
    0.09874 seconds ./spec/models/cocktail_recipe_spec.rb:70

Finished in 2.07 seconds (files took 3.19 seconds to load)
18 examples, 0 failures

Randomized with seed 20614

Traceback (most recent call last):
	13: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/defaults.rb:27:in `block in <top (required)>'
	12: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:182:in `run_exit_tasks!'
	11: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/configuration.rb:191:in `block in at_exit'
	10: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:70:in `result'
	 9: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:310:in `process_coverage_result'
	 8: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:299:in `result_with_not_loaded_files'
	 7: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:263:in `add_not_loaded_files'
	 6: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:263:in `each'
	 5: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov.rb:265:in `block in add_not_loaded_files'
	 4: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/run_file_coverage.rb:9:in `start'
	 3: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/run_file_coverage.rb:26:in `call'
	 2: from /Users/luka/.rvm/gems/ruby-2.5.3/bundler/gems/simplecov-52827cb42b93/lib/simplecov/branches_per_file.rb:16:in `start'
	 1: from /Users/luka/development/lazy_bar/app/models/never_tested.rb:1:in `<top (required)>'
/Users/luka/development/lazy_bar/app/models/never_tested.rb:2:in `<class:NeverTested>': uninitialized constant NeverTested::NotExistingNamespace (NameError)

As I said: even though it would be a good thing to catch all these type of stupid programmer errors; I think an autoloading of all code is a bit unexpected behaviour

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to agree with @klyonrad (thanks for chiming in!) - people might have some ruby files lying around that do stuff like delete folders, or run production tasks, code base refactoring - we shouldn't just load and execute those. I think it's fine to just show unloaded files as entirely uncovered or whatever else.

If we really needed the branch structure I think we should see if we could get access to the parser that generates it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PragTob see my comment above if you still not agree I will remove this class, and add it to my TODO list for next PR :)

@stepozer stepozer Aug 21, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@som4ik I suggest remove this class, because we tested your PR and found that took 10-15 seconds for our big legacy project... After remove this class everything working fast.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stepozer Yep, that's what exactly I will do. We already agreed to do it at the comments above.

@Marc3001

Marc3001 commented Apr 23, 2019 •

Copy link
Copy Markdown

Is anyone available to review this PR ? We will be really grateful to see this feature in simplecov on our ruby2.5 projects ;)

@jeremyevans

Copy link
Copy Markdown

I've wanted to use support branch coverage for a while in my projects, so I tried out this pull request (and the corresponding one in simplecov-html). Here is what I found, and they may well be issues with branch support in stdlib coverage and not issues with this pull request:

  • In general, this works well and adds very useful information on branch coverage. I found numerous places with missing branch coverage in projects I maintain that have 100% line coverage.
  • Some lines that should be covered and have line coverage are missing branch coverage. For example a line with %w'foo bar'.each do |x| or self::Constant.class_eval do will be marked as line covered but not branch covered ([0, '-']). Maybe lines that have line coverage but only a single branch with no branch coverage should be considered covered?
  • Some empty lines are reported with missed branch coverage with [0, "+"]. Maybe if the line isn't hit at all, we shouldn't report branch coverage on it? Lines marked this way are not handled properly in the html view, since the end up with a height of only a couple pixels.
  • Some starting comment lines with # :nocov: are marked as skipped and still marked red with missing branch coverage with [0, '-']. Additionally, some other lines inside nocov blocks are marked as skipped with missing branch coverage (when/else in case). If a line is skipped, branch coverage should be skipped for that line.

I would definitely like to see branch support in simplecov. Hopefully the issues can be addressed and this can be merged.

@PragTob

PragTob commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

Hi everyone!

Thanks @som4ik for all the work on this, everyone for their encouragements, testing this out and reporting problems 🎉

It seems like some bugs still might need to be squashed here before we can release it. I'm slowly getting back to trying to maintain simplecov and this is of course a huge piece of work. I'll aim to review and determine what might/might not need doing before we can land it and maybe release it as an "alpha" feature or what not.

Please bear with me for a little while longer, this is a huge PR.

@som4ik: Which one is the preferred PR to review? This here or #692 ? I'm a bit confused because #692 says "the first time I developed this" but points to this PR which was made after #692 ? Which one do you prefer to get in/which one should I review/work on?

Also bunny for your efforts:

IMG_20180805_081900

Thanks,
Tobi

@som4ik

som4ik commented Jun 26, 2019

Copy link
Copy Markdown
Contributor Author

@PragTob Thanks, I accepted the cute bunny 😃
Frankly speaking, I'd rather you had a look at the current PR #694 , I know it's quite big but it's structured way better and will support us in feature to expand and improve the functionality.
Looking forward to your comments.

@PragTob

PragTob commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

I see, thanks for the look. Aim is to take a look in the coming days, maybe even today. :)

@PragTob PragTob left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋

Hi there and thanks again for your awesome work 🎉 🎉 🎉

I love a lot of the changes you did (Combiners and other places where you broke up the responsibilities) 👍

IMG_20180818_152929

Sorry for the myriad of comments, I'm a very thorough reviewer as you can see (although my concentration faded a bit). I want to make sure that I understand everything, as well I'll end up maintaining it.

On a more general level some things where I think our style just differs:

  • you created some classes (combiners for instance iirc) that just transform some data, I don't think a full class with instance variables is necessary here - I think it's better to just have module method that explicitly passes on parameters (I commented this in places but I think it applies to more)
  • we need to find a good setting/configuration name 😁
  • the eager require for some of the files should go as we could execute random dangerous code which is definitely not a side effect someone expects from running simplecov :)
  • I think some of the docs that basically state the method name aren't necessary, but I can remove those myself :)

Again, this is very good work I probably wouldn't have started working on this if it wasn't for your great contribution 👌

Also, if you don't want to change something that I mentioned that's fine, it's my fault that this has been lying around for so long. Just tell me and I'll fix it myself before merging, or afterwards.

Still this is a big change, so has to be treated with carefulness. Still I want this PR to go in relatively soon as it has been lying around for some time and merge conflicts will only get bigger.

My plan is roughly this:

  • determine what's best, first merging this or #700
  • do a release without those changes (so still old school SimpleCov)
  • merge both those PRs
  • add more testing specifically test branch coverage through cucumber tests etc (please do not add this to this PR, it's big enough as is and I wanna get it merged)
  • do some alpha or beta release with the new stuff so people can easily try it out and help us find bugs
  • fix bugs ;P
  • do a full release but still advertise the feature as beta/use with caution/report all them bugs :)

Hope that sounds good to you, and once again thanks for all the great work 💚

Comment thread README.md

```ruby
SimpleCov.start do
use_branchable_report true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the naming. I'd expect something like: branch_coverage or use_branch_coverage but I don't yet understand all of this anyway 😁

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we need a coverage setting that is set to :lines or :branches or :methods or :all or what not :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a perfect idea. I will apply it and add validation on it.

Comment thread lib/simplecov.rb Outdated
#
# @return [Hash]
#
def process_coverage_result

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small and maybe personal thing, but when it comes to order of methods I like to go high level to detail, so in this case I'd first define process_coverage_result and then the methods it calls in the order that it calls them. That way it's easier to follow along because I can read the methods in the context that they're used in :)

Comment thread lib/simplecov/branches_per_file.rb Outdated
# Doing something similar to https://ruby-doc.org/stdlib-2.5.3/libdoc/coverage/rdoc/Coverage.html can throw an error.
# Errors can be related to Constants, modules are included/extended inside the file but not yet loaded or even exist.
# It even can be a programmer's error.
module BranchesPerFile

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like "BranchDateForMissingFile" or something as the module/class name? The original name had me a bit confused.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we might not need/want this see the comment chain with @klyonrad just loading ruby files seems potentially harmful to gem users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, somehow I agree with @klyonrad, but on the other hand, this mechanism will help us to determine the branches in the missed files, which I think is nice to have.
After the @klyonrad comment, I added a rescue to print out the error message that problematic file raises, don't you agree with this approach? it would make these modifications not harmful at all

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I'm not as worried about the errors (which we can and are catching), but more what random ruby scripts lying around might do. Imagine the following scenario:

  1. I wrote ruby script to that sshs into production and runs an expensive operation there, I was carless and included all the credentials. I just dropped it somewhere in my app folder
  2. I run my tests
  3. The file naturally isn't covered but gets picked up through track files or what not
  4. this file requires the file which causes all the ruby code to execute 😱
  5. Suddenly production is on fire because of that expensive operation and nobody has any idea why 🔥

I admit it's a worst case scenario. I'm certainly known to have little ruby scripts lying around that do something. They should never be executed as a side effect of a test suite run and to the best of my understanding this makes that possible. We should avoid that at all costs imo.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not like the ultra worst case scenario that you are painting here but at my previous job we literally had a file that upon loading was reading stuff from the database, storing into some kind of module/class variable and suddenly the information was shared between the different tests.

The lesson is: require does things 😉

Comment thread lib/simplecov/branches_per_file.rb Outdated
def self.start(source_file_path)
return {} unless SimpleCov.branchable_report
Coverage.start(:all)
require source_file_path

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to agree with @klyonrad (thanks for chiming in!) - people might have some ruby files lying around that do stuff like delete folders, or run production tasks, code base refactoring - we shouldn't just load and execute those. I think it's fine to just show unloaded files as entirely uncovered or whatever else.

If we really needed the branch structure I think we should see if we could get access to the parser that generates it.

Comment thread lib/simplecov.rb
#
def start_coverage_measurment
if branchable_report
Coverage.start(:all)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that API documented somewhere? https://ruby-doc.org/stdlib-2.6.3/libdoc/coverage/rdoc/Coverage.html#method-c-start doesn't seem to have anything or am I looking in the wrong place 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I read both of those, but having no official docs sucks. Might wanna PR against ruby. We could include at least one of those links at docs for our future selves :)

Comment thread spec/run_results_combiner_spec.rb Outdated
end

it "has proper results for three.rb" do
expect(subject[source_fixture("three.rb")][:lines]).to eq([nil, 3, 7])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just believe you that all of these are correct 👼

Comment thread spec/source_file_branch_spec.rb Outdated

if SimpleCov.usable?
describe SimpleCov::SourceFile::Branch do
let(:results) do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this results confuses me a bit, I think it's only used in the other lets to do result[index] - coudln't we just inline them then? Maybe I just don't understand its purpose 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will modify it.

Comment thread spec/source_file_branch_spec.rb Outdated
end

it "Is a root branch" do
expect(positive_sub_branch.root?).to be false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description says root branch, test says no 🤷‍♂️

Comment thread spec/source_file_branch_spec.rb Outdated
expect(positive_sub_branch.badge).to eq "+"
end

it "Has badge - of negative branch" do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusing to read as the tests directly contradict each other (has negative badge, and has positive badge) - I think it might be improved by introducing describes that focus on root/positive/negative branch respectively. What do you think?

Comment thread spec/source_file_branch_spec.rb Outdated
expect(negative_sub_branch.sub_branch?).to be true
end

it "Has badge + of positive branch" do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think usually these start lower case :)

@PragTob

PragTob commented Jul 1, 2019

Copy link
Copy Markdown
Collaborator

Looking at #700 it seems to me that most of the relevant changes are in spec_files and that's basically an indentation change I think/hope that your merge conflicts against #700 should be relatively easy to handle. I'm tempted to merge it first, which would be bad for you but I think I can do a PR on your branch to resolve them. What do you think @som4ik ?

@PragTob PragTob mentioned this pull request Jul 1, 2019
@som4ik

som4ik commented Jul 2, 2019 •

Copy link
Copy Markdown
Contributor Author

@PragTob Yep, I agree, #700 should be merged first.

@PragTob

PragTob commented Jul 2, 2019

Copy link
Copy Markdown
Collaborator

I'll get straight on that. Thanks for checking out the review and chiming in on this! 🙏

@som4ik

som4ik commented Jul 2, 2019

Copy link
Copy Markdown
Contributor Author

You are welcome, I have rolled over most of the comments, will continue reviewing them this evening or next two days. I will push the updates to this branch according to the code review notices ASAP.

@PragTob

PragTob commented Jul 2, 2019

Copy link
Copy Markdown
Collaborator

@som4ik thank you! Don't stress out about it though, you see how long it took me to get to this 😅 We're all doing this in our free time, take time if you need it. Also feel free to tell me if you disagree with my points :)

@PragTob PragTob mentioned this pull request Jul 2, 2019
@PragTob

PragTob commented Jul 2, 2019

Copy link
Copy Markdown
Collaborator

Also, all the drop rubies support of ruby xx PRs have been merged so this is ready to be rebased/have merge conflicts resolved (hopefully). As expected the merge conflicts are in not tooo many files.

If tests fail on JRuby on travis, travis has wird problems installing rvm these days it seems 🤷‍♂️

@stepozer

Copy link
Copy Markdown

@som4ik also on our project we found that this PR working incorrect for parallel tests (gem parallel_tests)... Right now we trying to find where an issue, will let you know.

@stepozer

Copy link
Copy Markdown

Also in HTML report I don't see new markers for branch coverage... I set up

SimpleCov.start('rails') { use_branchable_report true }

what I am doing wrong?

@jeremyevans

Copy link
Copy Markdown

@stepozer You probably need a version of simplecov-html installed with this pull request applied: simplecov-ruby/simplecov-html#64

Comment thread lib/simplecov/source_file.rb Outdated
def missed_lines
@missed_lines ||= lines.select(&:missed?)
end
def branches_coverage_precent

@tycooon tycooon Sep 5, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be branches_coverage_percent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! Just in case, some of these methods are used in the default formatter and needs to be changed in both places.

# @return [Array]
#
def covered_branches
@coverd_branches ||= root_branches.flat_map do |root_branch|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's better to name this ivar @covered_branches so that it matches the method name.

@PragTob

PragTob commented Dec 3, 2019

Copy link
Copy Markdown
Collaborator

@stepozer thank you that is really helpful! 🎉 🚀 💚

IMG_20180622_182841-ANIMATION

@som4ik

som4ik commented Dec 3, 2019

Copy link
Copy Markdown
Contributor Author

@tycooon Sorry for the late delay! soon I will push an update for this PR!
@stepozer Thank you 👍 very useful!

@PragTob

PragTob commented Dec 3, 2019

Copy link
Copy Markdown
Collaborator

@som4ik don't feel pressured to update the PR, as I said I was planning on updating it myself. I'll leave a comment here before I do though (and have to do it on another branch either way). If you get to upgrading it it's of course also welcome - it's a community effort after all :)

@tycooon

tycooon commented Dec 3, 2019 •

Copy link
Copy Markdown

@tycooon is your fork a fork of this PR?

Yep, although I changed some stuff :)

@som4ik
som4ik force-pushed the feature/branches-coverage-support branch from 4413153 to a6987d1 Compare December 3, 2019 23:37
@som4ik

som4ik commented Dec 4, 2019

Copy link
Copy Markdown
Contributor Author

@PragTob I have done:

  • Squash for all my prev commits
  • Resolved the conflicts with the latest update master branch
  • Removed the issue related to branches_per_file.rb (removed require totally)
  • Fixed code review notices
  • Added suggested the ability to handle parallel tests by @stepozer
    (@stepozer I tested it with parallel_tests gem it seems everything ok, if you could verify it I will appreciate it :) )

@tycooon I reviewed the changes/upgrades that you have done, I like it, good job! 👍
Do you have any updates for the default simplecov-html formatter that covers Methods coverage reports? :)
As you already added the methods combiner, I didn't change the name of the config input use_branchable_report or changed it's functionality as we discussed before, I thought it would be nice to be done in your updates or PR, what do you think?
cute-bunny-gif

@stepozer

stepozer commented Dec 4, 2019

Copy link
Copy Markdown

@som4ik I will try update code on our project. I'll let you know how your new code works

@tycooon

tycooon commented Dec 4, 2019

Copy link
Copy Markdown

@tycooon I reviewed the changes/upgrades that you have done, I like it, good job! 👍
Do you have any updates for the default simplecov-html formatter that covers Methods coverage reports? :)

Nope, was going to add that later.

As you already added the methods combiner, I didn't change the name of the config input use_branchable_report or changed it's functionality as we discussed before, I thought it would be nice to be done in your updates or PR, what do you think?

You are proposing that I add method coverage support in a later PR, am I correct? In that case we will definitely need to rename that method, so maybe it's better to rename it now, so that we don't have to care about the backward compatibility later?

@PragTob

PragTob commented Dec 4, 2019

Copy link
Copy Markdown
Collaborator

@som4ik Thank you so much for all this 🎉 I'm currently runnign a bunch of errands, but will re-review some time later today.

@tycooon I think getting this merged is a bit more important (tiny bit) than the right configuration option and method coverage or what not to boot with. I'm fine merging this now but waiting to cut a release until we changed the naming to be better. I still like coverage or coverage_type with a symbol, I was gonna look up in the literature how they usually differentiate the different types of coverage/call them.

@som4ik your recent email address doesn't seem to be connected to your github account, just fyi if you care about these kinds of things.

Thanks everyone!

IMG_20190215_122642_Bokeh

@PragTob PragTob left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thank you!

Some of the code review comments aren't addressed but that's fine, I/we can address them later. I'm fine with having a slightly wonky state at master and a couple of pre/rc releases for this. For now I think it's more important to get this merged to not create more merge conflicts and so that we can parallelize the work on this and do it in smaller better reviewable chunks :)

I highlighted a couple of questions again that I'd like to know the answers to before merging this :)

IMG_20190127_150119

Comment thread lib/simplecov.rb
if branchable_report
Coverage.start(:all)
else
Coverage.start

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self mental note, I think we can't since not all ruby versions support that argument

Comment thread lib/simplecov/source_file.rb Outdated
#
def positive?
return true if type == :when
1 + root_id.to_i == id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlighting this once more cos I still got no idea what's happening here 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For if, else conditions:
coverage returns matrices ex: [:if, 0,..] => {[:then, 1,..], [:else, 2,..]},
where positive branch always has Id equals to root branch Id incremented by 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add more comments to this method

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessed as much but wanted confirmation. Thank you! I guess it also works for unless which then is the question should that still be called positive but I think so. Thank you!

Comment thread lib/simplecov/source_file.rb Outdated
@missed_lines ||= lines.select(&:missed?)
end
def branches_coverage_percent
return 100.0 if no_branches? && no_lines?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not sure why we need to check no_lines? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, It should be removed, I will do it!

@stepozer

stepozer commented Dec 4, 2019

Copy link
Copy Markdown

Good job. Will nice if you release this and I will update gem and check.

@som4ik

som4ik commented Dec 5, 2019

Copy link
Copy Markdown
Contributor Author

@PragTob I added more comments in some places and also done small changes that give significant upgrade for the report matrics.
BEFORE:
befor-final
AFTER:
after-final
Hope CI will pass 🙏 ✊ 😉

@som4ik
som4ik force-pushed the feature/branches-coverage-support branch from 128f3aa to 1271233 Compare December 5, 2019 09:38
@PragTob

PragTob commented Dec 5, 2019

Copy link
Copy Markdown
Collaborator

@som4ik that looks nice! I think we could work on the presentation a bit but in a separate step :)

That script looks like it gives a nice overview of branch coverage cases - I think it might be a good to include it in the repo in an integration test - I could type it all from the image but if you have, I'd appreciate it :)

@PragTob PragTob left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bunnies

@PragTob

PragTob commented Dec 5, 2019

Copy link
Copy Markdown
Collaborator

Ok, let's do this 🚀

@PragTob
PragTob merged commit e789605 into simplecov-ruby:master Dec 5, 2019
@som4ik

som4ik commented Dec 5, 2019

Copy link
Copy Markdown
Contributor Author
x = 1
x.eql?(4) ? "4" : x

puts x unless x.eql?(5)

unless x == 5
  puts "Ola.."
end

unless x != 5
  puts "Ola.."
end

unless x != 5
  puts "Ola.."
else
  puts "text"
end

puts x if x.eql?(5)
if x != 5
  puts "Ola.."
end

if x == 5
  puts "Ola.."
end

if x != 5
  puts "Ola.."
else
  puts "text"
end
x = 4
if x == 1
  puts x

  puts x
  puts x
elsif x == 4
  puts x
  puts x
  puts x
  puts x
elsif x == 14
  puts x

  puts x
else
  puts x
end

if x == 1
  puts x
elsif x == 4
  puts x
elsif x == 14
  puts x
else
  puts x
end

@PragTob PragTob mentioned this pull request Dec 5, 2019
16 of 17 tasks
@stepozer

stepozer commented Dec 5, 2019

Copy link
Copy Markdown

We updated to new version, seems to be working. Will let you now if something will be wrong.

@PragTob

PragTob commented Dec 5, 2019

Copy link
Copy Markdown
Collaborator

Remaining work is tracked in #781

@PragTob

PragTob commented Dec 5, 2019

Copy link
Copy Markdown
Collaborator

@stepozer thank you very much! 🎉

PragTob added a commit that referenced this pull request Jan 3, 2020
PragTob added a commit that referenced this pull request Jan 3, 2020
@hedgesky

Copy link
Copy Markdown

So cool this got merged finally, thanks a lot @som4ik, @PragTob!

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

Successfully merging this pull request may close these issues.

10 participants