Skip to content

Commit

Permalink
Add GH Actions CI and fix tests on Erlang 27
Browse files Browse the repository at this point in the history
Add CI for Windows, MacOS and Ubuntu Linux. For Linux, test both rebar2 and
rebar3.

Apparently due to `string:split/2` in `rebar.config.script` jiffy wasn't
compatible with Erlang <20 for quite a now, and we didn't see any complaints,
so make Erlang 20 the minimum supported version. Old jiffy releases are still
available for anyone who needs them. In addition, only Erlang OTP docker images
20+ work with the latest (v4) checkout CI action, so that's another reason to
make that the new cutoff.

On Erlang 27 needed to make a few test updates:

 * The referenced binary length size computation changed so make sure to make
   the binaries large enough to avoid triggering the inconsistencies between
   <27 and 27+ version and needing to do an ifdef of some sort.

 * In Erlang 27 -0.0 =/= 0.0 so updated a few tests expecting exact comparison,
   to use numeric equality `=`. Jiffy doesn't round-trip -0.0s anyway, so it's
   only a test-side discrepancy.
  • Loading branch information
nickva authored and davisp committed Jun 8, 2024
1 parent 9ea1b35 commit 2de9792
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 92 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: ci

on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
linux:
name: ${{matrix.os}}-${{matrix.otp_version}}-${{matrix.rebar}}
runs-on: ${{matrix.os}}

strategy:
fail-fast: false
matrix:
otp_version: [20,23,26,27]
os: [ubuntu-latest]
rebar: [rebar, rebar3]

container:
image: erlang:${{matrix.otp_version}}

steps:
- uses: actions/checkout@v4
- name: ${{matrix.rebar}} make check
run: |
make REBAR=${{matrix.rebar}} check
macos:
name: macos
runs-on: ${{matrix.os}}

strategy:
fail-fast: false
matrix:
os: [macos-12, macos-14]

steps:
- uses: actions/checkout@v4
- name: install erlang
run: |
brew install erlang
- name: install rebar3
run: |
brew install rebar3
- name: make check
run: |
make check
windows:
name: windows
runs-on: ${{matrix.os}}

strategy:
fail-fast: false
matrix:
os: [windows-2019, windows-2022]

