-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add repeat until failure command (#118)
* ✨ Add r command to repeat tests until failure * ♻️ Extract run summary into its own module Also, refactor for less string concatentation.
- Loading branch information
1 parent
ce55d50
commit 15ea504
Showing
13 changed files
with
290 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule MixTestInteractive.Command.RepeatUntilFailure do | ||
@moduledoc """ | ||
Specify or clear the number of repetitions for running until failure. | ||
Runs the tests repeatedly until failure or until the specified number of runs. | ||
If not provided, the count is cleared and the tests will run just once as | ||
usual. | ||
Corresponds to `mix test --repeat-until-failure <count>`. | ||
This option is only available in `mix test` in Elixir 1.17.0 and later. | ||
""" | ||
use MixTestInteractive.Command, command: "r", desc: "set or clear the repeat-until-failure count" | ||
|
||
alias MixTestInteractive.Command | ||
alias MixTestInteractive.Settings | ||
|
||
@impl Command | ||
def name, do: "r [<count>]" | ||
|
||
@impl Command | ||
def run([], %Settings{} = settings) do | ||
{:ok, Settings.clear_repeat_count(settings)} | ||
end | ||
|
||
@impl Command | ||
def run([count], %Settings{} = settings) do | ||
{:ok, Settings.with_repeat_count(settings, count)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
defmodule MixTestInteractive.RunSummary do | ||
@moduledoc false | ||
alias MixTestInteractive.Settings | ||
|
||
@doc """ | ||
Return a text summary of the current interactive mode settings. | ||
""" | ||
@spec from_settings(Settings.t()) :: String.t() | ||
def from_settings(%Settings{} = settings) do | ||
[&base_summary/1, &all_tag_filters/1, &max_failures/1, &repeat_count/1, &seed/1, &tracing/1] | ||
|> Enum.flat_map(fn fun -> List.wrap(fun.(settings)) end) | ||
|> Enum.join("\n") | ||
end | ||
|
||
defp all_tag_filters(%Settings{} = settings) do | ||
Enum.reject( | ||
[ | ||
tag_filters("Excluding tags", settings.excludes), | ||
tag_filters("Including tags", settings.includes), | ||
tag_filters("Only tags", settings.only) | ||
], | ||
&is_nil/1 | ||
) | ||
end | ||
|
||
defp base_summary(%Settings{} = settings) do | ||
cond do | ||
settings.failed? -> | ||
"Ran only failed tests" | ||
|
||
settings.stale? -> | ||
"Ran only stale tests" | ||
|
||
!Enum.empty?(settings.patterns) -> | ||
"Ran all test files matching #{Enum.join(settings.patterns, ", ")}" | ||
|
||
true -> | ||
"Ran all tests" | ||
end | ||
end | ||
|
||
defp max_failures(%Settings{max_failures: nil}), do: nil | ||
|
||
defp max_failures(%Settings{} = settings) do | ||
"Max failures: #{settings.max_failures}" | ||
end | ||
|
||
defp repeat_count(%Settings{repeat_count: nil}), do: nil | ||
|
||
defp repeat_count(%Settings{} = settings) do | ||
"Repeat until failure: #{settings.repeat_count}" | ||
end | ||
|
||
def seed(%Settings{seed: nil}), do: nil | ||
|
||
def seed(%Settings{} = settings) do | ||
"Seed: #{settings.seed}" | ||
end | ||
|
||
defp tracing(%Settings{tracing?: false}), do: nil | ||
|
||
defp tracing(%Settings{}) do | ||
"Tracing: ON" | ||
end | ||
|
||
defp tag_filters(_label, []), do: nil | ||
|
||
defp tag_filters(label, tags) do | ||
label <> ": " <> inspect(tags) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.