Juggernaut.View (Juggernaut v0.4.0)

Copy Markdown View Source

The output formats of a run (design notes §5, §11) and the pieces they share.

Every view is a pure function of a Juggernaut.Run (and, for the live view, of the run's events) plus options; none reads engine internals, the clock or the filesystem. The caller supplies what a view cannot know from the run: the configured thresholds, how timeouts are scored, the source text of the mutated files and the test files that exist.

render/3 picks a format by its --format name:

Options

  • :thresholds (keyword/0) - The configured thresholds (.juggernaut.exs thresholds). The default value is [].

    • :core - Minimum score of core mutants. The default value is 100.

    • :changed - Minimum score elsewhere. The default value is 80.

    • :per - Per file or per run. The default value is :file.

  • :timeouts - How a timeout kill is scored; :survived lists it with the survivors. The default value is :killed.

  • :page (pos_integer/0) - Page of survivors to show. The default value is 1.

  • :per_page (pos_integer/0) - Survivors per page. The default value is 20.

  • :sources (map of String.t/0 keys and String.t/0 values) - Original source text by file path, for excerpts and the MTE export. The default value is %{}.

  • :test_files (list of String.t/0) - Test files that exist, for the suggested test file. The default value is [].

  • :ansi (boolean/0) - Colour the human output. The default value is false.

  • :report (boolean/0) - Stream: end with a report event holding the agent document. The default value is false.

  • :ci (boolean/0) - MTE system.ci. The default value is false.

Summary

Types

Where a page of survivors sits in the whole list.

A listed mutant with its result.

How a listed mutant is shown: survived, not covered, or a timeout scored as survived.

Functions

Rows of cells as left-aligned text columns, each padded to its widest cell.

The conventional test file of a source file: lib/a/b.ex → test/a/b_test.exs, and in an umbrella apps/x/lib/a.ex → apps/x/test/a_test.exs. The first lib segment becomes test; a path without one has its first segment replaced (gates/x.ex → test/x_test.exs).

The files of run that hold core mutants.

n followed by the singular or plural noun.

A duration for people: 850 ms, 3.1 s, 2 min 05 s.

The source lines around a mutant: from the nearest def/defp/defmacro(p) head at most 20 lines above it (else 3 lines above) to 3 lines below. nil when the file's source was not given.

A mutant's family for people: relational:>=, or the operator alone.

The mutant of run named by ref (design notes §3): its full short id, its hash part, or a unique prefix of 4 or more hex digits of the hash. An unknown or ambiguous ref is a usage error (exit 2); an ambiguous one lists the candidates.

The hash part of a short id (Grant.check/2:relational:4be1c09 → 4be1c09).

The mutants killed only by integration tests (Juggernaut.Result.integration_only?/1: every unit test of their selection passed first), core first, then by file, line and id. They count as killed; a timeout kill scored as survived is a survivor instead (survivors/2), so it is not listed here.

The number of the last page of page's list; 0 when the list is empty.

The command that shows the page after page of run_id's survivors, in format (nil for human output). It always names --per-page, so following it shows the next items whatever page size the current output used.

Validates view options, a keyword list or a map (such as one this returned), and fills the defaults. Raises ArgumentError when invalid.

One page of items and where it sits. A page past the end is empty.

The command that shows page number of run_id's survivors at per_page a page, in format (nil for human output).

A percentage for people: 97.4%, or - when nothing was scored.

The run's phases as {name, duration_ms}, in run order.

Renders a finished run in format (a --format name) as iodata.

The result of mutant in run; a mutant without one never ran (:pending).

The reuse note: how many results were reused and the run time recorded for them. Time saved is only ever reported from these recorded durations, never measured or estimated.

The scope of a run for people: changed vs main (2 files), full, ...

What a selection (Juggernaut.Result.selection/0) runs, for people. The run's own counted reason, when it has one, is the result's reason.

Where a test that kills the mutant belongs: the nearest miss's test file, else the conventional test file (lib/a/b.ex → test/a/b_test.exs) when it exists, else nil.

How a result is listed among the survivors, or nil when it is not a survivor.

The mutants listed as survivors, core first, then by file, line and id: survived and no_coverage results, and timeout kills when timeouts are scored as survived.

The file part of a file:line test id.

The command that re-checks one mutant, in format (nil for human output).

Types

options()

@type options() :: %{
  thresholds: keyword(),
  timeouts: :killed | :survived,
  page: pos_integer(),
  per_page: pos_integer(),
  sources: %{required(String.t()) => String.t()},
  test_files: [String.t()],
  ansi: boolean(),
  report: boolean(),
  ci: boolean()
}

page()

@type page() :: %{
  page: pos_integer(),
  per_page: pos_integer(),
  total: non_neg_integer(),
  more: non_neg_integer()
}

Where a page of survivors sits in the whole list.

survivor()

A listed mutant with its result.

survivor_status()

@type survivor_status() :: :survived | :no_coverage | :timeout

How a listed mutant is shown: survived, not covered, or a timeout scored as survived.

Functions

columns(rows)

@spec columns([[String.t()]]) :: [String.t()]

Rows of cells as left-aligned text columns, each padded to its widest cell.

conventional_test_file(file)

@spec conventional_test_file(String.t()) :: String.t()

The conventional test file of a source file: lib/a/b.ex → test/a/b_test.exs, and in an umbrella apps/x/lib/a.ex → apps/x/test/a_test.exs. The first lib segment becomes test; a path without one has its first segment replaced (gates/x.ex → test/x_test.exs).

core_files(run)

@spec core_files(Juggernaut.Run.t()) :: MapSet.t(String.t())

The files of run that hold core mutants.

count(n, singular, plural)

@spec count(non_neg_integer(), String.t(), String.t()) :: String.t()

n followed by the singular or plural noun.

duration(ms)

@spec duration(non_neg_integer()) :: String.t()

A duration for people: 850 ms, 3.1 s, 2 min 05 s.

excerpt(mutant, sources)

@spec excerpt(Juggernaut.Mutant.t(), %{required(String.t()) => String.t()}) ::
  %{start_line: pos_integer(), lines: [String.t()]} | nil

The source lines around a mutant: from the nearest def/defp/defmacro(p) head at most 20 lines above it (else 3 lines above) to 3 lines below. nil when the file's source was not given.

family(mutant)

@spec family(Juggernaut.Mutant.t()) :: String.t()

A mutant's family for people: relational:>=, or the operator alone.

find_mutant(run, ref)

@spec find_mutant(Juggernaut.Run.t(), String.t()) ::
  {:ok, Juggernaut.Mutant.t()} | {:error, Juggernaut.Error.t()}

The mutant of run named by ref (design notes §3): its full short id, its hash part, or a unique prefix of 4 or more hex digits of the hash. An unknown or ambiguous ref is a usage error (exit 2); an ambiguous one lists the candidates.

hash(mutant_id)

@spec hash(String.t()) :: String.t()

The hash part of a short id (Grant.check/2:relational:4be1c09 → 4be1c09).

integration_only(run, opts)

@spec integration_only(Juggernaut.Run.t(), options()) :: [
  {Juggernaut.Mutant.t(), Juggernaut.Result.t()}
]

The mutants killed only by integration tests (Juggernaut.Result.integration_only?/1: every unit test of their selection passed first), core first, then by file, line and id. They count as killed; a timeout kill scored as survived is a survivor instead (survivors/2), so it is not listed here.

last_page(map)

@spec last_page(page()) :: non_neg_integer()

The number of the last page of page's list; 0 when the list is empty.

next_page_command(run_id, page, format)

@spec next_page_command(String.t(), page(), atom() | nil) :: String.t()

The command that shows the page after page of run_id's survivors, in format (nil for human output). It always names --per-page, so following it shows the next items whatever page size the current output used.

options!(opts)

@spec options!(keyword() | options()) :: options()

Validates view options, a keyword list or a map (such as one this returned), and fills the defaults. Raises ArgumentError when invalid.

page(items, page, per_page)

@spec page([term()], pos_integer(), pos_integer()) :: {[term()], page()}

One page of items and where it sits. A page past the end is empty.

page_command(run_id, number, per_page, format)

@spec page_command(String.t(), pos_integer(), pos_integer(), atom() | nil) ::
  String.t()

The command that shows page number of run_id's survivors at per_page a page, in format (nil for human output).

percent(score)

@spec percent(number() | nil) :: String.t()

A percentage for people: 97.4%, or - when nothing was scored.

phases(run)

@spec phases(Juggernaut.Run.t()) :: [{String.t(), non_neg_integer()}]

The run's phases as {name, duration_ms}, in run order.

render(atom, run, opts)

@spec render(
  :human | :agent | :json | :markdown | :github,
  Juggernaut.Run.t(),
  keyword() | options()
) ::
  iodata()

Renders a finished run in format (a --format name) as iodata.

result(run, mutant)

The result of mutant in run; a mutant without one never ran (:pending).

reused(map)

@spec reused(%{results: non_neg_integer(), recorded_ms: non_neg_integer()}) ::
  String.t() | nil

The reuse note: how many results were reused and the run time recorded for them. Time saved is only ever reported from these recorded durations, never measured or estimated.

scope(run)

@spec scope(Juggernaut.Run.t()) :: String.t()

The scope of a run for people: changed vs main (2 files), full, ...

selection_text(selection)

@spec selection_text(Juggernaut.Result.selection()) :: String.t()

What a selection (Juggernaut.Result.selection/0) runs, for people. The run's own counted reason, when it has one, is the result's reason.

suggested_test_file(mutant, result, test_files)

@spec suggested_test_file(Juggernaut.Mutant.t(), Juggernaut.Result.t(), [String.t()]) ::
  String.t() | nil

Where a test that kills the mutant belongs: the nearest miss's test file, else the conventional test file (lib/a/b.ex → test/a/b_test.exs) when it exists, else nil.

survivor_status(result, arg2)

@spec survivor_status(Juggernaut.Result.t() | nil, :killed | :survived) ::
  survivor_status() | nil

How a result is listed among the survivors, or nil when it is not a survivor.

survivors(run, opts)

@spec survivors(Juggernaut.Run.t(), options()) :: [survivor()]

The mutants listed as survivors, core first, then by file, line and id: survived and no_coverage results, and timeout kills when timeouts are scored as survived.

test_file(test_id)

@spec test_file(String.t()) :: String.t()

The file part of a file:line test id.

verify_command(mutant_id, format)

@spec verify_command(String.t(), atom() | nil) :: String.t()

The command that re-checks one mutant, in format (nil for human output).