simplecov-ruby / simplecov

Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
MIT License
4.75k stars 551 forks source link

resultset.json documentation? #1021

Closed will closed 2 years ago

will commented 2 years ago

I'm toying with the idea of adding a way to see coverage in the neovim gutter instead of having to open up the html report. I figure the best way would be to read the json file.

It seems like the array of lines is how many times that line is hit, and so anything that is 0 would be not covered. I don’t understand the null values though. Not tracked at all maybe?

The branches though is a big mystery to me:

        "branches": {
          "[:unless, 0, 65, 4, 65, 46]": {
            "[:else, 1, 65, 4, 65, 46]": 1,
            "[:then, 2, 65, 4, 65, 14]": 0
          },
          "[:\"&.\", 3, 71, 28, 71, 52]": {
            "[:then, 4, 71, 28, 71, 52]": 1,
            "[:else, 5, 71, 28, 71, 52]": 0
          },
          "[:unless, 6, 71, 4, 71, 53]": {
            "[:else, 7, 71, 4, 71, 53]": 1,
            "[:then, 8, 71, 4, 71, 14]": 0
          },

Can you please shed some light on what all these numbers mean? I've poked around the souce code a bit, but couldn't figure it out, so hoping it's not too noisy opening this issue to ask.

colszowka commented 2 years ago

Hi @will 👋

These values should be straight from the ruby Coverage module, and are documented there: https://devdocs.io/ruby~3.1/coverage

will commented 2 years ago

Thank you! I didn’t think of checking in the ruby side hah

will commented 2 years ago

@colszowka thanks again! it's so handy to know exactly what conditional is missing in coverage when there can be more than one conditional per line

image
PragTob commented 2 years ago

@will just as additional information, resultset.json is not part of the public API and should not be relied on. Furthermore, it is missing certain features of SimpleCov (filtering, adding files etc is done post resultset.json). We now include a JSON formatter. I recommend using it instead.

will commented 2 years ago

@PragTob I poked a bit at that, but it seems like it doesn't work with rpsec 3?

Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected /Users/will/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/formatters/deprecation_formatter.rb:186:in 'puts': The SimpleCovJSONFormatter formatter uses the deprecated formatter interface not supported directly by RSpec 3. To continue to use this formatter you must install the rspec-legacy_formatters gem, which provides support for legacy formatters or upgrade the formatter to a compatible version. Formatter added at: /Users/will/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/exe/rspec:4:in `<top (required)>' (RSpec::Core::DeprecationError)

I could do what it says and try that legacy formatters gem, but the name makes me think that is not a long term solution either