Skip to main content

Module mutation

Module mutation 

Source
Expand description

The static half of mutation testing: mutant selection, test mapping, pruning and ranking. The static half of mutation testing: select, map, prune and rank mutants.

The plan reads only facts that the dead-code analysis already has: the module graph with its test reachability (including the vi.mock replacement masks), the dead-code results, the function complexity of each module, and the captured security sink sites. It reads the source text of each selected file one time to instrument it, and it holds the instrumented code in memory. It never writes a file and never runs user code.

Each mutant gets one disposition:

  • planned: a test file reaches the file, and no static rule prunes the mutant. The runner executes these mutants in rank order.
  • pending: a planned mutant after the max_mutants limit.
  • no-coverage: no test file reaches the file in the graph. A test that replaces the module with vi.mock does not reach it.
  • pruned: a static rule removes the mutant (see PruneReason).

Structs§

DiffIndex
Parsed, command-neutral index of files and added lines in a unified diff.
FrameworkConfigExports
Framework config exports, by root-relative file path.
FunctionFacts
The facts of the function that contains a mutant.
FunctionRef
The function that contains a mutant.
Mutant
One mutant.
MutantId
The stable identity of a mutant: 16 lowercase hex digits.
MutantTestReach
How tests reach the code of one mutant, from the module graph.
MutationPlan
The static mutation plan.
MutationPlanCounts
The number of mutants for each disposition.
MutationPlanInputs
The analysis facts that a plan reads.
MutationPlanRequest
What to plan.
PlannedFile
One file that the runner loads in its instrumented form.
PlannedMutant
One mutant of the plan.
PruneCounts
The number of pruned mutants for each reason.
SkippedFile
A selected file that the plan did not instrument.

Enums§

MutantDisposition
The status of a mutant in a plan.
MutationError
An error from instrument.
MutationPlanError
An error from plan_mutations_for_session.
MutationScope
The files and lines that a plan mutates.
Operator
One mutation operator.
PruneReason
Why a static rule removes a mutant.
SkipReason
Why the plan did not instrument a selected file.
SourceKind
The language of a source text.

Constants§

RESERVED_PREFIX
The name prefix that the instrumentation reserves.
RUNNER_CONFIG_MODULES
The runner config modules at the project root. Each test run loads them, so they and the files that they reach through static imports are in MutationPlan::support_files.

Functions§

instrument_source
Instruments a source file of any layout that fallow mutation supports: JavaScript, TypeScript, and the script blocks of Vue, Svelte and Astro components. Returns None for another file type.
is_component_file
True when path is a Vue, Svelte or Astro component file, whose code is in script blocks. A Svelte module file (.svelte.ts) is not a component file.
plan_mutations
Builds the mutation plan from the facts of one analysis.
plan_mutations_for_session
Runs the dead-code analysis of session with complexity and the graph, then builds the mutation plan.
plan_mutations_for_session_with
Like plan_mutations_for_session, but skip_components reads the first plan and decides if the component files leave the plan. The test runner can depend on the test files of the plan, so the caller decides after the first plan. When the first plan has a component mutant and skip_components returns true, the plan is built again from the same analysis with MutationPlanRequest::skip_component_files set.