Skip to content

Commit 64bd68d

Browse files
authored
Merge pull request #11 from jtendo/rebar3
Support rebar3 + hex + R15B..19
2 parents 15d8360 + eaea388 commit 64bd68d

File tree

7 files changed

+66
-32
lines changed

7 files changed

+66
-32
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.eunit
2-
ebin
32
deps
43
priv
54
*.o
65
*.beam
76
rebar
7+
_build
8+
*.xml

.travis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
language: erlang
2+
23
otp_release:
3-
- R15B02
4-
- R15B01
54
- R15B
5+
- R16B03
6+
- 17.0
7+
- 18.0
8+
- 19.0
9+
10+
install: wget https://s3.amazonaws.com/rebar3/rebar3 && chmod 755 rebar3
11+
12+
script: ./rebar3 eunit

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3+
Version 2, December 2004
4+
5+
Copyright (C) 2011 Adam Rutkowski <[email protected]>
6+
7+
Everyone is permitted to copy and distribute verbatim or modified
8+
copies of this license document, and changing it is allowed as long
9+
as the name is changed.
10+
11+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13+

rebar.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
{erl_opts, [warnings_as_errors]}.
1+
{erl_opts,[warnings_as_errors,
2+
{platform_define, "^(19|2)", rand_only}
3+
]}.
24

35
{cover_enabled, true}.
46
{cover_print_enabled, true}.
57
{eunit_opts, [verbose,
68
{report, {eunit_surefire, [{dir, "."}]}}]}.
9+
10+
{plugins, [rebar3_hex]}.

rebar.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[].

src/binpp.app.src

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{application, binpp, [
22
{description, "Erlang Binary Pretty Printer"},
3-
{vsn, "1.1"},
3+
{vsn, "1.1.1"},
44
{registered, []},
5-
{applications, [kernel, stdlib]}
5+
{applications, [kernel, stdlib]},
6+
{env, []},
7+
{modules, []},
8+
{maintainers, ["Adam Rutkowski"]},
9+
{licenses, ["WTFPL"]},
10+
{links, [{"Github", "https://github.com/jtendo/binpp"}]}
611
]}.

src/binpp.erl

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
%%%
2-
%%% DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3-
%%% Version 2, December 2004
4-
%%%
5-
%%% Copyright (C) 2011 Adam Rutkowski <[email protected]>
6-
%%%
7-
%%% Everyone is permitted to copy and distribute verbatim or modified
8-
%%% copies of this license document, and changing it is allowed as long
9-
%%% as the name is changed.
10-
%%%
11-
%%% DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12-
%%% TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13-
%%%
14-
151
%% @doc Pretty printer for Erlang binaries.
16-
%%
172
-module(binpp).
183
-author('Adam Rutkowski [email protected]').
194

@@ -217,8 +202,24 @@ buckets(X, N, M, [H|T], [A|Acc]) ->
217202
-define(MAX_BIN_SIZE, 2048).
218203
-define(RUNS, 100).
219204

205+
-ifdef(rand_only).
206+
-define(random, rand).
207+
-else.
208+
-define(random, random).
209+
-endif.
210+
211+
-ifdef(rand_only).
212+
random_seed() ->
213+
%% the rand module self-seeds
214+
ok.
215+
-else.
216+
random_seed() ->
217+
<<A:32, B:32, C:32>> = crypto:rand_bytes(12),
218+
random:seed({A,B,C}).
219+
-endif.
220+
220221
setup_random() ->
221-
_ = random:seed(erlang:now()),
222+
_ = random_seed(),
222223
ok.
223224

224225
binpp_random_test_() ->
@@ -345,20 +346,22 @@ convert_bin_test_() ->
345346

346347
rand_pprint() ->
347348
F = fun pprint/1,
348-
Tests = [ { crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)), ok } || _ <- lists:seq(1, ?RUNS) ],
349+
Tests = [ { crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)), ok } || _ <- lists:seq(1, ?RUNS) ],
349350
[ { <<"Random pprint">>, fun() -> ?assertEqual(R, F(I)) end }
350351
|| { I, R } <- Tests ].
351352

352353
rand_pprint_bitstring() ->
353354
F = fun pprint/1,
354-
Tests = [ { << (crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)))/binary, 0:(random:uniform(7))>>, ok }
355+
Tests = [ { <<
356+
(crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)))/binary,
357+
0:(?random:uniform(7))>>, ok }
355358
|| _ <- lists:seq(1, ?RUNS) ],
356359
[ { <<"Random pprint (bitstring)">>, fun() -> ?assertEqual(R, F(I)) end }
357360
|| { I, R } <- Tests ].
358361

359362
rand_compare() ->
360363
F = fun compare/2,
361-
Rand = fun() -> crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)) end,
364+
Rand = fun() -> crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)) end,
362365
Tests = [ { { Rand(), Rand() }, ok } || _ <- lists:seq(1, ?RUNS) ],
363366
[ { <<"Random compare">>, fun() -> ?assertEqual(R, F(I1, I2)) end }
364367
|| { {I1, I2}, R } <- Tests ].
@@ -375,8 +378,8 @@ rand_pprint_opts() ->
375378
],
376379
Range = length(OptsMap),
377380
Rand = fun() ->
378-
Input = crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)),
379-
{Opt, Predicate} = lists:nth(random:uniform(Range), OptsMap),
381+
Input = crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)),
382+
{Opt, Predicate} = lists:nth(?random:uniform(Range), OptsMap),
380383
{Input, Opt, Predicate}
381384
end,
382385
Tests = [ Rand() || _ <- lists:seq(1, ?RUNS) ],
@@ -388,9 +391,9 @@ rand_pprint_opts() ->
388391
rand_pprint_slice() ->
389392
F = fun pprint/3,
390393
Rand = fun() ->
391-
Bytes = crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)),
392-
Pos = random:uniform(byte_size(Bytes)),
393-
Len = random:uniform(byte_size(Bytes)),
394+
Bytes = crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)),
395+
Pos = ?random:uniform(byte_size(Bytes)),
396+
Len = ?random:uniform(byte_size(Bytes)),
394397
{Bytes, Pos, Len}
395398
end,
396399
Tests = [ Rand() || _ <- lists:seq(1, ?RUNS) ],
@@ -403,9 +406,9 @@ rand_pprint_slice() ->
403406
rand_from_str() ->
404407
F = fun from_str/1,
405408
Rand = fun() ->
406-
Bytes = crypto:rand_bytes(random:uniform(?MAX_BIN_SIZE)),
409+
Bytes = crypto:strong_rand_bytes(?random:uniform(?MAX_BIN_SIZE)),
407410
{ok, Converted} = convert(Bytes),
408-
case random:uniform(2) of
411+
case ?random:uniform(2) of
409412
1 -> {lists:flatten(Converted), Bytes};
410413
2 -> {string:join(Converted, " "), Bytes}
411414
end

0 commit comments

Comments
 (0)