Class: Mutant::ContextMap::Loader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/context_map/loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Reads simplecov's coverage.json into a ContextMap

Every way the read can fail ends in an explanation of how to produce the recording, because the recording is the whole reason the strategy was asked for.

rubocop:disable Metrics/ClassLength

Constant Summary collapse

MISSING_ARTIFACT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"Test selection strategy `context_map` needs a per test coverage recording,\nbut none exists at:\n\n  %<path>s\n\nRecord one with simplecov 1.2.0 or newer:\n\n  # spec/spec_helper.rb, or test/test_helper.rb\n  require 'simplecov'\n  SimpleCov.start do\n    track_tests\n  end\n\nRun the test suite once to write the recording, then re-run mutant. The\ndefault HTML formatter writes `coverage.json` beside its report, as does\n`SimpleCov::Formatter::JSONFormatter`.\n\nPass `--selection-path DIRECTORY` if the recording is not under ./coverage.\n"
UNREADABLE_ARTIFACT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"Unable to read the coverage recording at:\n\n  %<path>s\n\n%<error>s\n"
INVALID_ARTIFACT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"The coverage recording at:\n\n  %<path>s\n\nis not a simplecov report mutant can read:\n\n  %<error>s\n\nDelete it and record it again with simplecov 1.2.0 or newer.\n"
UNKNOWN_SCHEMA =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"The coverage recording at:\n\n  %<path>s\n\nuses report schema version %<schema>s, which mutant does not understand.\nUpgrade mutant, or record again with a simplecov that writes schema\nversion 1.\n"
NO_CONTEXTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"The coverage recording at:\n\n  %<path>s\n\nhas no per test data, so mutant cannot tell which tests cover a subject.\n\nEnable tracking with simplecov 1.2.0 or newer:\n\n  SimpleCov.start do\n    track_tests\n  end\n\nRun the test suite once with tracking enabled, then re-run mutant.\n"
UNKNOWN_CONTEXT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'%<file>s refers to a context the recording does not list'
NOT_DIGITS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'Expected: digits in base %<base>d but got: %<actual>s'
CONTEXT_INDEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Transform::Sequence.new(
  steps: [
    Transform::STRING,
    Transform::Block.capture(:decimal) { |string| parse_digits(string, base: 10, pattern: /\A\d+\z/) }
  ]
)
LINE_BITMAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Transform::Sequence.new(
  steps: [
    Transform::STRING,
    Transform::Block.capture(:hexadecimal) { |string| parse_digits(string, base: 16, pattern: /\A\h+\z/) }
  ]
)
TABLE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Per source file: the index of each test that executed it, and a bitmap of the lines it executed

Transform::Hash::Map.new(key: CONTEXT_INDEX, value: LINE_BITMAP)
FILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The report carries far more than mutant reads, and gains keys between minor schema versions. Each hash below is sliced to the keys mutant names before the strict transform sees it.

A file with no contexts section is one no recorded test executed, and contributes nothing rather than making the recording unreadable.

Transform::Sequence.new(
  steps: [
    Transform::Hash::Slice.new(keys: %w[contexts]),
    Transform::Hash.new(
      optional: [Transform::Hash::Key.new(value: 'contexts', transform: TABLE)],
      required: []
    )
  ]
)
META =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Transform::Sequence.new(
  steps: [
    Transform::Hash::Slice.new(keys: %w[root schema_version]),
    Transform::Hash.new(
      optional: [],
      required: [
        Transform::Hash::Key.new(value: 'root',           transform: Transform::STRING),
        Transform::Hash::Key.new(value: 'schema_version', transform: Transform::STRING)
      ]
    )
  ]
)
COVERAGE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Transform::Hash::Map.new(key: Transform::STRING, value: FILE)
DOCUMENT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Transform::Sequence.new(
  steps: [
    Transform::Hash::Slice.new(keys: %w[contexts coverage meta]),
    Transform::Hash.new(
      optional: [Transform::Hash::Key.new(value: 'contexts', transform: Transform::STRING_ARRAY)],
      required: [
        Transform::Hash::Key.new(value: 'coverage', transform: COVERAGE),
        Transform::Hash::Key.new(value: 'meta',     transform: META)
      ]
    )
  ]
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(path:, world:) ⇒ Either<String, ContextMap>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load the recording under path

Returns:



165
166
167
168
169
# File 'lib/mutant/context_map/loader.rb', line 165

def self.call(path:, world:)
  artifact = path.file? ? path : path.join(ARTIFACT_BASENAME)

  new(artifact:, world:).call
end

Instance Method Details

#callEither<String, ContextMap>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load the recording

Returns:



174
175
176
177
178
179
180
181
# File 'lib/mutant/context_map/loader.rb', line 174

def call
  return error(MISSING_ARTIFACT) unless artifact.file?

  read
    .bind(&method(:parse))
    .bind(&method(:decode))
    .bind(&method(:from_document))
end