ExUnit v1.3.2 ExUnit.Filters

Conveniences for parsing and evaluating filters.

Summary

Functions

Evaluates the include and exclude filters against the given tags

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

Types

t :: [{atom, Regex.t | String.Chars.t} | atom]

Functions

eval(include, exclude, tags, collection)

Specs

eval(t, t, map, [ExUnit.Test.t]) ::
  :ok |
  {:error, binary}

Evaluates the include and exclude filters against the given tags.

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"}, [])
{:error, "due to foo filter"}
normalize(include, exclude)

Specs

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]}
parse(filters)

Specs

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"}]
parse_path(file)

Specs

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.