From 4b65d1603c9b16cf440e0b434673de9d7bdca6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Mon, 2 Jan 2017 10:58:33 +0100 Subject: [PATCH] Load locally build .so file when performing tests This should help with issue #19 and #20 --- src/fxml.erl | 5 ++++- src/fxml_stream.erl | 11 +++++++---- test/fxml_test.erl | 6 ++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/fxml.erl b/src/fxml.erl index 935bf28..ed6e535 100644 --- a/src/fxml.erl +++ b/src/fxml.erl @@ -36,7 +36,7 @@ append_subtags/2, get_path_s/2, replace_tag_attr/3, replace_subtag/2, to_xmlel/1]). --export([load_nif/0]). +-export([load_nif/0, load_nif/1]). -include("fxml.hrl"). -export_type([xmlel/0]). @@ -44,6 +44,9 @@ %% Replace element_to_binary/1 with NIF load_nif() -> SOPath = p1_nif_utils:get_so_path(?MODULE, [fast_xml], "fxml"), + load_nif(SOPath). + +load_nif(SOPath) -> case catch erlang:load_nif(SOPath, 0) of ok -> ok; Err -> error_logger:warning_msg("unable to load fxml NIF: ~p~n", [Err]), diff --git a/src/fxml_stream.erl b/src/fxml_stream.erl index a2fcb01..ee1a949 100644 --- a/src/fxml_stream.erl +++ b/src/fxml_stream.erl @@ -30,7 +30,7 @@ -export([new/1, new/2, new/3, parse/2, close/1, reset/1, change_callback_pid/2, parse_element/1]). --export([load_nif/0]). +-export([load_nif/0, load_nif/1]). -include("fxml.hrl"). @@ -54,13 +54,16 @@ -export_type([xml_stream_state/0, xml_stream_el/0]). load_nif() -> - NifFile = p1_nif_utils:get_so_path(?MODULE, [fast_xml], "fxml_stream"), - case erlang:load_nif(NifFile, 0) of + SOPath = p1_nif_utils:get_so_path(?MODULE, [fast_xml], "fxml_stream"), + load_nif(SOPath). + +load_nif(SOPath) -> + case erlang:load_nif(SOPath, 0) of ok -> ok; {error, {Reason, Txt}} -> error_logger:error_msg("failed to load NIF ~s: ~s", - [NifFile, Txt]), + [SOPath, Txt]), {error, Reason} end. diff --git a/test/fxml_test.erl b/test/fxml_test.erl index e41a3dc..0bd2f91 100644 --- a/test/fxml_test.erl +++ b/test/fxml_test.erl @@ -39,7 +39,8 @@ close(State) -> ?assertEqual(true, fxml_stream:close(State)). start_test() -> - ?assertEqual(ok, application:start(fast_xml)). + ?assertEqual(ok, fxml:load_nif(p1_nif_utils:get_so_path(fxml, [], "fxml"))), + ?assertEqual(ok, fxml_stream:load_nif(p1_nif_utils:get_so_path(fxml_stream, [], "fxml_stream"))). tag_test() -> ?assertEqual(#xmlel{name = <<"root">>}, @@ -877,6 +878,3 @@ rpc_empty_response_test() -> Result = {response, []}, ?assertEqual({ok, Result}, fxmlrpc:decode(Response)), ?assertEqual(Response, fxmlrpc:encode(Result)). - -application_stop_test() -> - ?assertEqual(ok, application:stop(fast_xml)). -- 2.11.0