Skip to content

Commit f2258ad

Browse files
committed
Format tests/lib/*
Apply erlfmt using `rebar3 fmt`.
1 parent 42a3e98 commit f2258ad

File tree

12 files changed

+132
-114
lines changed

12 files changed

+132
-114
lines changed

tests/libs/eavmlib/test_logger.erl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ test() ->
7373

7474
ok.
7575

76-
7776
do_log({_Location, _Time, _Pid, Level, _Msg} = _LogRequest) ->
7877
increment_counter(Level).
7978

80-
8179
-record(state, {
8280
counters = [
8381
{info, 0},
@@ -104,13 +102,14 @@ get_counter(Level) ->
104102
{Ref, Counter} -> Counter
105103
end.
106104

107-
counter(#state{counters=Counters} = State) ->
108-
NewState = receive
109-
{increment, Level} ->
110-
Value = proplists:get_value(Level, Counters),
111-
State#state{counters=[{Level, Value + 1} | lists:keydelete(Level, 1, Counters)]};
112-
{Pid, Ref, get_counter, Level} ->
113-
Pid ! {Ref, proplists:get_value(Level, Counters)},
114-
State
115-
end,
105+
counter(#state{counters = Counters} = State) ->
106+
NewState =
107+
receive
108+
{increment, Level} ->
109+
Value = proplists:get_value(Level, Counters),
110+
State#state{counters = [{Level, Value + 1} | lists:keydelete(Level, 1, Counters)]};
111+
{Pid, Ref, get_counter, Level} ->
112+
Pid ! {Ref, proplists:get_value(Level, Counters)},
113+
State
114+
end,
116115
counter(NewState).

tests/libs/eavmlib/test_timer_manager.erl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ test_send_after() ->
4747
timer_manager:send_after(100, self(), ping),
4848
pong = wait_for_timeout(ping, 5000).
4949

50-
5150
wait_for_timeout(Msg, Timeout) ->
5251
receive
5352
{timeout, _TimerRef, Msg} ->
5453
ok;
5554
Msg ->
5655
pong
57-
after Timeout ->
58-
fail
56+
after Timeout -> fail
5957
end.

tests/libs/estdlib/test_gen_server.erl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).
2525

2626
-record(state, {
27-
num_casts=0,
28-
num_infos=0
27+
num_casts = 0,
28+
num_infos = 0
2929
}).
3030

3131
test() ->
@@ -88,9 +88,8 @@ test_info() ->
8888
gen_server:stop(Pid),
8989
ok.
9090

91-
92-
test_init_exception() ->
93-
try
91+
test_init_exception() ->
92+
try
9493
case gen_server:start(?MODULE, throwme, []) of
9594
{ok, _Pid} ->
9695
expected_error_on_exception;
@@ -102,7 +101,6 @@ test_info() ->
102101
{did_not_expect_an_exception, E}
103102
end.
104103

105-
106104
test_late_reply() ->
107105
{ok, Pid} = gen_server:start(?MODULE, [], []),
108106
%%
@@ -134,7 +132,7 @@ test_late_reply() ->
134132
test_concurrent_clients() ->
135133
{ok, Pid} = gen_server:start(?MODULE, [], []),
136134
Self = self(),
137-
P1 = spawn(fun() -> make_requests(Pid, Self, 1, 1000) end),
135+
P1 = spawn(fun() -> make_requests(Pid, Self, 1, 1000) end),
138136
P2 = spawn(fun() -> make_requests(Pid, Self, 10, 100) end),
139137
P3 = spawn(fun() -> make_requests(Pid, Self, 20, 50) end),
140138
wait_for(P1),
@@ -174,24 +172,27 @@ handle_call(async_ping, From, State) ->
174172
erlang:spawn(gen_server, reply, [From, pong]),
175173
{noreply, State};
176174
handle_call({reply_after, Ms, Reply}, From, State) ->
177-
spawn(fun() -> timer:sleep(Ms), gen_server:reply(From, Reply) end),
175+
spawn(fun() ->
176+
timer:sleep(Ms),
177+
gen_server:reply(From, Reply)
178+
end),
178179
{noreply, State};
179-
handle_call(get_num_casts, From, #state{num_casts=NumCasts} = State) ->
180+
handle_call(get_num_casts, From, #state{num_casts = NumCasts} = State) ->
180181
gen_server:reply(From, NumCasts),
181-
{noreply, State#state{num_casts=0}};
182-
handle_call(get_num_infos, From, #state{num_infos=NumInfos} = State) ->
182+
{noreply, State#state{num_casts = 0}};
183+
handle_call(get_num_infos, From, #state{num_infos = NumInfos} = State) ->
183184
gen_server:reply(From, NumInfos),
184-
{noreply, State#state{num_infos=0}}.
185+
{noreply, State#state{num_infos = 0}}.
185186

186187
handle_cast(crash, _State) ->
187188
throw(test_crash);
188-
handle_cast(ping, #state{num_casts=NumCasts} = State) ->
189-
{noreply, State#state{num_casts=NumCasts + 1}};
189+
handle_cast(ping, #state{num_casts = NumCasts} = State) ->
190+
{noreply, State#state{num_casts = NumCasts + 1}};
190191
handle_cast(_Request, State) ->
191192
{noreply, State}.
192193

193-
handle_info(ping, #state{num_infos=NumInfos} = State) ->
194-
{noreply, State#state{num_infos=NumInfos + 1}};
194+
handle_info(ping, #state{num_infos = NumInfos} = State) ->
195+
{noreply, State#state{num_infos = NumInfos + 1}};
195196
handle_info(_Info, State) ->
196197
{noreply, State}.
197198

tests/libs/estdlib/test_gen_statem.erl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
-export([init/1, initial/3, terminate/3]).
2525

2626
-record(data, {
27-
num_casts=0,
28-
num_infos=0
27+
num_casts = 0,
28+
num_infos = 0
2929
}).
3030

3131
test() ->
@@ -34,7 +34,6 @@ test() ->
3434
ok = test_info(),
3535
ok.
3636

37-
3837
test_call() ->
3938
{ok, Pid} = gen_statem:start(?MODULE, [], []),
4039
pong = gen_statem:call(Pid, ping),
@@ -78,14 +77,14 @@ init(_) ->
7877

7978
initial({call, From}, ping, Data) ->
8079
{next_state, initial, Data, [{reply, From, pong}]};
81-
initial(cast, ping, #data{num_casts=NumCasts} = Data) ->
82-
{next_state, initial, Data#data{num_casts=NumCasts+1}};
83-
initial(info, ping, #data{num_infos=NumInfos} = Data) ->
84-
{next_state, initial, Data#data{num_infos=NumInfos+1}};
85-
initial({call, From}, get_num_casts, #data{num_casts=NumCasts} = Data) ->
86-
{next_state, initial, Data#data{num_casts=0}, [{reply, From, NumCasts}]};
87-
initial({call, From}, get_num_infos, #data{num_infos=NumInfos} = Data) ->
88-
{next_state, initial, Data#data{num_infos=0}, [{reply, From, NumInfos}]}.
80+
initial(cast, ping, #data{num_casts = NumCasts} = Data) ->
81+
{next_state, initial, Data#data{num_casts = NumCasts + 1}};
82+
initial(info, ping, #data{num_infos = NumInfos} = Data) ->
83+
{next_state, initial, Data#data{num_infos = NumInfos + 1}};
84+
initial({call, From}, get_num_casts, #data{num_casts = NumCasts} = Data) ->
85+
{next_state, initial, Data#data{num_casts = 0}, [{reply, From, NumCasts}]};
86+
initial({call, From}, get_num_infos, #data{num_infos = NumInfos} = Data) ->
87+
{next_state, initial, Data#data{num_infos = 0}, [{reply, From, NumInfos}]}.
8988

9089
terminate(_Reason, _StateName, _Data) ->
9190
ok.

tests/libs/estdlib/test_gen_tcp.erl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ test_echo_server() ->
3434
{ok, {_Address, Port}} = inet:sockname(ListenSocket),
3535

3636
Self = self(),
37-
spawn(fun() -> Self ! ready, accept(Self, ListenSocket) end),
37+
spawn(fun() ->
38+
Self ! ready,
39+
accept(Self, ListenSocket)
40+
end),
3841
receive
3942
ready ->
4043
ok
@@ -47,7 +50,6 @@ test_echo_server() ->
4750

4851
ok.
4952

50-
5153
accept(Pid, ListenSocket) ->
5254
case gen_tcp:accept(ListenSocket) of
5355
{ok, Socket} ->
@@ -57,7 +59,6 @@ accept(Pid, ListenSocket) ->
5759
ok
5860
end.
5961

60-
6162
echo(Pid, Socket) ->
6263
receive
6364
{tcp_closed, _Socket} ->
@@ -68,7 +69,6 @@ echo(Pid, Socket) ->
6869
echo(Pid, Socket)
6970
end.
7071

71-
7272
test_send_receive(Port, N) ->
7373
{ok, Socket} = gen_tcp:connect(localhost, Port, [{active, true}]),
7474

@@ -77,11 +77,9 @@ test_send_receive(Port, N) ->
7777
gen_tcp:close(Socket),
7878
receive
7979
server_closed -> ok
80-
after 1000 ->
81-
throw(timeout)
80+
after 1000 -> throw(timeout)
8281
end.
8382

84-
8583
loop(_Socket, 0) ->
8684
ok;
8785
loop(Socket, I) ->

tests/libs/estdlib/test_gen_udp.erl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ test_send_receive_active() ->
3939
ok = gen_udp:close(Socket),
4040
ok.
4141

42-
4342
make_messages(0) ->
4443
[];
4544
make_messages(N) ->
4645
[<<"foo">> | make_messages(N - 1)].
4746

4847
start_sender(Socket, Port, Msgs) ->
4948
send(Socket, Port, Msgs),
50-
receive stop ->
51-
ok
49+
receive
50+
stop ->
51+
ok
5252
end.
5353

5454
send(_Socket, _Port, []) ->
5555
ok;
5656
send(Socket, Port, [Msg | Rest]) ->
57-
gen_udp:send(Socket, {127,0,0,1}, Port, Msg),
57+
gen_udp:send(Socket, {127, 0, 0, 1}, Port, Msg),
5858
send(Socket, Port, Rest).
5959

6060
count_received() ->
@@ -64,6 +64,5 @@ count_received(I) ->
6464
receive
6565
_Msg ->
6666
count_received(I + 1)
67-
after 100 ->
68-
I
67+
after 100 -> I
6968
end.

tests/libs/estdlib/test_io_lib.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ test() ->
5151
?ASSERT_MATCH(io_lib:format("~p", [foo]), "foo"),
5252
?ASSERT_MATCH(io_lib:format("\t~p", [bar]), "\tbar"),
5353

54-
?ASSERT_MATCH(io_lib:format("a ~p ~p of ~p patterns", [small, number, interesting]), "a small number of interesting patterns"),
54+
?ASSERT_MATCH(
55+
io_lib:format("a ~p ~p of ~p patterns", [small, number, interesting]),
56+
"a small number of interesting patterns"
57+
),
5558
?ASSERT_MATCH(io_lib:format("escape ~~p~n", []), "escape ~p\n"),
5659

5760
?ASSERT_FAILURE(io_lib:format("no pattern", [foo]), bad_format),

0 commit comments

Comments
 (0)