Skip to content

Commit 0ba2177

Browse files
committed
WIP
1 parent 8c76b6b commit 0ba2177

File tree

10 files changed

+42
-26
lines changed

10 files changed

+42
-26
lines changed

Diff for: .tool-versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Describes the versions of Erlang and Elixir we develop against;
22
# can be overridden for compatibility testing purposes.
3-
erlang 26.1
4-
elixir 1.15.6-otp-26
3+
erlang 26.1.2
4+
elixir 1.16.2-otp-26

Diff for: lib/matcha/context/erlang.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Matcha.Context.Erlang do
1717
# https://github.com/elixir-lang/elixir/blob/f4b05d178d7b9bb5356beae7ef8e01c32324d476/lib/elixir/src/elixir_utils.erl#L24-L37
1818

1919
moduledoc =
20-
if Matcha.Helpers.erlang_version() < 25 do
20+
if Version.match?(Matcha.Helpers.erlang_version(), "< 25.0.0") do
2121
moduledoc <>
2222
"""
2323
@@ -33,7 +33,7 @@ defmodule Matcha.Context.Erlang do
3333
end
3434

3535
moduledoc =
36-
if Matcha.Helpers.erlang_version() < 26 do
36+
if Version.match?(Matcha.Helpers.erlang_version(), "< 26.0.0") do
3737
moduledoc <>
3838
"""
3939
@@ -116,12 +116,12 @@ defmodule Matcha.Context.Erlang do
116116
xor: 2
117117
]
118118

119-
if Matcha.Helpers.erlang_version() >= 25 do
119+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
120120
@allowed_functions @allowed_functions ++ [binary_part: 2, binary_part: 3]
121121
@allowed_functions @allowed_functions ++ [byte_size: 1]
122122
end
123123

124-
if Matcha.Helpers.erlang_version() >= 26 do
124+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
125125
@allowed_functions @allowed_functions ++ [ceil: 1, floor: 1]
126126
@allowed_functions @allowed_functions ++ [is_function: 2]
127127
@allowed_functions @allowed_functions ++ [tuple_size: 1]

Diff for: lib/matcha/helpers.ex

+17-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ defmodule Matcha.Helpers do
2929
end
3030

3131
def erlang_version do
32-
:erlang.system_info(:otp_release) |> List.to_integer()
32+
Path.join([
33+
:code.root_dir(),
34+
"releases",
35+
:erlang.system_info(:otp_release),
36+
"OTP_VERSION"
37+
])
38+
|> File.read!()
39+
|> String.trim()
40+
|> String.split(".")
41+
|> Stream.unfold(fn
42+
[] -> nil
43+
[head | tail] -> {head, tail}
44+
end)
45+
|> Stream.concat(Stream.repeatedly(fn -> 0 end))
46+
|> Enum.take(3)
47+
|> Enum.join(".")
48+
|> Version.parse!()
3349
end
3450
end

Diff for: lib/matcha/rewrite/calls.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule Matcha.Rewrite.Calls do
7575
@spec raise_invalid_call_error!(Rewrite.t(), Rewrite.Bindings.var_ast()) :: no_return()
7676
defp raise_invalid_call_error!(rewrite, call)
7777

78-
if Matcha.Helpers.erlang_version() < 25 do
78+
if Version.match?(Matcha.Helpers.erlang_version(), "< 25.0.0") do
7979
for {erlang_25_function, erlang_25_arity} <- [binary_part: 2, binary_part: 3, byte_size: 1] do
8080
defp raise_invalid_call_error!(rewrite = %Rewrite{}, {module, function, args})
8181
when module == :erlang and

Diff for: lib/matcha/trace.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ defmodule Matcha.Trace do
292292
def format_message({:trace, pid, :call, {module, function, arguments}, message}) do
293293
call = format_call(module, function, arguments, pid, message)
294294

295-
"Matcha.Trace:#{call}\n"
295+
"Matcha.Trace: #{call}\n"
296296
end
297297

298298
def format_message(term) do

Diff for: mix.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ defmodule Matcha.MixProject do
163163
{:benchee_html, "~> 1.0", only: @dev_envs, runtime: false},
164164
{:credo, "~> 1.6", only: @dev_envs, runtime: false},
165165
{:dialyxir, "~> 1.0", only: @dev_envs, runtime: false},
166-
{:erlex, "== 0.2.7-handoff",
167-
only: [:dev, :test], runtime: false, allow_pre: true, override: true},
168166
{:doctor, "~> 0.21", only: @dev_envs, runtime: false},
169167
{:ex_doc, "~> 0.29", only: @dev_envs, runtime: false},
170-
{:excoveralls, "~> 0.18", only: @dev_envs}
168+
{:excoveralls, "~> 0.18", only: @dev_envs},
169+
{:erlex, "== 0.2.7-handoff",
170+
only: [:dev, :test], runtime: false, allow_pre: true, override: true}
171171
]
172172

173173
defp docs,

Diff for: test/unit/matcha/rewrite/bodies_test.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ defmodule Matcha.Rewrite.Bodies.UnitTest do
427427
assert Spec.raw(spec) == [{{:"$1", :"$2"}, [], [{:andalso, :"$1", :"$2"}]}]
428428
end
429429

