Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/mix/lib/mix/dep/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ defmodule Mix.Dep.Loader do
{scm, opts} = get_scm(app, opts)

{scm, opts} =
if is_nil(scm) and Mix.Hex.ensure_installed?(locked?) do
if is_nil(scm) and locked? and Mix.Hex.ensure_installed?(locked?) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the question — I might be missing something here.

I added the locked? check because when I remove it, the following test starts failing:

test raises when no SCM is specified (Mix.DepTest)
     test/mix/dep_test.exs:115
     Expected exception Mix.Error but got MatchError (no match of right hand side value:

         {:error, {:hex, {~c"no such file or directory", ~c"hex.app"}}}
     )
     code: with_deps(deps, fn ->
     stacktrace:
       lib/hex.ex:5: Hex.start/0
       (mix 1.20.0-dev) lib/mix/hex.ex:64: Mix.Hex.start/0
       (mix 1.20.0-dev) lib/mix/dep/loader.ex:193: Mix.Dep.Loader.with_scm_and_app/5
       (mix 1.20.0-dev) lib/mix/dep/loader.ex:145: Mix.Dep.Loader.to_dep/4
       (elixir 1.20.0-dev) lib/enum.ex:1717: Enum."-map/2-lists^map/1-1-"/2
       (mix 1.20.0-dev) lib/mix/dep/loader.ex:376: Mix.Dep.Loader.mix_children/3
       (mix 1.20.0-dev) lib/mix/dep/loader.ex:22: Mix.Dep.Loader.children/1
       (mix 1.20.0-dev) lib/mix/dep/converger.ex:101: Mix.Dep.Converger.all/4
       (mix 1.20.0-dev) lib/mix/dep/converger.ex:93: Mix.Dep.Converger.converge/4
       (mix 1.20.0-dev) lib/mix/dep/converger.ex:76: Mix.Dep.Converger.converge/1
       (elixir 1.20.0-dev) lib/file.ex:2013: File.cd!/2
       test/test_helper.exs:174: MixTest.Case.in_fixture/3
       test/mix/dep_test.exs:35: Mix.DepTest.with_deps/2
       test/mix/dep_test.exs:118: (test)

I’m not fully sure what the intended behavior is here, so I added the guard to keep the existing test behavior.
Happy to change this if there’s a better approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at test/mix/tasks/deps_test.exs and see how tests with dependencies are handled. We already have some dependencies that we can handle, such as ok and git_repo, and you can create a project with the same name as one of those deps. You can then also move the test to test/mix/tasks/deps_test.exs :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I’ve moved the test to test/mix/tasks/deps_test.exs and reused the existing :ok dependency fixture as suggested. All make test_mix passes locally.

_ = Mix.Hex.start()
get_scm(app, opts)
else
Expand All @@ -202,6 +202,14 @@ defmodule Mix.Dep.Loader do
)
end

project_app = Mix.Project.config()[:app]

if project_app && project_app == app do
Mix.shell().error(
"warning: the application name #{inspect(app)} is the same as one of its dependencies"
)
end

%Mix.Dep{
scm: scm,
app: app,
Expand Down
27 changes: 27 additions & 0 deletions lib/mix/test/mix/project_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,33 @@ defmodule Mix.ProjectTest do
end)
end

test "warns when project app name matches a dependency" do
Mix.shell(Mix.Shell.Process)

in_tmp("duplicate_app_name", fn ->
File.write!("mix.exs", """
defmodule DuplicateAppName.MixProject do
use Mix.Project

def project do
[
app: :foo,
version: "0.1.0",
deps: [{:foo, "~> 0.1.0"}]
]
end
end
""")

Mix.Project.in_project(:foo, ".", fn _ ->
Mix.Dep.Loader.children(true)
end)
end)

assert_received {:mix_shell, :error,
["warning: the application name :foo is the same as one of its dependencies"]}
end

test "in_project prints nice error message if fails to load file", context do
in_tmp(context.test, fn ->
File.write("mix.exs", """
Expand Down