Skip to content
Open
Changes from all 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
Fix compatiblity for versions >= 1.14.2
  • Loading branch information
Szymon Mentel committed Jan 26, 2023
commit 99e3f847d17ba282e83d9d5ee0d35245085cc609
49 changes: 30 additions & 19 deletions lib/test_iex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,45 @@ defmodule TestIex do
end

Code.load_file(path)

if v6_or_higher?() do
ExUnit.Server.modules_loaded()
else
ExUnit.Server.cases_loaded()
end

load_modules()
ExUnit.run()
end

def test(paths, _line) when is_list(paths) do
ExUnit.configure(exclude: [], include: [])

Enum.map(paths, &Code.load_file/1)
load_modules()
ExUnit.run()
end

if v6_or_higher?() do
ExUnit.Server.modules_loaded()
else
ExUnit.Server.cases_loaded()
end
defp load_modules() do
cond do
# 1.14.2 [1]introduces the changes from the commit [2]
# [1]: https://github.com/elixir-lang/elixir/commit/0909940b04a3e22c9ea4fedafa2aac349717011c
# [2]: https://github.com/elixir-lang/elixir/commit/83b2a3d91f8888dd1493f64677467fae65450a0d#
version_eq_than?(1, 14, 2) ->
ExUnit.Server.modules_loaded(false)

ExUnit.run()
version_eq_than?(1, 6, 0) ->
ExUnit.Server.modules_loaded()

true ->
ExUnit.Server.cases_loaded()
end
end

defp v6_or_higher?() do
System.version()
|> String.split(".")
|> Enum.at(1)
|> String.to_integer() >= 6
defp version_eq_than?(1, minor, patch) do
Copy link
Owner

Choose a reason for hiding this comment

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

@mentels I appreciate the PR and the comments.

As a testing library, would you be able to add a couple of tests for this?

"1." <> minor_dot_patch_maybe_dash_reminder = System.version()
# examples of the major_dot_patch_maybe_dash_reminder:
# - 14.3
# - 15.0-dev
[_full_match, minor_actual, patch_actual | _] =
Regex.run(~r/(\d+)\.(\d+).*/, minor_dot_patch_maybe_dash_reminder)

cond do
minor_actual > minor -> true
minor_actual == minor and patch_actual >= patch -> true
true -> false
end
end
end