Skip to content

Commit

Permalink
dev-erlang/fast_xml: Fix unit tests
Browse files Browse the repository at this point in the history
Package-Manager: Portage-2.3.3, Repoman-2.3.1
  • Loading branch information
aidecoe committed Jan 2, 2017
1 parent 883a623 commit 90b8929
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dev-erlang/fast_xml/fast_xml-1.1.18.ebuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 1999-2016 Gentoo Foundation
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

Expand All @@ -23,3 +23,5 @@ DEPEND="${RDEPEND}
test? ( >=dev-lang/elixir-1.1 )"

DOCS=( CHANGELOG.md README.md )

PATCHES=( "${FILESDIR}"/${PV}-0001-Fix-unittests.patch )
92 changes: 92 additions & 0 deletions dev-erlang/fast_xml/files/1.1.18-0001-Fix-unittests.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
From 4b65d1603c9b16cf440e0b434673de9d7bdca6b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= <[email protected]>
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

0 comments on commit 90b8929

Please sign in to comment.