Skip to content

Commit b121aab

Browse files
TylerWittjosevalim
authored andcommitted
Add specs for override: list options
1 parent 7945446 commit b121aab

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

lib/mix/lib/mix/dep.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ defmodule Mix.Dep do
347347
dep_status(dep) <>
348348
"\n does not match the requirement specified\n" <>
349349
dep_status(other) <>
350-
"\n Ensure they match or specify one of the above in your deps and set \"override: true\""
350+
"\n Ensure they match or specify one of the above in your deps and set \"override: [#{inspect(other.app)}]\""
351351
end
352352

353353
def format_status(%Mix.Dep{app: app, status: {:divergedonly, other}} = dep) do

lib/mix/lib/mix/tasks/deps.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ defmodule Mix.Tasks.Deps do
9999
targets (like `[:host, :rpi3]`)
100100
101101
* `:override` - if set to `true` the dependency will override any other
102-
definitions of itself by other dependencies
102+
definitions of itself by other dependencies. This option can also be a
103+
list, which overrides the definitions of only certain dependencies. If
104+
a dependency is not included in the list and an override is required,
105+
it will still fail. If a dependency is in the list and no longer necessary,
106+
then a warning is emitted
103107
104108
* `:manager` - Mix can also compile Rebar3 and makefile projects
105109
and can fetch sub dependencies of Rebar3 projects. Mix will

lib/mix/test/mix/dep_test.exs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,47 @@ defmodule Mix.DepTest do
12661266
end
12671267
end
12681268

1269+
describe "override_for" do
1270+
test "warns when overrides are no longer needed for an app" do
1271+
deps = [
1272+
{:deps_repo, "0.1.0", path: "custom/deps_repo"},
1273+
{:git_repo, "0.1.0",
1274+
git: MixTest.Case.fixture_path("git_repo"), override_for: [:deps_repo]}
1275+
]
1276+
1277+
with_deps(deps, fn ->
1278+
in_fixture("deps_status", fn ->
1279+
Mix.Tasks.Deps.Get.run([])
1280+
Mix.Tasks.Deps.Compile.run([])
1281+
end)
1282+
end)
1283+
1284+
message =
1285+
"Dependency git_repo (#{fixture_path("git_repo")}) no longer requires override_for on deps_repo"
1286+
1287+
assert_received {:mix_shell, :info, [^message]}
1288+
end
1289+
1290+
test "errors when more overrides are needed for an app" do
1291+
deps = [
1292+
{:deps_repo, "0.1.0", path: "custom/deps_repo"},
1293+
{:git_repo, "0.2.0", git: MixTest.Case.fixture_path("git_repo"), override_for: []}
1294+
]
1295+
1296+
with_deps(deps, fn ->
1297+
in_fixture("deps_status", fn ->
1298+
Mix.Tasks.Deps.Get.run([])
1299+
Mix.Tasks.Deps.Compile.run([])
1300+
end)
1301+
end)
1302+
1303+
message =
1304+
"Dependency git_repo (#{fixture_path("git_repo")}) requires override_for on deps_repo"
1305+
1306+
assert_received {:mix_shell, :info, [^message]}
1307+
end
1308+
end
1309+
12691310
describe "app generation" do
12701311
test "considers runtime from current app on nested deps" do
12711312
Process.put(:custom_deps_git_repo_opts, runtime: false)

0 commit comments

Comments
 (0)