harnais_runner v0.1.0 Harnais.Runner.Correr View Source

The correr manages a complete test run with one or more tests (provas).

Each test runner create a correr to manage the run.

See Harnais.Runner for the overview.

Correr State

A correr has the following fields:

KeyAliases
:test_type:type
:test_runner:runner
:test_specs:t, :tests, :specs, :test_specifications
:test_value:v, :value
:test_module:d, :module
:test_namer:n, :namer
:test_mapper:m, :mapper
:test_transform:p, :transform
:test_provas

The default for all fields is the unset value (Plymio.Fontais.Guard.the_unset_value/0).

Correr Field: :test_type

The type of the run (e.g. reduce) derived from the test runner name (e.g. run_tests_reduce_test_value/1)

Correr Field: :test_runner

The default function to run each test. Each :test_type (e.g. reduce) has its own default but can be overridden.

Correr Field: :test_specs

The :test_specs passed to the test_runner.

Correr Field: :test_value

The default value passed as the first argument to the :test_call (see the prova).

Correr Field: :test_module

The name of the default module to use in the :test_call (see the prova).

Correr Field: :test_namer

The default test namer passed to each prova.

Correr Field: :test_mapper

See the explanation here.

Correr Field: :test_transform

See the explanation here.

Correr Field: :test_provas

Each specification in the :test_specs is used to create a prova. The :test_provas holds the list of provas.

Link to this section Summary

Functions

new/1 creates a new instance of the module’s struct and, if the optional opts were given, calls update/2 with the instance and the opts, returning {:ok, instance}, else {:error, error}

new!/1 calls new/1 and, if the result is {:ok, instance} returns the instance

run/1 takes a correr and runs each prova

update/2 takes an instance of the module’s struct and an optional opts

update!/2 calls update/2 and, if the result is {:ok, instance} returns the instance

Link to this section Types

Link to this type t() View Source
t() :: %Harnais.Runner.Correr{
  test_mapper: term(),
  test_module: term(),
  test_namer: term(),
  test_provas: term(),
  test_runner: term(),
  test_specs: term(),
  test_transform: term(),
  test_type: term(),
  test_value: term()
}

Link to this section Functions

Link to this function new(opts \\ []) View Source
new(any()) :: {:ok, t()} | {:error, error()}

new/1 creates a new instance of the module’s struct and, if the optional opts were given, calls update/2 with the instance and the opts, returning {:ok, instance}, else {:error, error}.

Link to this function new!(opts \\ []) View Source
new!(any()) :: t() | no_return()

new!/1 calls new/1 and, if the result is {:ok, instance} returns the instance.

Link to this function run(state) View Source
run(t()) :: {:ok, {any(), t()}} | {:error, error()}

run/1 takes a correr and runs each prova.

Examples

Tests for a correr look very similar to test runner ones e.g. same.

iex> {:ok, {answer, %CORRER{}}} = [
...>    type: :same, runner: &Harnais.Runner.run_tests_same_test_runner/2,
...>    module: Map, value: %{a: 42},
...>    test_specs: [[args: [:a], call: [:get], result: 42]],
...> ] |> CORRER.new! |> CORRER.run
...> answer
42
Link to this function update(t, opts \\ []) View Source
update(t(), opts()) :: {:ok, t()} | {:error, error()}

update/2 takes an instance of the module’s struct and an optional opts.

The opts are normalised by calling the module’s update_canonical_opts/1 and then reduced with update_field/2:

 opts |> Enum.reduce(instance, fn {k,v}, s -> s |> update_field({k,v}) end)

{:ok, instance} is returned.

Link to this function update!(t, opts \\ []) View Source
update!(t(), any()) :: t() | no_return()

update!/2 calls update/2 and, if the result is {:ok, instance} returns the instance.