Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmetic changes to CI, rebar3 config, and types #72

Merged
merged 10 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
name: OTP ${{matrix.otp_vsn}}
strategy:
matrix:
otp_vsn: ['26.2', '25.3', '24.3']
rebar_vsn: ['3.22.0']
runs-on: 'ubuntu-22.04'
otp_vsn: ['27', '26', '25']
rebar_vsn: ['3.24.0']
runs-on: 'ubuntu-24.04'
env:
OTPVER: ${{ matrix.otp }}
steps:
Expand All @@ -23,7 +23,7 @@ jobs:
with:
otp-version: ${{ matrix.otp_vsn }}
rebar3-version: ${{ matrix.rebar_vsn }}
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache
with:
path: _build
Expand All @@ -34,8 +34,9 @@ jobs:
- run: rebar3 dialyzer
- run: rebar3 as test codecov analyze
- run: gcov -o c_src exml
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v5
with:
name: Upload coverage reports to Codecov
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ _build/
/logs/
/priv/*so
*.beam
*.lock
/rebar3
doc/
27 changes: 14 additions & 13 deletions include/exml.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
attrs = [] :: [exml:attr()],
children = [] :: [exml:element() | exml:cdata()]}).

%% Implementation of the exmlAssertEqual/2 macro is an exact copy of
%% Implementation of the exmlAssertEqual/2 macro is a modification of
%% https://github.com/erszcz/rxml/commit/e8483408663f0bc2af7896e786c1cdea2e86e43d#diff-2cb5d18741df32f4ead70c21fdd221d1
%% See assertEqual in $ERLANG/lib/stdlib-2.6/include/assert.hrl for the original.
-define(exmlAssertEqual(Example, Expr),
-define(exmlAssertEqual(Expect, Expr),
begin
((fun (__E, __V) ->
case __V of
__E -> ok;
__V -> erlang:error({exmlAssertEqual,
[{module, ?MODULE},
{line, ?LINE},
{expression, (??Expr)},
{expected, __E},
{value, __V}]})
end
end)(exml:xml_sort((Example)), exml:xml_sort((Expr))))
((fun () ->
X__X = (exml:xml_sort(Expect)),
case (exml:xml_sort(Expr)) of
X__X -> ok;
X__V -> erlang:error({exmlAssertEqual,
[{module, ?MODULE},
{line, ?LINE},
{expression, (??Expr)},
{expected, Expect},
{value, X__V}]})
end
end)())
end).

-endif.
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
]}
]}.

{project_plugins, [rebar3_ex_doc]}.
{plugins, [pc, rebar3_hex]}.
{project_plugins, [rebar3_hex, rebar3_ex_doc]}.
{plugins, [pc]}.

% Interrupt compilation, if the artifact is not found
{artifacts, ["priv/exml_nif.so"]}.
Expand Down
1 change: 1 addition & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[].
14 changes: 11 additions & 3 deletions src/exml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ xml_size(#xmlstreamstart{ name = Name, attrs = Attrs }) ->
byte_size(Name) + 2 + xml_size(Attrs);
xml_size(#xmlstreamend{ name = Name }) ->
byte_size(Name) + 3;
xml_size({Key, Value}) ->
xml_size({Key, Value}) when is_binary(Key) ->
% Attributes
byte_size(Key)
+ 4 % ="" and whitespace before
+ byte_size(Value).
Expand All @@ -66,7 +67,12 @@ xml_size({Key, Value}) ->
%% @end
%% The implementation of this function is a subtle modification of
%% https://github.com/erszcz/rxml/commit/e8483408663f0bc2af7896e786c1cdea2e86e43d
-spec xml_sort(item() | [item()]) -> item() | [item()].
-spec xml_sort([item()]) -> [item()];
(element()) -> element();
(attr()) -> attr();
(cdata()) -> cdata();
(exml_stream:start()) -> exml_stream:start();
(exml_stream:stop()) -> exml_stream:stop().
xml_sort(#xmlcdata{} = Cdata) ->
Cdata;
xml_sort(#xmlel{ attrs = Attrs, children = Children } = El) ->
Expand All @@ -78,6 +84,8 @@ xml_sort(#xmlstreamstart{ attrs = Attrs } = StreamStart) ->
StreamStart#xmlstreamstart{ attrs = lists:sort(Attrs) };
xml_sort(#xmlstreamend{} = StreamEnd) ->
StreamEnd;
xml_sort({Key, Value}) ->
{Key, Value};
xml_sort(Elements) when is_list(Elements) ->
lists:sort([ xml_sort(E) || E <- Elements ]).

Expand All @@ -102,7 +110,7 @@ to_pretty_iolist(Element) ->
to_iolist(Element, pretty).

%% @doc Parses a binary or a list of binaries into an XML `t:element()'.
-spec parse(binary() | [binary()]) -> {ok, exml:element()} | {error, any()}.
-spec parse(binary() | [binary()]) -> {ok, element()} | {error, any()}.
parse(XML) ->
exml_nif:parse(XML).

Expand Down
12 changes: 9 additions & 3 deletions src/exml_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
load() ->
PrivDir = case code:priv_dir(?MODULE) of
{error, _} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
case code:which(?MODULE) of
Path when is_list(Path) ->
EbinDir = filename:dirname(Path),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
_ ->
%% cover_compiled | preloaded | non_existing
erlang:error({cannot_get_load_path, ?MODULE})
end;
Path ->
Path
end,
Expand Down
2 changes: 1 addition & 1 deletion src/exml_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ path(Element, Path) ->
%% '''
%% will return `<<"Message from bob to alice">>'
%% @end
-spec path(exml:element(), path(), Default) -> exml:element() | binary() | Default.
-spec path(exml:element() | undefined, path(), Default) -> exml:element() | binary() | Default.
path(#xmlel{} = Element, [], _) ->
Element;
path(#xmlel{} = Element, [{element, Name} | Rest], Default) ->
Expand Down
4 changes: 2 additions & 2 deletions test/exml_properties_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("exml.hrl").
-compile(export_all).

-compile([export_all, nowarn_export_all]).

p(Name, Property) ->
?assert(proper:quickcheck
Expand Down
2 changes: 1 addition & 1 deletion test/exml_stream_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-include("exml_stream.hrl").
-include_lib("eunit/include/eunit.hrl").

-compile(export_all).
-compile([export_all, nowarn_export_all]).

basic_parse_test() ->
{ok, Parser0} = exml_stream:new_parser(),
Expand Down
9 changes: 7 additions & 2 deletions test/exml_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-include_lib("exml/include/exml.hrl").
-include_lib("exml/include/exml_stream.hrl").

-compile(export_all).
-compile([export_all, nowarn_export_all]).

application_test() ->
?assertEqual(ok, application:start(exml)),
Expand All @@ -40,6 +40,11 @@ sort_xmlel_identity_test() ->
},
?assertEqual(El, exml:xml_sort(El)).

sort_xmlel_attributes_test() ->
Attrs = [{<<"attr1">>, <<"foo">>}, {<<"attr2">>, <<"bar">>}],
ToOrder = [{<<"attr2">>, <<"bar">>}, {<<"attr1">>, <<"foo">>}],
?assertEqual(Attrs, exml:xml_sort(ToOrder)).

sort_xmlel_test() ->
Attrs = [{<<"attr1">>, <<"bar">>}, {<<"attr2">>, <<"baz">>}],
El1 = #xmlel{
Expand Down Expand Up @@ -107,7 +112,7 @@ assert_xmlel_equal_macro_positive_test() ->
children = [#xmlcdata{ content = <<"some value">> }]
},
El2 = El1#xmlel{ attrs = lists:reverse(Attrs) },
?assertEqual(ok, ?exmlAssertEqual(El1, El2)).
?exmlAssertEqual(El1, El2).

assert_xmlel_equal_macro_negative_test() ->
El1 = #xmlel{
Expand Down