Permalink
Browse files

Merge pull request #11 from jtendo/rebar3

Support rebar3 + hex + R15B..19
  • Loading branch information...
2 parents 15d8360 + eaea388 commit 64bd68d215d1a6cd35871e7c134d7fe2e46214ea @aerosol aerosol committed on GitHub Aug 14, 2016
Showing with 66 additions and 32 deletions.
  1. +2 −1 .gitignore
  2. +9 −2 .travis.yml
  3. +13 −0 LICENSE
  4. +5 −1 rebar.config
  5. +1 −0 rebar.lock
  6. +7 −2 src/binpp.app.src
  7. +29 −26 src/binpp.erl
View
@@ -1,7 +1,8 @@
.eunit
-ebin
deps
priv
*.o
*.beam
rebar
+_build
+*.xml
View
@@ -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
View
13 LICENSE
@@ -0,0 +1,13 @@
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+Copyright (C) 2011 Adam Rutkowski <hq@mtod.org>
+
+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
+
View
@@ -1,6 +1,10 @@
-{erl_opts, [warnings_as_errors]}.
+{erl_opts,[warnings_as_errors,
+ {platform_define, "^(19|2)", rand_only}
+ ]}.
{cover_enabled, true}.
{cover_print_enabled, true}.
{eunit_opts, [verbose,
{report, {eunit_surefire, [{dir, "."}]}}]}.
+
+{plugins, [rebar3_hex]}.
View
@@ -0,0 +1 @@
+[].
View
@@ -1,6 +1,11 @@
{application, binpp, [
{description, "Erlang Binary Pretty Printer"},
- {vsn, "1.1"},
+ {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"}]}
]}.
View
@@ -1,19 +1,4 @@
-%%%
-%%% DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-%%% Version 2, December 2004
-%%%
-%%% Copyright (C) 2011 Adam Rutkowski <hq@mtod.org>
-%%%
-%%% 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').
@@ -217,8 +202,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() ->
+ <<A:32, B:32, C:32>> = crypto:rand_bytes(12),
+ random:seed({A,B,C}).
+-endif.
+
setup_random() ->
- _ = random:seed(erlang:now()),
+ _ = random_seed(),
ok.
binpp_random_test_() ->
@@ -345,20 +346,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 +378,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 +391,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 +406,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

0 comments on commit 64bd68d

Please sign in to comment.