Skip to content

Commit

Permalink
Merge pull request #11 from jtendo/rebar3
Browse files Browse the repository at this point in the history
Support rebar3 + hex + R15B..19
  • Loading branch information
aerosol authored Aug 14, 2016
2 parents 15d8360 + eaea388 commit 64bd68d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.eunit
ebin
deps
priv
*.o
*.beam
rebar
_build
*.xml
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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

6 changes: 5 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -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]}.
1 change: 1 addition & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[].
9 changes: 7 additions & 2 deletions src/binpp.app.src
Original file line number Diff line number Diff line change
@@ -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"}]}
]}.
55 changes: 29 additions & 26 deletions src/binpp.erl
Original file line number Diff line number Diff line change
@@ -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').

Expand Down Expand Up @@ -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_() ->
Expand Down Expand Up @@ -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 ].
Expand All @@ -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) ],
Expand All @@ -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) ],
Expand All @@ -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
Expand Down

0 comments on commit 64bd68d

Please sign in to comment.