Skip to content

Commit

Permalink
Fix version filter
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Aug 4, 2024
1 parent 05a86e1 commit 225bce9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rustler_tests/lib/resource_dyncall.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if System.otp_release() >= "26" do
if RustlerTest.Helper.has_nif_version("2.16") do
defmodule ResourceDyncall do
use Rustler,
otp_app: :rustler_test,
Expand Down
26 changes: 14 additions & 12 deletions rustler_tests/lib/rustler_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ defmodule NifNotLoadedError do
defexception message: "nif not loaded"
end

defmodule RustlerTest.Helper do
def nif_feature_from_running_version() do
[major, minor | _] =
:erlang.system_info(:nif_version)
|> to_string
|> String.split(".")

"nif_version_#{major}_#{minor}"
defmodule RustlerTest do
defmodule Helper do
@nif_version Version.parse!("#{:erlang.system_info(:nif_version)}.0")

def nif_feature_from_running_version() do
"nif_version_#{@nif_version.major}_#{@nif_version.minor}"
end

def has_nif_version(version) do
req = Version.parse_requirement!("~> #{version}")
Version.match?(@nif_version, req)
end
end
end

defmodule RustlerTest do
use Rustler,
otp_app: :rustler_test,
crate: :rustler_test,
features: [RustlerTest.Helper.nif_feature_from_running_version()]
features: [Helper.nif_feature_from_running_version()]

defp err, do: :erlang.nif_error(:nif_not_loaded)

Expand Down Expand Up @@ -146,7 +148,7 @@ defmodule RustlerTest do

def append_to_path(_path, _to_append), do: err()

if System.otp_release() >= "26" do
if Helper.has_nif_version("2.16") do
def perform_dyncall(_res, _a, _b, _c), do: err()
end
end
2 changes: 1 addition & 1 deletion rustler_tests/test/resource_dyncall_tests.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if System.otp_release() >= "26" do
if RustlerTest.Helper.has_nif_version("2.16") do
defmodule RustlerTest.ResourceDyncallTest do
use ExUnit.Case, async: true

Expand Down

0 comments on commit 225bce9

Please sign in to comment.