Skip to content

Commit

Permalink
Merge pull request #38 from antedeguemon/vm-fixes-multiple-input-files
Browse files Browse the repository at this point in the history
Fixes handling of multiple input files
  • Loading branch information
NickNeck committed Oct 30, 2022
2 parents 780e88c + ebd0dbc commit 61a36ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/mix/tasks/recode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ defmodule Mix.Tasks.Recode do
defp opts!(opts) do
case OptionParser.parse!(opts, @opts) do
{opts, []} -> opts
{opts, [inputs]} -> Keyword.put(opts, :inputs, inputs)
{_opts, args} -> Mix.raise("#{inspect(args)} : Unknown")
{opts, inputs} -> Keyword.put(opts, :inputs, inputs)
end
end

Expand Down
18 changes: 15 additions & 3 deletions test/mix/tasks/recode_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,35 @@ defmodule Mix.Tasks.RecodeTest do
test "mix recode --config priv/config.exs -" do
expect(RunnerMock, :run, fn config ->
assert Keyword.keyword?(config)
assert config[:inputs] == "-"
assert config[:inputs] == ["-"]

":test" |> source() |> project()
end)

assert catch_exit(Tasks.Recode.run(["--config", "priv/config.exs", "-"])) == :normal
end

test "mix recode file_1.ex file_2.ex" do
expect(RunnerMock, :run, fn config ->
assert Keyword.keyword?(config)
assert config[:inputs] == ["file_1.ex", "file_2.ex"]

":test" |> source() |> project()
end)

assert catch_exit(Tasks.Recode.run(["--config", "priv/config.exs", "file_1.ex", "file_2.ex"])) ==
:normal
end

test "mix recode raises exception for unknown config file" do
assert_raise Mix.Error, "Config file not found", fn ->
Tasks.Recode.run(["--config", "priv/no_config.exs"])
end
end

test "mix recode raises exception for unknown arg" do
assert_raise Mix.Error, ~s|["inputs", "foo"] : Unknown|, fn ->
Tasks.Recode.run(["--config", "priv/config.exs", "inputs", "foo"])
assert_raise OptionParser.ParseError, ~r|unknown-arg : Unknown option|, fn ->
Tasks.Recode.run(["--config", "priv/config.exs", "--unknown-arg", "inputs", "foo"])
end
end

Expand Down

0 comments on commit 61a36ae

Please sign in to comment.