Juggernaut.Mutator (Juggernaut v0.4.0)

Copy Markdown View Source

Turns one source file into its mutants (design notes §6, §8, §10.1 step 3).

The file is parsed once with Sourceror. Each function clause is walked (Juggernaut.Mutator.Walk), every enabled operator family is offered each site in one of its positions, and each replacement becomes a Juggernaut.Mutant with a stable key, its location in the original text, the original and replacement text and a unified diff. Then, in order:

  • identical mutants (same key) are made once;
  • a return_value replacement that another family already makes at the same node is dropped, and so is a guard_drop whose guard holds another mutant;
  • ignore comments are applied (Juggernaut.Ignore): an ignored mutant stays, with its directive;
  • in the inner lane, outside core files, one mutant per line is kept: the first by family order, then key (design notes §8.4).

Module-body code runs at compile time and is never mutated; its sites are only counted (compile_time). Mutant ids are the canonical keys until assign_ids/1 gives the run's short ids.

Summary

Functions

Gives mutants (of one run, any files) their short ids (Juggernaut.MutantId).

The default options: every family, the default prefixes, no routing, gate lane.

The mutants of source, the file at file (a path relative to the project root). A file that does not parse is a usage error naming the file and position.

Types

opts()

@type opts() :: %{
  families: [atom()],
  prefixes: [String.t()],
  routing: Juggernaut.Routing.t(),
  lane: :inner | :gate | :release,
  core?: (String.t(), module() -> boolean())
}

result()

@type result() :: %{
  file: String.t(),
  mutants: [Juggernaut.Mutant.t()],
  clauses: [
    %{
      module: module(),
      function: {atom(), arity()},
      clause: non_neg_integer(),
      lines: Range.t()
    }
  ],
  compile_time: non_neg_integer(),
  routes: [Juggernaut.Routing.entry()],
  errors: [map()],
  warnings: [map()]
}

Functions

assign_ids(mutants)

@spec assign_ids([Juggernaut.Mutant.t()]) :: [Juggernaut.Mutant.t()]

Gives mutants (of one run, any files) their short ids (Juggernaut.MutantId).

default_opts()

@spec default_opts() :: opts()

The default options: every family, the default prefixes, no routing, gate lane.

mutate(file, source, opts)

@spec mutate(String.t(), String.t(), opts()) ::
  {:ok, result()} | {:error, Juggernaut.Error.t()}

The mutants of source, the file at file (a path relative to the project root). A file that does not parse is a usage error naming the file and position.