Skip to content

Commit

Permalink
🐛 Handle command-line with only patterns (#123)
Browse files Browse the repository at this point in the history
The new command-line parsing in v4.0 wasn't properly handling a command-line that had only patterns/filenames as arguments. We were treating that as empty mti options and ignoring the patterns rather than passing the command line on to be parsed as mix test options.

Fixes #122
  • Loading branch information
randycoulman authored Sep 28, 2024
1 parent 9b720e2 commit da88d6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mix_test_interactive/command_line_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ defmodule MixTestInteractive.CommandLineParser do
end

defp try_parse_as_mti_args(args) do
{mti_opts, _args, invalid} = OptionParser.parse(args, strict: @options)
{mti_opts, patterns, invalid} = OptionParser.parse(args, strict: @options)

cond do
invalid == [] -> {:ok, mti_opts}
invalid == [] and patterns == [] -> {:ok, mti_opts}
mti_opts[:help] || mti_opts[:version] -> {:ok, mti_opts}
mti_opts == [] -> {:error, :maybe_mix_test_args}
true -> force_parse_as_mti_args(args)
Expand Down
6 changes: 6 additions & 0 deletions test/mix_test_interactive/command_line_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ defmodule MixTestInteractive.CommandLineParserTest do
assert settings.initial_cli_args == ["--color"]
end

test "extracts patterns even when no other flags are present" do
{:ok, %{settings: settings}} = CommandLineParser.parse(["pattern1", "pattern2"])
assert settings.patterns == ["pattern1", "pattern2"]
assert settings.initial_cli_args == []
end

test "failed takes precedence over stale" do
{:ok, %{settings: settings}} = CommandLineParser.parse(["--failed", "--stale"])
refute settings.stale?
Expand Down

0 comments on commit da88d6b

Please sign in to comment.