From b5eb8d9a90551d0f43afe934ef36c48705fddcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Fri, 24 Nov 2023 12:08:23 +0100 Subject: [PATCH] Mix: allow installing a dependency without list brackets --- lib/mix/lib/mix.ex | 3 +++ lib/mix/test/mix_test.exs | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex index 8532964475f..e4e55ba45b5 100644 --- a/lib/mix/lib/mix.ex +++ b/lib/mix/lib/mix.ex @@ -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() diff --git a/lib/mix/test/mix_test.exs b/lib/mix/test/mix_test.exs index e7b02da1e7d..236058ff739 100644 --- a/lib/mix/test/mix_test.exs +++ b/lib/mix/test/mix_test.exs @@ -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"]}