ExUnit v1.7.4 ExUnit.Filters View Source

Conveniences for parsing and evaluating filters.

Link to this section Summary

Functions

Evaluates the include and exclude filters against the given tags to determine if tests should be skipped or excluded

Returns a tuple containing useful information about test failures from the manifest. The tuple contains

Normalizes include and excludes to remove duplicates and keep precedence

Parses the given filters, as one would receive from the command line

Parses filters out of a path

Link to this section Types

Link to this section Functions

Link to this function eval(include, exclude, tags, collection) View Source
eval(t(), t(), map(), [ExUnit.Test.t()]) :: :ok | {:error, binary()}

Evaluates the include and exclude filters against the given tags to determine if tests should be skipped or excluded.

Some filters, like :line, may require the whole test collection to find the closest line, that’s why it must also be passed as argument.

Filters can either be a regular expression or any data structure that implements to String.Chars, which is invoked before comparing the filter with the tag value.

Examples

iex> ExUnit.Filters.eval([foo: "bar"], [:foo], %{foo: "bar"}, [])
:ok

iex> ExUnit.Filters.eval([foo: "bar"], [:foo], %{foo: "baz"}, [])
{:excluded, "due to foo filter"}
Link to this function failure_info(manifest_file) View Source
failure_info(Path.t()) ::
  {MapSet.t(Path.t()), MapSet.t(ExUnit.FailuresManifest.test_id())}

Returns a tuple containing useful information about test failures from the manifest. The tuple contains:

  • A set of files that contain tests that failed the last time they ran. The paths are absolute paths.
  • A set of test ids that failed the last time they ran
Link to this function normalize(include, exclude) View Source
normalize(t() | nil, t() | nil) :: {t(), t()}

Normalizes include and excludes to remove duplicates and keep precedence.

Examples

iex> ExUnit.Filters.normalize(nil, nil)
{[], []}

iex> ExUnit.Filters.normalize([:foo, :bar, :bar], [:foo, :baz])
{[:foo, :bar], [:baz]}

iex> ExUnit.Filters.normalize([foo: "true"], [:foo])
{[foo: "true"], [:foo]}

iex> ExUnit.Filters.normalize([:foo], [foo: "true"])
{[:foo], []}

iex> ExUnit.Filters.normalize([foo: "true"], [foo: true])
{[foo: "true"], []}

iex> ExUnit.Filters.normalize([foo: true], [foo: "true"])
{[foo: true], []}
Link to this function parse(filters) View Source
parse([String.t()]) :: t()

Parses the given filters, as one would receive from the command line.

Examples

iex> ExUnit.Filters.parse(["foo:bar", "baz", "line:9", "bool:true"])
[{:foo, "bar"}, :baz, {:line, "9"}, {:bool, "true"}]
Link to this function parse_path(file) View Source
parse_path(String.t()) :: {String.t(), any()}

Parses filters out of a path.

Determines whether a given file path (supplied to ExUnit/Mix as arguments on the command line) includes a line number filter, and if so returns the appropriate ExUnit configuration options.