Class: Mutant::ContextMap::Loader Private
- Inherits:
-
Object
- Object
- Mutant::ContextMap::Loader
- 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.
<<~'MESSAGE' Test selection strategy `context_map` needs a per test coverage recording, but none exists at: %<path>s Record one with simplecov 1.2.0 or newer: # spec/spec_helper.rb, or test/test_helper.rb require 'simplecov' SimpleCov.start do track_tests end Run the test suite once to write the recording, then re-run mutant. The default HTML formatter writes `coverage.json` beside its report, as does `SimpleCov::Formatter::JSONFormatter`. Pass `--selection-path DIRECTORY` if the recording is not under ./coverage. MESSAGE
- 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.
<<~'MESSAGE' Unable to read the coverage recording at: %<path>s %<error>s MESSAGE
- 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.
<<~'MESSAGE' The coverage recording at: %<path>s is not a simplecov report mutant can read: %<error>s Delete it and record it again with simplecov 1.2.0 or newer. MESSAGE
- 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.
<<~'MESSAGE' The coverage recording at: %<path>s uses report schema version %<schema>s, which mutant does not understand. Upgrade mutant, or record again with a simplecov that writes schema version 1. MESSAGE
- 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.
<<~'MESSAGE' The coverage recording at: %<path>s has no per test data, so mutant cannot tell which tests cover a subject. Enable tracking with simplecov 1.2.0 or newer: SimpleCov.start do track_tests end Run the test suite once with tracking enabled, then re-run mutant. MESSAGE
- 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
contextssection 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
-
.call(path:, world:) ⇒ Either<String, ContextMap>
private
Load the recording under path.
Instance Method Summary collapse
-
#call ⇒ Either<String, ContextMap>
private
Load the recording.
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
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
#call ⇒ 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
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 |