Skip to content

Commit

Permalink
Merge pull request #310 from treble37/elixir116_update
Browse files Browse the repository at this point in the history
Elixir116 update
  • Loading branch information
antonmi authored Feb 1, 2024
2 parents fa3802a + 5d84011 commit aa0cd24
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 102 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
elixir-version: '1.13.4'
- otp-version: '25.0'
elixir-version: '1.14.2'
- otp-version: '25.1.2'
elixir-version: '1.15.7'
- otp-version: '26.0'
elixir-version: '1.16.0'
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
Expand Down
240 changes: 142 additions & 98 deletions lib/mix/utils/stale_compatible.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,107 @@ defmodule Mix.Utils.StaleCompatible do

## Test changed dependency resolution

def tests_with_changed_references(%Version{major: 1, minor: minor} = version, test_sources)
when minor >= 10 do
test_manifest = Stale.manifest()
[elixir_manifest] = Mix.Tasks.Compile.Elixir.manifests()

if Mix.Utils.stale?([elixir_manifest], [test_manifest]) do
compile_path = Mix.Project.compile_path()
{elixir_modules, elixir_sources} = apply(CE, :read_manifest, [elixir_manifest])

stale_modules =
for CE.module(module: module) <- elixir_modules,
beam = Path.join(compile_path, Atom.to_string(module) <> ".beam"),
Mix.Utils.stale?([beam], [test_manifest]),
do: module,
into: MapSet.new()

stale_modules =
find_all_dependent_on(version, stale_modules, elixir_sources, elixir_modules)

for module <- stale_modules,
source(source: source, runtime_references: r, compile_references: c) <- test_sources,
module in r or module in c,
do: source,
into: MapSet.new()
else
MapSet.new()
end
end
cond do
Version.match?(System.version(), "< 1.10.0") ->
def tests_with_changed_references(%Version{major: 1, minor: minor} = version, test_sources)
when minor < 10 do
test_manifest = Stale.manifest()
[elixir_manifest] = Mix.Tasks.Compile.Elixir.manifests()

if Mix.Utils.stale?([elixir_manifest], [test_manifest]) do
elixir_manifest_entries =
apply(CE, :read_manifest, [elixir_manifest, Mix.Project.compile_path()])
|> Enum.group_by(&elem(&1, 0))

stale_modules =
for CE.module(module: module) <- elixir_manifest_entries.module,
# version 1.9 has this:
# for CE.module(module: module, beam: beam) <- elixir_manifest_entries.module
# but beam was removed in v1.10.
beam = Path.join(Mix.Project.compile_path(), Atom.to_string(module) <> ".beam"),
Mix.Utils.stale?([beam], [test_manifest]),
do: module,
into: MapSet.new()

stale_modules =
find_all_dependent_on(
version,
stale_modules,
elixir_manifest_entries.source,
elixir_manifest_entries.module
)

def tests_with_changed_references(%Version{major: 1, minor: minor} = version, test_sources)
when minor < 10 do
test_manifest = Stale.manifest()
[elixir_manifest] = Mix.Tasks.Compile.Elixir.manifests()

if Mix.Utils.stale?([elixir_manifest], [test_manifest]) do
elixir_manifest_entries =
apply(CE, :read_manifest, [elixir_manifest, Mix.Project.compile_path()])
|> Enum.group_by(&elem(&1, 0))

stale_modules =
for CE.module(module: module) <- elixir_manifest_entries.module,
# version 1.9 has this:
# for CE.module(module: module, beam: beam) <- elixir_manifest_entries.module
# but beam was removed in v1.10.
beam = Path.join(Mix.Project.compile_path(), Atom.to_string(module) <> ".beam"),
Mix.Utils.stale?([beam], [test_manifest]),
do: module,
into: MapSet.new()

stale_modules =
find_all_dependent_on(
version,
stale_modules,
elixir_manifest_entries.source,
elixir_manifest_entries.module
)
for module <- stale_modules,
source(source: source, runtime_references: r, compile_references: c) <-
test_sources,
module in r or module in c,
do: source,
into: MapSet.new()
else
MapSet.new()
end
end

for module <- stale_modules,
source(source: source, runtime_references: r, compile_references: c) <- test_sources,
module in r or module in c,
do: source,
into: MapSet.new()
else
MapSet.new()
end
Version.match?(System.version(), "< 1.16.0") ->
def tests_with_changed_references(%Version{major: 1, minor: minor} = version, test_sources)
when minor >= 10 and minor < 16 do
test_manifest = Stale.manifest()
[elixir_manifest] = Mix.Tasks.Compile.Elixir.manifests()

if Mix.Utils.stale?([elixir_manifest], [test_manifest]) do
compile_path = Mix.Project.compile_path()
{elixir_modules, elixir_sources} = apply(CE, :read_manifest, [elixir_manifest])

stale_modules =
for CE.module(module: module) <- elixir_modules,
beam = Path.join(compile_path, Atom.to_string(module) <> ".beam"),
Mix.Utils.stale?([beam], [test_manifest]),
do: module,
into: MapSet.new()

stale_modules =
find_all_dependent_on(version, stale_modules, elixir_sources, elixir_modules)

for module <- stale_modules,
source(source: source, runtime_references: r, compile_references: c) <-
test_sources,
module in r or module in c,
do: source,
into: MapSet.new()
else
MapSet.new()
end
end

