From 290db92828f3d572c88e616cdd7d1e5925d96220 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Sun, 14 Aug 2016 21:29:04 +0200 Subject: [PATCH 1/4] Support rebar3 and latest OTP releases --- .gitignore | 3 ++- .travis.yml | 11 +++++++++-- rebar.config | 4 +++- rebar.lock | 1 + src/binpp.erl | 40 +++++++++++++++++++++++++++++----------- 5 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 rebar.lock diff --git a/.gitignore b/.gitignore index 7ee715c..6cccf4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .eunit -ebin deps priv *.o *.beam rebar +_build +*.xml diff --git a/.travis.yml b/.travis.yml index 5caa932..7e18237 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,12 @@ language: erlang + otp_release: - - R15B02 - - R15B01 - R15B + - R16B03 + - 17.0 + - 18.0 + - 19.0 + +install: wget https://s3.amazonaws.com/rebar3/rebar3 && chmod 755 rebar3 + +script: ./rebar3 eunit diff --git a/rebar.config b/rebar.config index 6327de4..bb7c023 100644 --- a/rebar.config +++ b/rebar.config @@ -1,4 +1,6 @@ -{erl_opts, [warnings_as_errors]}. +{erl_opts,[warnings_as_errors, + {platform_define, "^(19|2)", rand_only} + ]}. {cover_enabled, true}. {cover_print_enabled, true}. diff --git a/rebar.lock b/rebar.lock new file mode 100644 index 0000000..57afcca --- /dev/null +++ b/rebar.lock @@ -0,0 +1 @@ +[]. diff --git a/src/binpp.erl b/src/binpp.erl index a3d0033..50ade98 100644 --- a/src/binpp.erl +++ b/src/binpp.erl @@ -217,8 +217,24 @@ buckets(X, N, M, [H|T], [A|Acc]) -> -define(MAX_BIN_SIZE, 2048). -define(RUNS, 100). +-ifdef(rand_only). +-define(random, rand). +-else. +-define(random, random). +-endif. + +-ifdef(rand_only). +random_seed() -> + %% the rand module self-seeds + ok. +-else. +random_seed() -> + <> = crypto:rand_bytes(12), + random:seed({A,B,C}). +-endif. + setup_random() -> - _ = random:seed(erlang:now()), + _ = random_seed(), ok. binpp_random_test_() -> @@ -345,20 +361,22 @@ convert_bin_test_() -> rand_pprint() -> F = fun pprint/1, - Tests = [ { crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)), ok } || _ <- lists:seq(1, ?RUNS) ], + Tests = [ { crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)), ok } || _ <- lists:seq(1, ?RUNS) ], [ { <<"Random pprint">>, fun() -> ?assertEqual(R, F(I)) end } || { I, R } <- Tests ]. rand_pprint_bitstring() -> F = fun pprint/1, - Tests = [ { << (crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)))/binary, 0:(random:uniform(7))>>, ok } + Tests = [ { << + (crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)))/binary, + 0:(?random:uniform(7))>>, ok } || _ <- lists:seq(1, ?RUNS) ], [ { <<"Random pprint (bitstring)">>, fun() -> ?assertEqual(R, F(I)) end } || { I, R } <- Tests ]. rand_compare() -> F = fun compare/2, - Rand = fun() -> crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)) end, + Rand = fun() -> crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)) end, Tests = [ { { Rand(), Rand() }, ok } || _ <- lists:seq(1, ?RUNS) ], [ { <<"Random compare">>, fun() -> ?assertEqual(R, F(I1, I2)) end } || { {I1, I2}, R } <- Tests ]. @@ -375,8 +393,8 @@ rand_pprint_opts() -> ], Range = length(OptsMap), Rand = fun() -> - Input = crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)), - {Opt, Predicate} = lists:nth(random:uniform(Range), OptsMap), + Input = crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)), + {Opt, Predicate} = lists:nth(?random:uniform(Range), OptsMap), {Input, Opt, Predicate} end, Tests = [ Rand() || _ <- lists:seq(1, ?RUNS) ], @@ -388,9 +406,9 @@ rand_pprint_opts() -> rand_pprint_slice() -> F = fun pprint/3, Rand = fun() -> - Bytes = crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)), - Pos = random:uniform(byte_size(Bytes)), - Len = random:uniform(byte_size(Bytes)), + Bytes = crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)), + Pos = ?random:uniform(byte_size(Bytes)), + Len = ?random:uniform(byte_size(Bytes)), {Bytes, Pos, Len} end, Tests = [ Rand() || _ <- lists:seq(1, ?RUNS) ], @@ -403,9 +421,9 @@ rand_pprint_slice() -> rand_from_str() -> F = fun from_str/1, Rand = fun() -> - Bytes = crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)), + Bytes = crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)), {ok, Converted} = convert(Bytes), - case random:uniform(2) of + case ?random:uniform(2) of 1 -> {lists:flatten(Converted), Bytes}; 2 -> {string:join(Converted, " "), Bytes} end From 6e7409cdbbf3d844bf5ce262d569b70368185324 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Sun, 14 Aug 2016 22:30:36 +0200 Subject: [PATCH 2/4] Bump version (1.1.1) --- src/binpp.app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/binpp.app.src b/src/binpp.app.src index d919bb3..a9d6d55 100644 --- a/src/binpp.app.src +++ b/src/binpp.app.src @@ -1,6 +1,6 @@ {application, binpp, [ {description, "Erlang Binary Pretty Printer"}, - {vsn, "1.1"}, + {vsn, "1.1.1"}, {registered, []}, {applications, [kernel, stdlib]} ]}. From d3f45a42ded2bb1745ed1e249409548aa555d76c Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Sun, 14 Aug 2016 22:35:01 +0200 Subject: [PATCH 3/4] Update package metadata --- LICENSE | 13 +++++++++++++ src/binpp.app.src | 7 ++++++- src/binpp.erl | 15 --------------- 3 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d904692 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + +Copyright (C) 2011 Adam Rutkowski + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + diff --git a/src/binpp.app.src b/src/binpp.app.src index a9d6d55..ea78873 100644 --- a/src/binpp.app.src +++ b/src/binpp.app.src @@ -2,5 +2,10 @@ {description, "Erlang Binary Pretty Printer"}, {vsn, "1.1.1"}, {registered, []}, - {applications, [kernel, stdlib]} + {applications, [kernel, stdlib]}, + {env, []}, + {modules, []}, + {maintainers, ["Adam Rutkowski"]}, + {licenses, ["WTFPL"]}, + {links, [{"Github", "https://github.com/jtendo/binpp"}]} ]}. diff --git a/src/binpp.erl b/src/binpp.erl index 50ade98..ec5f8cf 100644 --- a/src/binpp.erl +++ b/src/binpp.erl @@ -1,19 +1,4 @@ -%%% -%%% DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -%%% Version 2, December 2004 -%%% -%%% Copyright (C) 2011 Adam Rutkowski -%%% -%%% Everyone is permitted to copy and distribute verbatim or modified -%%% copies of this license document, and changing it is allowed as long -%%% as the name is changed. -%%% -%%% DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -%%% TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -%%% - %% @doc Pretty printer for Erlang binaries. -%% -module(binpp). -author('Adam Rutkowski hq@mtod.org'). From eaea3887c6c4b916940f7f21bc7f6b7c3066e8b5 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Sun, 14 Aug 2016 22:37:18 +0200 Subject: [PATCH 4/4] Add rebar3_hex plugin --- rebar.config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rebar.config b/rebar.config index bb7c023..bf625a8 100644 --- a/rebar.config +++ b/rebar.config @@ -6,3 +6,5 @@ {cover_print_enabled, true}. {eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}. + +{plugins, [rebar3_hex]}.