steps:
- name: prevent git from messing up our json test files
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v4
- name: install erlang
run: |
choco install erlang
- name: install rebar3
run: |
choco install rebar3
- name: make check
run: |
$path = vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -nologo -nocolor -property installationPath
if ($path) {
$path = join-path $path '\VC\Auxiliary\Build\vcvars64.bat'
if (test-path $path) {
cmd /s /c """$path"" $args && set" | where { $_ -match '(\w+)=(.*)' } | foreach {
$null = new-item -force -path "Env:\$($Matches[1])" -value $Matches[2]
}
}
}
make check
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions c_src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,9 @@ dec_number(Decoder* d, ERL_NIF_TERM* value)
ERL_NIF_TERM
make_empty_object(ErlNifEnv* env, int ret_map)
{
#if MAP_TYPE_PRESENT
if(ret_map) {
return enif_make_new_map(env);
}
#endif

return enif_make_tuple1(env, enif_make_list(env, 0));
}
Expand Down Expand Up @@ -680,11 +678,7 @@ decode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
} else if(get_bytes_per_red(env, val, &(d->bytes_per_red))) {
continue;
} else if(enif_is_identical(val, d->atoms->atom_return_maps)) {
#if MAP_TYPE_PRESENT
d->return_maps = 1;
#else
return enif_make_badarg(env);
#endif
} else if(enif_is_identical(val, d->atoms->atom_return_trailer)) {
d->return_trailer = 1;
} else if(enif_is_identical(val, d->atoms->atom_dedupe_keys)) {
Expand Down
4 changes: 0 additions & 4 deletions c_src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ enc_comma(Encoder* e)
return 1;
}

#if MAP_TYPE_PRESENT
int
enc_map_to_ejson(ErlNifEnv* env, ERL_NIF_TERM map, ERL_NIF_TERM* out)
{
Expand Down Expand Up @@ -636,7 +635,6 @@ enc_map_to_ejson(ErlNifEnv* env, ERL_NIF_TERM map, ERL_NIF_TERM* out)
*out = enif_make_tuple1(env, list);
return 1;
}
#endif

ERL_NIF_TERM
encode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
Expand Down Expand Up @@ -897,15 +895,13 @@ encode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
termstack_push(&stack, curr);
termstack_push(&stack, e->atoms->ref_object);
termstack_push(&stack, tuple[1]);
#if MAP_TYPE_PRESENT
} else if(enif_is_map(env, curr)) {
if(!enc_map_to_ejson(env, curr, &curr)) {
ret = enc_error(e, "internal_error");
goto done;
}

termstack_push(&stack, curr);
#endif
} else if(enif_is_list(env, curr)) {
if(!enc_start_array(e)) {
ret = enc_error(e, "internal_error");
Expand Down
4 changes: 0 additions & 4 deletions c_src/jiffy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#define DEFAULT_BYTES_PER_REDUCTION 20
#define DEFAULT_ERLANG_REDUCTION_COUNT 2000

#define MAP_TYPE_PRESENT \
((ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION >= 6) \
|| (ERL_NIF_MAJOR_VERSION > 2))

#define CONSUME_TIMESLICE_PRESENT \
((ERL_NIF_MAJOR_VERSION >= 2 && ERL_NIF_MINOR_VERSION >= 4))

Expand Down
7 changes: 0 additions & 7 deletions c_src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

#include "erl_nif.h"

#define MAP_TYPE_PRESENT \
((ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION >= 6) \
|| (ERL_NIF_MAJOR_VERSION > 2))

#define BEGIN_C extern "C" {
#define END_C }

Expand All @@ -27,8 +23,6 @@ make_object(ErlNifEnv* env, ERL_NIF_TERM pairs, ERL_NIF_TERM* out,

std::set<std::string> seen;

#if MAP_TYPE_PRESENT

ERL_NIF_TERM old_val;

if(ret_map) {
Expand All @@ -46,7 +40,6 @@ make_object(ErlNifEnv* env, ERL_NIF_TERM pairs, ERL_NIF_TERM* out,
*out = ret;
return 1;
}
#endif

ret = enif_make_list(env, 0);
while(enif_get_list_cell(env, pairs, &val, &pairs)) {
Expand Down
12 changes: 0 additions & 12 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,9 @@
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
"LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++"},

%% OS X Leopard flags for 64-bit
{"darwin9.*-64$", "CXXFLAGS", "-m64"},
{"darwin9.*-64$", "LDFLAGS", "-arch x86_64"},

%% OS X Snow Leopard flags for 32-bit
{"darwin10.*-32$", "CXXFLAGS", "-m32"},
{"darwin10.*-32$", "LDFLAGS", "-arch i386"},

{"win32", "CXXFLAGS", "$CXXFLAGS /O2 /DNDEBUG"}
]}.

{erl_opts, [
{platform_define, "R1(1|2|3|4|5|6)", 'JIFFY_NO_MAPS'}
]}.

{eunit_opts, [
verbose
]}.
7 changes: 5 additions & 2 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ case IsRebar2 of
Config2;
false ->
Config2 ++ [
{plugins, [{pc, "~> 1.0"}]},
{artifacts, ["priv/jiffy.so"]},
{plugins, [{pc, "~> 1.15"}]},
case os:type() of
{win32, _} -> {artifacts, ["priv/jiffy.dll"]};
{_, _} -> {artifacts, ["priv/jiffy.so"]}
end,
{provider_hooks, [
{post, [
{compile, {pc, compile}},
Expand Down
13 changes: 0 additions & 13 deletions src/jiffy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,9 @@
-type json_string() :: atom() | binary().
-type json_number() :: integer() | float().

-ifdef(JIFFY_NO_MAPS).

-type json_object() :: {[{json_string(),json_value()}]}.

-else.

-type json_object() :: {[{json_string(),json_value()}]}
| #{json_string() => json_value()}.

-endif.

-type jiffy_decode_result() :: json_value()
| {has_trailer, json_value(), binary()}.

Expand Down Expand Up @@ -141,18 +133,13 @@ finish_decode({has_trailer, Value, Rest}) ->
finish_decode(Val) ->
maybe_map(Val).

-ifndef(JIFFY_NO_MAPS).
maybe_map(Obj) when is_map(Obj) ->
maps:map(fun finish_decode_map/2, Obj);
maybe_map(Val) ->
Val.

finish_decode_map(_, V) ->
finish_decode(V).
-else.
maybe_map(Val) ->
Val.
-endif.

finish_decode_obj([], Acc) ->
{lists:reverse(Acc)};
Expand Down
5 changes: 0 additions & 5 deletions src/jiffy_utf8.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ fix(Bin) when is_binary(Bin) ->
fix(Val) ->
maybe_map(Val).

-ifndef(JIFFY_NO_MAPS).
maybe_map(Obj) when is_map(Obj) ->
maps:fold(fun fix_map/3, maps:new(), Obj);
maybe_map(Val) ->
Val.

fix_map(K, V, Acc) ->
maps:put(fix(K), fix(V), Acc).
-else.
maybe_map(Val) ->
Val.
-endif.

fix_props([], Acc) ->
{lists:reverse(Acc)};
Expand Down
4 changes: 2 additions & 2 deletions test/jiffy_03_number_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ gen(error, J) ->
gen(floats, F) ->
NegF = -1.0 * F,
{msg("float round trip - ~p", [F]), [
{"Pos", ?_assertEqual(F, dec(enc(F)))},
{"Neg", ?_assertEqual(NegF, dec(enc(NegF)))}
{"Pos", ?_assert(F == dec(enc(F)))},
{"Neg", ?_assert(NegF == dec(enc(NegF)))}
]}.


Expand Down
17 changes: 1 addition & 16 deletions test/jiffy_11_property_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ property_test_() ->
run(prop_dec_trailer),
run(prop_enc_no_crash),
run(prop_dec_no_crash_bin),
run(prop_dec_no_crash_any)
] ++ map_props().


-ifndef(JIFFY_NO_MAPS).
map_props() ->
[
run(prop_dec_no_crash_any),
run(prop_map_enc_dec)
].
-else.
map_props() ->
[].
-endif.


prop_enc_dec() ->
?FORALL(Data, json(), begin
Expand Down Expand Up @@ -63,15 +52,13 @@ prop_enc_dec_pretty() ->
).


-ifndef(JIFFY_NO_MAPS).
prop_map_enc_dec() ->
?FORALL(Data, json(),
begin
MapData = to_map_ejson(Data),
MapData == jiffy:decode(jiffy:encode(MapData), [return_maps])
end
).
-endif.


prop_enc_no_crash() ->
Expand Down Expand Up @@ -115,15 +102,13 @@ run(Name) ->
]}.


-ifndef(JIFFY_NO_MAPS).
to_map_ejson({Props}) ->
NewProps = [{K, to_map_ejson(V)} || {K, V} <- Props],
maps:from_list(NewProps);
to_map_ejson(Vals) when is_list(Vals) ->
[to_map_ejson(V) || V <- Vals];
to_map_ejson(Val) ->
Val.
-endif.


% Random any term generation
Expand Down
4 changes: 0 additions & 4 deletions test/jiffy_15_return_trailer_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ trailer_test_() ->
?_assertEqual(Result, jiffy:decode(Data, Opts))
end, Cases)}.

-ifndef(JIFFY_NO_MAPS).

trailer_bignum_test() ->
Opts = [return_maps, return_trailer],
Data = <<"{\"amount\":-50000000000000000000}{}">>,
Obj = #{<<"amount">> => -50000000000000000000},
Expect = {has_trailer, Obj, <<"{}">>},
?assertEqual(Expect, jiffy:decode(Data, Opts)).

-endif.
8 changes: 4 additions & 4 deletions test/jiffy_17_copy_strings_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ check_binaries(_Bin) ->
copy_strings_test_() ->
Opts = [copy_strings],
Cases = [
<<"\"foo\"">>,
<<"[\"bar\"]">>,
<<"{\"foo\":\"bar\"}">>,
<<"{\"foo\":[\"bar\"]}">>
<<"\"xoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\"">>,
<<"[\"yoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\"]">>,
<<"{\"zoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\":\"woooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\"}">>,
<<"{\"koooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\":[\"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\"]}">>
],
{"Test copy_strings", lists:map(fun(Json) ->
EJson = jiffy:decode(Json, Opts),
Expand Down

0 comments on commit 2de9792

Please sign in to comment.