From 225bce9f31d99baff0ac0cc3f217f5e4bdffac43 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Sun, 4 Aug 2024 11:59:59 +0200 Subject: [PATCH] Fix version filter --- rustler_tests/lib/resource_dyncall.ex | 2 +- rustler_tests/lib/rustler_test.ex | 26 ++++++++++--------- rustler_tests/test/resource_dyncall_tests.exs | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/rustler_tests/lib/resource_dyncall.ex b/rustler_tests/lib/resource_dyncall.ex index ec289e38..d642ad9d 100644 --- a/rustler_tests/lib/resource_dyncall.ex +++ b/rustler_tests/lib/resource_dyncall.ex @@ -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, diff --git a/rustler_tests/lib/rustler_test.ex b/rustler_tests/lib/rustler_test.ex index cc10377b..f2c7b58c 100644 --- a/rustler_tests/lib/rustler_test.ex +++ b/rustler_tests/lib/rustler_test.ex @@ -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) @@ -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 diff --git a/rustler_tests/test/resource_dyncall_tests.exs b/rustler_tests/test/resource_dyncall_tests.exs index 19659004..ac2b0a18 100644 --- a/rustler_tests/test/resource_dyncall_tests.exs +++ b/rustler_tests/test/resource_dyncall_tests.exs @@ -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