Skip to content

minimum_coverage raises KeyError with oneshot_line coverage #1170

@willnet

Description

@willnet

After oneshot_line coverage support was added in 522dc7d, minimum_coverage appears to crash with a KeyError when oneshot_line is used as the primary coverage.

It looks like minimum_coverage ends up checking :oneshot_line, while coverage_statistics only exposes :line, :branch, and :method.

Reproduction

Run this single-file repro script:

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"
  gem "simplecov", github: "simplecov-ruby/simplecov", branch: "main"
end

require "tmpdir"
require "fileutils"

dir = Dir.mktmpdir("simplecov-oneshot-repro")
at_exit { FileUtils.remove_entry(dir) if Dir.exist?(dir) }

source_file = File.join(dir, "sample.rb")

File.write(source_file, <<~RUBY)
  def greet(name)
    return "hi" if name

    "hello"
  end

  greet("world")
RUBY

require "simplecov"

SimpleCov.start do
  enable_coverage :oneshot_line
  primary_coverage :oneshot_line
  minimum_coverage 100
end

load source_file

Expected behavior

minimum_coverage should work with oneshot_line coverage, or at least fail gracefully with a clear error.

Actual behavior

It raises:

'Hash#fetch': key not found: :oneshot_line (KeyError)

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