true ->
def tests_with_changed_references(%Version{major: 1} = version, test_sources) do
test_manifest = Stale.manifest()
[elixir_manifest] = Mix.Tasks.Compile.Elixir.manifests()

if Mix.Utils.stale?([elixir_manifest], [test_manifest]) do
compile_path = Mix.Project.compile_path()
{elixir_modules, elixir_sources} = apply(CE, :read_manifest, [elixir_manifest])

stale_modules =
for {module, _} <- elixir_modules,
beam = Path.join(compile_path, Atom.to_string(module) <> ".beam"),
Mix.Utils.stale?([beam], [test_manifest]),
do: module,
into: MapSet.new()

stale_modules =
find_all_dependent_on(version, stale_modules, elixir_sources, elixir_modules)

for module <- stale_modules,
source(source: source, runtime_references: r, compile_references: c) <-
test_sources,
module in r or module in c,
do: source,
into: MapSet.new()
else
MapSet.new()
end
end
end

## ParallelRequire callback: Handled differently depending on Elixir version
Expand Down Expand Up @@ -225,42 +261,50 @@ defmodule Mix.Utils.StaleCompatible do
end
end

if Version.match?(System.version(), "< 1.11.0") do
defp dependent_modules(%Version{major: 1, minor: minor}, module, modules, sources)
when minor >= 10 do
for CE.source(
source: source,
runtime_references: r,
compile_references: c,
struct_references: s
) <- sources,
module in r or module in c or module in s,
CE.module(sources: sources, module: dependent_module) <- modules,
source in sources,
do: dependent_module
end
else
defp dependent_modules(%Version{major: 1, minor: minor}, module, modules, sources)
when minor >= 11 do
for CE.source(
source: source,
runtime_references: r,
compile_references: c,
export_references: s
) <- sources,
module in r or module in c or module in s,
CE.module(sources: sources, module: dependent_module) <- modules,
source in sources,
do: dependent_module
end
end
cond do
Version.match?(System.version(), "< 1.11.0") ->
defp dependent_modules(%Version{major: 1, minor: minor}, module, modules, sources)
when minor >= 10 do
for CE.source(
source: source,
runtime_references: r,
compile_references: c,
struct_references: s
) <- sources,
module in r or module in c or module in s,
CE.module(sources: sources, module: dependent_module) <- modules,
source in sources,
do: dependent_module
end

defp dependent_modules(%Version{}, module, modules, sources) do
for CE.source(source: source, runtime_references: r, compile_references: c) <- sources,
module in r or module in c,
CE.module(sources: sources, module: dependent_module) <- modules,
source in sources,
do: dependent_module
Version.match?(System.version(), "< 1.16.0") ->
defp dependent_modules(%Version{major: 1, minor: minor}, module, modules, sources)
when minor >= 11 do
for CE.source(
source: source,
runtime_references: r,
compile_references: c,
export_references: s
) <- sources,
module in r or module in c or module in s,
CE.module(sources: sources, module: dependent_module) <- modules,
source in sources,
do: dependent_module
end

true ->
defp dependent_modules(%Version{}, module, modules, sources) do
for {source,
CE.source(
runtime_references: r,
compile_references: c,
export_references: e
)} <- sources,
module in r or module in c or module in e,
{dependent_module, CE.module(sources: sources)} <- modules,
source in sources,
do: dependent_module
end
end

defp parse_version do
Expand Down
4 changes: 3 additions & 1 deletion spec/assertions/enum/have_all_spec.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ defmodule ESpec.Assertions.Enum.HaveAllSpec do

it "checks success with `to`" do
message = expect(dict()) |> to(have_all(positive()))
expect(message) |> to(end_with "returns `true` for all elements in `%{a: 1, b: 2, c: 3}`.")

expect(message)
|> to(end_with "returns `true` for all elements in `#{inspect(%{a: 1, b: 2, c: 3})}`.")
end

it "checks success with `not_to`" do
Expand Down
2 changes: 1 addition & 1 deletion spec/assertions/eq_spec.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule ESpec.Assertions.EqSpec do
{:shared,
expectation: fn -> expect(%{a: 2, b: 3, c: 4}) |> to(eq(%{a: 2, b: 4})) end,
message:
"Expected `%{a: 2, b: 3, c: 4}` to equal (==) `%{a: 2, b: 4}`, but it doesn't.",
"Expected `#{inspect(%{a: 2, b: 3, c: 4})}` to equal (==) `%{a: 2, b: 4}`, but it doesn't.",
extra: true}
end

Expand Down
9 changes: 7 additions & 2 deletions spec/diff_spec.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ defmodule DiffSpec do
use ESpec, async: true

defmacrop diff_1_2 do
if Version.match?(System.version(), ">= 1.10.0") do
if Version.match?(System.version(), ">= 1.10.0") and
Version.match?(System.version(), "< 1.15.0") do
quote do
%ExUnit.Diff{
equivalent?: false,
Expand All @@ -12,7 +13,11 @@ defmodule DiffSpec do
end
else
quote do
{[ins: "1"], [del: "2"]}
%ExUnit.Diff{
equivalent?: false,
left: %{delimiter: nil, contents: [true: "2"]},
right: %{delimiter: nil, contents: [true: "1"]}
}
end
end
end
Expand Down

0 comments on commit aa0cd24

Please sign in to comment.