430-
if Matcha.Helpers.erlang_version() >= 25 do
430+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
431431
test "binary_part/3" do
432432
spec =
433433
spec do
@@ -461,7 +461,7 @@ defmodule Matcha.Rewrite.Bodies.UnitTest do
461461
assert Spec.raw(spec) == [{:"$1", [], [bit_size: :"$1"]}]
462462
end
463463

464-
if Matcha.Helpers.erlang_version() >= 25 do
464+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
465465
test "byte_size/1" do
466466
spec =
467467
spec do
@@ -1077,7 +1077,7 @@ defmodule Matcha.Rewrite.Bodies.UnitTest do
10771077
end
10781078
end
10791079

1080-
if Matcha.Helpers.erlang_version() >= 26 do
1080+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
10811081
# FIXME: defguard expressions not correctly expanding in match spec bodies
10821082
# describe "Record guards" do
10831083
# test "is_record/1" do

Diff for: test/unit/matcha/rewrite/guards_test.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ defmodule Matcha.Rewrite.Guards.UnitTest do
288288
]
289289
end
290290

291-
if Matcha.Helpers.erlang_version() >= 25 do
291+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
292292
test "binary_part/3" do
293293
spec =
294294
spec do
@@ -322,7 +322,7 @@ defmodule Matcha.Rewrite.Guards.UnitTest do
322322
assert Spec.raw(spec) == [{:"$1", [{:==, {:bit_size, :"$1"}, 24}], [:"$1"]}]
323323
end
324324

325-
if Matcha.Helpers.erlang_version() >= 25 do
325+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
326326
test "byte_size/1" do
327327
spec =
328328
spec do
@@ -738,7 +738,7 @@ defmodule Matcha.Rewrite.Guards.UnitTest do
738738
assert Spec.raw(spec) == [{:"$1", [{:==, {:trunc, :"$1"}, 0}], [:"$1"]}]
739739
end
740740

741-
if Matcha.Helpers.erlang_version() >= 26 do
741+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
742742
describe "Record guards" do
743743
test "is_record/1" do
744744
import Record, only: [is_record: 1]

Diff for: test/usage/elixir_guards_test.exs

+7-7
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ defmodule ElixirGuards.UsageTest do
393393
]
394394
end
395395

396-
if Matcha.Helpers.erlang_version() >= 25 do
396+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
397397
test "binary_part/3" do
398398
spec =
399399
spec do
@@ -482,7 +482,7 @@ defmodule ElixirGuards.UsageTest do
482482
assert Spec.run!(spec, ["ab", "abc", "abcd"]) == [16, 24, 32]
483483
end
484484

485-
if Matcha.Helpers.erlang_version() >= 25 do
485+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 25.0.0") do
486486
test "byte_size/1" do
487487
spec =
488488
spec do
@@ -544,7 +544,7 @@ defmodule ElixirGuards.UsageTest do
544544
end
545545
end
546546

547-
if Matcha.Helpers.erlang_version() >= 26 do
547+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
548548
test "ceil/2" do
549549
spec =
550550
spec do
@@ -680,7 +680,7 @@ defmodule ElixirGuards.UsageTest do
680680
assert Spec.run!(spec, one: :two, three: :four) == [:one, :three]
681681
end
682682

683-
if Matcha.Helpers.erlang_version() >= 26 do
683+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
684684
test "floor/2" do
685685
spec =
686686
spec do
@@ -1101,7 +1101,7 @@ defmodule ElixirGuards.UsageTest do
11011101
assert Matcha.Spec.run!(spec, [fun, :other]) == [true, false]
11021102
end
11031103

1104-
if Matcha.Helpers.erlang_version() >= 26 do
1104+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
11051105
test "is_function/2" do
11061106
fun0 = fn -> 0 end
11071107
fun1 = fn _ -> 1 end
@@ -1824,7 +1824,7 @@ defmodule ElixirGuards.UsageTest do
18241824
]
18251825
end
18261826

1827-
if Matcha.Helpers.erlang_version() >= 26 do
1827+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
18281828
test "tuple_size/2" do
18291829
spec =
18301830
spec do
@@ -1888,7 +1888,7 @@ defmodule ElixirGuards.UsageTest do
18881888
end
18891889

18901890
describe "Record guards" do
1891-
if Matcha.Helpers.erlang_version() >= 26 do
1891+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
18921892
test "is_record/1" do
18931893
import Record, only: [is_record: 1]
18941894

Diff for: test/usage/erlang_guards_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule ErlangGuards.UsageTest do
3030
# ]) == [true, false]
3131
# end
3232

33-
if Matcha.Helpers.erlang_version() >= 26 do
33+
if Version.match?(Matcha.Helpers.erlang_version(), ">= 26.0.0") do
3434
# We shadow Elixir's implementation with a replacement to make sure it works for all Erlang/OTP versions,
3535
# and will continue to do so as long as we support < 26 to simplify our code,
3636
# so it's worth testing the literal OTP 26 behaviour for when native support is available to make sure it works.

0 commit comments

Comments
 (0)