Skip to content

Code Coverage #850

Description

@robinetmiller

As seen in #849, there are segments of the JSON codebase that are lacking test coverage. Since this is a core Ruby library, it would be befitting to have a robust test suite.

Personally, I tend to use Simplecov for projects, but in the case of JSON, that may be difficult/impossible due to the require sequencing. I've spent some time putting together a rudimentary prototype coverage using Ruby's Coverage module directly, so something should be possible, even if it is a grotty txt file. An ideal system would be simple to view and integrate with other tools, though, so I'm tempted to try and go further.

To that end, I've got a few questions:

  • Is there a preference for coverage tool or output format?
  • Is there any policy/preference regarding adding development dependencies?
  • Are there any sneaky pitfalls that I'm missing? (eg. someone has tried this before and it went real bad)

The only pitfalls I can think of so far are:

  1. JSON is a core library, so getting the coverage tool to notice it properly with any dependencies possibly invoking it early might be, uh, fun
  2. There are segments of the test suite that have guards on them (eg. ENV["JSON_COMPACT"])
  3. This wouldn't provide any coverage reports for the non-Ruby segments of code, of course, but any coverage is better than no coverage.

Activity

  1. byroot commented on Sep 2, 2025

    @byroot
    Member

    I'm going to be quite busy all this week, but the quick pointer I can give you is that json is a default gem, so I'd start by looking at the other default gems to see if any of them uses a coverage tool: https://github.com/ruby/ruby/blob/f9bffff3d4b45d4c6fed42f13d556c520f3cfd67/tool/sync_default_gems.rb

    The json test suite is synced inside ruby itself, so it's indeed important to consider that, but we can have a conditional to only perform coverage when running standalone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions