Skip to content

Commit

Permalink
Mix: allow installing a dependency without list brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
azizk committed Nov 24, 2023
1 parent 9daef61 commit b5eb8d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/mix/lib/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ defmodule Mix do
@doc since: "1.12.0"
def install(deps, opts \\ [])

def install(dep, opts) when is_atom(dep) or is_tuple(dep),
do: install([dep], opts)

def install(deps, opts) when is_list(deps) and is_list(opts) do
Mix.start()

Expand Down
21 changes: 19 additions & 2 deletions lib/mix/test/mix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,32 @@ defmodule MixTest do

setup :test_project

test "single unwrapped dependency", %{tmp_dir: tmp_dir} do
dep = {:install_test, path: Path.join(tmp_dir, "install_test")}
refute is_list(dep)
Mix.install(dep)

assert Protocol.consolidated?(InstallTest.Protocol)

assert File.dir?(Path.join(tmp_dir, "installs"))
assert_received {:mix_shell, :info, ["==> install_test"]}
assert_received {:mix_shell, :info, ["Compiling 1 file (.ex)"]}
assert_received {:mix_shell, :info, ["Generated install_test app"]}
refute_received _

assert Application.app_dir(:crypto) =~ "crypto"
assert List.keyfind(Application.started_applications(), :install_test, 0)
assert apply(InstallTest, :hello, []) == :world
end

test "default options", %{tmp_dir: tmp_dir} do
Mix.install([
{:install_test, path: Path.join(tmp_dir, "install_test")}
])

assert File.dir?(Path.join(tmp_dir, "installs"))

assert Protocol.consolidated?(InstallTest.Protocol)

assert File.dir?(Path.join(tmp_dir, "installs"))
assert_received {:mix_shell, :info, ["==> install_test"]}
assert_received {:mix_shell, :info, ["Compiling 1 file (.ex)"]}
assert_received {:mix_shell, :info, ["Generated install_test app"]}
Expand Down

0 comments on commit b5eb8d9

Please sign in to comment.