Skip to content

Commit

Permalink
Fixes for Elixir 1.15.0 (#974)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Meadows-Jönsson <[email protected]>
  • Loading branch information
josevalim and ericmj authored Jan 29, 2023
1 parent 96948da commit 853b278
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
6 changes: 6 additions & 0 deletions lib/mix/tasks/hex.publish.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ defmodule Mix.Tasks.Hex.Publish do
end

defp docs_task() do
# Elixir v1.15 prunes the loadpaths on compilation and
# docs will compile code. So we add all original code paths back.
path = :code.get_path()

try do
Mix.Task.run("docs", [])
rescue
Expand All @@ -199,6 +203,8 @@ defmodule Mix.Tasks.Hex.Publish do
""")

reraise ex, stacktrace
after
:code.add_pathsz(path)
end
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Hex.MixProject do

def application do
[
extra_applications: [:ssl, :inets, :logger],
extra_applications: [:ssh, :ssl, :inets, :logger],
mod: {Hex.Application, []}
]
end
Expand Down
49 changes: 44 additions & 5 deletions test/hex/mix_task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Hex.MixTaskTest do
[
app: :simple,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ecto, "0.2.0"}
]
Expand All @@ -18,6 +19,7 @@ defmodule Hex.MixTaskTest do
[
app: :simple,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ecto, "~> 0.2.1"}
]
Expand All @@ -30,6 +32,7 @@ defmodule Hex.MixTaskTest do
[
app: :simple,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ecto, "~> 0.2.0"}
]
Expand All @@ -42,6 +45,7 @@ defmodule Hex.MixTaskTest do
[
app: :override,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ecto, "0.2.0"},
{:ex_doc, "~> 0.1.0", override: true}
Expand All @@ -55,6 +59,7 @@ defmodule Hex.MixTaskTest do
[
app: :non_hex_dep,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:has_hex_dep, path: fixture_path("has_hex_dep")}
]
Expand All @@ -67,6 +72,7 @@ defmodule Hex.MixTaskTest do
[
app: :ecto_path_dep,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:postgrex, ">= 0.0.0"},
{:ecto, path: fixture_path("ecto")}
Expand All @@ -80,6 +86,7 @@ defmodule Hex.MixTaskTest do
[
app: :ecto_path_dep,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:postgrex, "0.2.1"},
{:ecto, path: fixture_path("ecto")}
Expand All @@ -93,6 +100,7 @@ defmodule Hex.MixTaskTest do
[
app: :ecto_path_dep,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:postgrex_conflict, ">= 0.0.0", hex: :postgrex},
{:ecto, path: fixture_path("ecto")}
Expand All @@ -106,6 +114,7 @@ defmodule Hex.MixTaskTest do
[
app: :override_with_path,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:postgrex, ">= 0.0.0"},
{:ex_doc, path: fixture_path("ex_doc"), override: true}
Expand All @@ -119,6 +128,7 @@ defmodule Hex.MixTaskTest do
[
app: :override_two_levels_with_path,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:phoenix, ">= 0.0.0"},
{:ex_doc, path: fixture_path("ex_doc"), override: true}
Expand All @@ -132,6 +142,7 @@ defmodule Hex.MixTaskTest do
[
app: :override_with_path_parent,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:override_with_path, path: fixture_path("override_with_path")}
]
Expand All @@ -144,6 +155,7 @@ defmodule Hex.MixTaskTest do
[
app: :optional,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:only_doc, ">= 0.0.0"}
]
Expand All @@ -156,6 +168,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_optional,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:only_doc, ">= 0.0.0"},
{:ex_doc, "0.0.1"}
Expand All @@ -169,6 +182,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_package_name,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:app_name, ">= 0.0.0", hex: :package_name}
]
Expand All @@ -181,6 +195,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_depend_name,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:depend_name, ">= 0.0.0"}
]
Expand All @@ -193,6 +208,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_incorrect_dep_version,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ex_doc, "> hello"}
]
Expand All @@ -205,6 +221,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_missing_dep_version,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ex_doc, []}
]
Expand All @@ -217,6 +234,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_non_matching_requirement,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ex_doc, "~> 100.0.0"}
]
Expand All @@ -229,6 +247,7 @@ defmodule Hex.MixTaskTest do
[
app: :with_only_matching_pre_requirement,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:beta, "~> 1.1.0"}
]
Expand All @@ -241,6 +260,7 @@ defmodule Hex.MixTaskTest do
[
app: :depends_on_ecto_sql,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ecto_sql, "~> 3.3"},
{:ecto_enum, "1.4.0"}
Expand All @@ -254,13 +274,32 @@ defmodule Hex.MixTaskTest do
[
app: :depends_on_sponsored,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:sponsored, "0.1.0"}
]
]
end
end

defp reset_code_paths(fun) do
path = :code.get_path()

try do
fun.()
after
:code.add_pathsz(path)
end
end

defp deps_compile() do
reset_code_paths(fn -> Mix.Task.run("deps.compile") end)
end

defp compile() do
reset_code_paths(fn -> Mix.Task.run("compile") end)
end

test "deps.get" do
Mix.Project.push(Simple)

Expand All @@ -272,7 +311,7 @@ defmodule Hex.MixTaskTest do
assert_received {:mix_shell, :info, ["* Getting postgrex (Hex package)"]}
assert_received {:mix_shell, :info, ["* Getting ex_doc (Hex package)"]}

Mix.Task.run("deps.compile")
deps_compile()
Mix.Task.run("deps")

assert_received {:mix_shell, :info, ["* ecto 0.2.0 (Hex package)" <> _]}
Expand Down Expand Up @@ -304,7 +343,7 @@ defmodule Hex.MixTaskTest do
Mix.Task.clear()

Mix.Task.run("deps.get")
Mix.Task.run("deps.compile")
deps_compile()
Mix.Task.run("deps")

assert_received {:mix_shell, :info, ["* ecto 0.2.0 (Hex package)" <> _]}
Expand Down Expand Up @@ -344,7 +383,7 @@ defmodule Hex.MixTaskTest do
assert_received {:mix_shell, :info, ["* Updating postgrex (Hex package)"]}
assert_received {:mix_shell, :info, ["* Updating ex_doc (Hex package)"]}

Mix.Task.run("deps.compile")
deps_compile()
Mix.Task.run("deps")

assert_received {:mix_shell, :info, ["* ecto 0.2.1 (Hex package)" <> _]}
Expand Down Expand Up @@ -545,7 +584,7 @@ defmodule Hex.MixTaskTest do
Hex.State.put(:cache_home, File.cwd!())

Mix.Task.run("deps.get")
Mix.Task.run("deps.compile")
deps_compile()
Mix.Task.run("deps")

assert_received {:mix_shell, :info, ["* ecto 0.2.0 (Hex package)" <> _]}
Expand Down Expand Up @@ -956,7 +995,7 @@ defmodule Hex.MixTaskTest do
})

Mix.Task.run("deps.get")
Mix.Task.run("compile")
compile()
Mix.Task.run("deps.update", ["ecto_sql"])
end)
after
Expand Down
18 changes: 9 additions & 9 deletions test/mix/tasks/hex.publish_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ defmodule Mix.Tasks.Hex.PublishTest do
send(self(), {:mix_shell_input, :prompt, "hunter42"})
Mix.Tasks.Hex.Publish.run(["package", "--no-progress", "--replace"])

message =
"Package published to http://localhost:4043/packages/publish_and_revert/0.0.1 " <>
"(cea573df6b6ca7027ca918ea349ec34af17774b426dd4c3a0db0bdecca97d0d0)"

assert_received {:mix_shell, :info, [^message]}
assert_received {:mix_shell, :info,
[
"Package published to http://localhost:4043/packages/publish_and_revert/0.0.1 " <>
_
]}

assert {:ok, {200, _, _}} = Hex.API.Release.get("hexpm", "publish_and_revert", "0.0.1")

message =
"Before publishing, please read the Code of Conduct: https://hex.pm/policies/codeofconduct\n"

assert_received {:mix_shell, :info, [^message]}
assert_received {:mix_shell, :info,
[
"Before publishing, please read the Code of Conduct: https://hex.pm/policies/codeofconduct\n"
]}

send(self(), {:mix_shell_input, :yes?, true})
send(self(), {:mix_shell_input, :prompt, "hunter42"})
Expand Down

0 comments on commit 853b278

Please sign in to comment.