|
1 | 1 | defmodule ExUnit.Filters do
|
2 |
| - alias ExUnit.FailuresManifest |
3 |
| - |
4 | 2 | @moduledoc """
|
5 | 3 | Conveniences for parsing and evaluating filters.
|
6 | 4 | """
|
| 5 | + alias ExUnit.FailuresManifest |
7 | 6 |
|
8 | 7 | @type t :: list({atom, Regex.t() | String.Chars.t()} | atom)
|
9 | 8 | @type location :: {:location, {String.t(), pos_integer | [pos_integer, ...]}}
|
@@ -195,26 +194,32 @@ defmodule ExUnit.Filters do
|
195 | 194 | @spec eval(t, t, map, [ExUnit.Test.t()]) ::
|
196 | 195 | :ok | {:excluded, String.t()} | {:skipped, String.t()}
|
197 | 196 | def eval(include, exclude, tags, collection) when is_map(tags) do
|
198 |
| - excluded = Enum.find_value(exclude, &has_tag(&1, tags, collection)) |
199 |
| - excluded? = excluded != nil |
200 |
| - included? = Enum.any?(include, &has_tag(&1, tags, collection)) |
| 197 | + cond do |
| 198 | + Enum.any?(include, &has_tag(&1, tags, collection)) -> |
| 199 | + maybe_skipped(include, tags, collection) |
| 200 | + |
| 201 | + excluded = Enum.find_value(exclude, &has_tag(&1, tags, collection)) -> |
| 202 | + {:excluded, "due to #{excluded} filter"} |
201 | 203 |
|
202 |
| - if included? or not excluded? do |
203 |
| - skip_tag = %{skip: Map.get(tags, :skip, true)} |
204 |
| - skip_included_explicitly? = Enum.any?(include, &has_tag(&1, skip_tag, collection)) |
| 204 | + true -> |
| 205 | + maybe_skipped(include, tags, collection) |
| 206 | + end |
| 207 | + end |
205 | 208 |
|
206 |
| - case Map.fetch(tags, :skip) do |
207 |
| - {:ok, msg} when is_binary(msg) and not skip_included_explicitly? -> |
208 |
| - {:skipped, msg} |
| 209 | + defp maybe_skipped(include, tags, collection) do |
| 210 | + case tags do |
| 211 | + %{skip: skip} when is_binary(skip) or skip == true -> |
| 212 | + skip_tags = %{skip: skip} |
| 213 | + skip_included_explicitly? = Enum.any?(include, &has_tag(&1, skip_tags, collection)) |
209 | 214 |
|
210 |
| - {:ok, true} when not skip_included_explicitly? -> |
211 |
| - {:skipped, "due to skip tag"} |
| 215 | + cond do |
| 216 | + skip_included_explicitly? -> :ok |
| 217 | + is_binary(skip) -> {:skipped, skip} |
| 218 | + skip -> {:skipped, "due to skip tag"} |
| 219 | + end |
212 | 220 |
|
213 |
| - _ -> |
214 |
| - :ok |
215 |
| - end |
216 |
| - else |
217 |
| - {:excluded, "due to #{excluded} filter"} |
| 221 | + _ -> |
| 222 | + :ok |
218 | 223 | end
|
219 | 224 | end
|
220 | 225 |
|
|
0 commit comments