Skip to content

Commit

Permalink
[#89] Fix dialyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Brujo Benavides committed Nov 6, 2015
1 parent c6c2395 commit 9dbfbea
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROJECT = katana
DEPS = eper aleppo xref_runner
SHELL_DEPS := sync
TEST_DEPS = mixer
LOCAL_DEPS := xmerl tools compiler syntax_tools common_test inets ssl test_server dialyzer wx
LOCAL_DEPS := xmerl tools compiler syntax_tools common_test inets ssl test_server hipe public_key dialyzer wx

dep_eper = git https://github.com/massemanet/eper.git 0.96.3
dep_sync = git https://github.com/inaka/sync.git 0.1.3
Expand Down
5 changes: 3 additions & 2 deletions src/ktn_random.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ generate() ->
generate(Length) ->
gen_server:call(?MODULE, {random_string, Length}).

-spec uniform(non_neg_integer()) -> non_neg_integer().
-spec uniform(term()) -> non_neg_integer() | {error, {invalid_value, term()}}.
uniform(Max) ->
gen_server:call(?MODULE, {random_uniform, Max}).

-spec uniform(non_neg_integer(), non_neg_integer()) -> non_neg_integer().
-spec uniform(term(), term()) ->
non_neg_integer() | {error, {invalid_range, term(), term()}}.
uniform(Min, Max) ->
gen_server:call(?MODULE, {random_uniform, Min, Max}).

Expand Down
8 changes: 2 additions & 6 deletions src/ktn_recipe.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ run(Mod, InitialState) when is_atom(Mod) ->
-spec run(transitions(), step_fun(), step_fun(), term()) -> term().
run(Transitions, ResultFun, ErrorFun, InitialState) ->
NormalizedTransitions = normalize(Transitions),
InitialFun = initial_fun(Transitions),
InitialFun = initial_fun(NormalizedTransitions),
run(NormalizedTransitions, InitialFun, ResultFun, ErrorFun, InitialState).

-spec run(normalized_transitions(), output(), step_fun(), step_fun(), term()) ->
Expand Down Expand Up @@ -66,11 +66,7 @@ run(Transitions, StepFun, ResultFun, ErrorFun, State) ->
end.

-spec initial_fun(normalized_transitions()) -> step_fun().
initial_fun(Transitions) ->
case hd(Transitions) of
{InitialFun, _, _} -> InitialFun;
InitialFun -> InitialFun
end.
initial_fun([{InitialFun, _, _} | _]) -> InitialFun.

-spec normalize(module() | transitions()) -> normalized_transitions().
normalize(Mod) when is_atom(Mod) ->
Expand Down
10 changes: 5 additions & 5 deletions src/ktn_recipe_verify.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
, error => error()
}.

-spec transitions() -> verify_exports
| verify_normalizability
| verify_transitions
| verify_transition_exports
.
-spec transitions() -> [ verify_exports
| verify_normalizability
| verify_transitions
| verify_transition_exports
].
transitions() ->
[ verify_exports
, verify_normalizability
Expand Down
2 changes: 1 addition & 1 deletion src/ktn_user_default.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ l_all(Mod) ->
cmd(Cmd) ->
io:format("~s~n", [os:cmd(Cmd)]).

-spec all_modules() -> module().
-spec all_modules() -> [module()].
all_modules() ->
[ list_to_atom(
re:replace(
Expand Down
4 changes: 2 additions & 2 deletions test/ktn_binary_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end_per_suite(Config) ->
-spec join(config()) -> ok.
join(_Config) ->
Binaries = [<<"foo">>, <<"bar">>, <<"buzz">>],

<<>> = ktn_binary:join([], <<", ">>),
<<"foo">> = ktn_binary:join([<<"foo">>], <<", ">>),
<<"foo, bar, buzz">> = ktn_binary:join(Binaries, <<", ">>).
<<"foo, bar, buzz">> = ktn_binary:join(Binaries, <<", ">>),
ok.
7 changes: 4 additions & 3 deletions test/ktn_code_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ consult(_Config) ->

[{'.'}] = ktn_code:consult("{'.'}.\n"),
[{<<"ble.bla">>}, {"github.com"}] =
ktn_code:consult("{<<\"ble.bla\">>}.\n{\"github.com\"}.\r\n").

ktn_code:consult("{<<\"ble.bla\">>}.\n{\"github.com\"}.\r\n"),
ok.

-spec beam_to_string(config()) -> ok.
beam_to_string(_Config) ->
{error, beam_lib, _} = ktn_code:beam_to_string(bla),
{ok, _} = ktn_code:beam_to_string("../../ebin/ktn_code.beam").
{ok, _} = ktn_code:beam_to_string("../../ebin/ktn_code.beam"),
ok.

parse_tree(_Config) ->
ModuleNode = #{type => module,
Expand Down
12 changes: 8 additions & 4 deletions test/ktn_lists_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ delete_first(_Config) ->
[4] = ktn_lists:delete_first(Fun, [4, 4]),
[1, 3] = ktn_lists:delete_first(Fun, [1, 3]),
[1, 3] = ktn_lists:delete_first(Fun, [1, 4, 3]),
[1, 3, 4] = ktn_lists:delete_first(Fun, [1, 4, 3, 4]).
[1, 3, 4] = ktn_lists:delete_first(Fun, [1, 4, 3, 4]),
ok.

-spec split_when(config()) -> ok.
split_when(_Config) ->
Expand All @@ -65,7 +66,8 @@ split_when(_Config) ->
["."] = ktn_lists:split_when(IsDot, "."),
["{a}.", " {b}.", "{c, d, e}"] =
ktn_lists:split_when(IsDot, "{a}. {b}.{c, d, e}"),
["{a} {b}{c, d, e}"] = ktn_lists:split_when(IsDot, "{a} {b}{c, d, e}").
["{a} {b}{c, d, e}"] = ktn_lists:split_when(IsDot, "{a} {b}{c, d, e}"),
ok.

-spec map(config()) -> ok.
map(_Config) ->
Expand All @@ -76,7 +78,8 @@ map(_Config) ->
[2, 4, 6] = ktn_lists:map(Multiply, [2], [1, 2, 3]),

SumMultiply = fun(X, Y, Z) -> (X + Y) * Z end,
[30, 40, 50] = ktn_lists:map(SumMultiply, [2, 10], [1, 2, 3]).
[30, 40, 50] = ktn_lists:map(SumMultiply, [2, 10], [1, 2, 3]),
ok.

-spec filter(config()) -> ok.
filter(_Config) ->
Expand All @@ -87,4 +90,5 @@ filter(_Config) ->
[3] = ktn_lists:filter(Multiply, [2], [1, 2, 3]),

SumMultiply = fun(X, Y, Z) -> (X + Y) * Z =/= 30 end,
[2, 3] = ktn_lists:filter(SumMultiply, [2, 10], [1, 2, 3]).
[2, 3] = ktn_lists:filter(SumMultiply, [2, 10], [1, 2, 3]),
ok.
15 changes: 10 additions & 5 deletions test/ktn_maps_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ end_per_suite(Config) ->
find_nested_values(Config) ->
Map = proplists:get_value(map, Config),
8080 = ktn_maps:get([conversation, destination, port], Map),
1.5 = ktn_maps:get([location, latitude], Map).
1.5 = ktn_maps:get([location, latitude], Map),
ok.

-spec find_shallow_values(config()) -> ok.
find_shallow_values(Config) ->
Map = proplists:get_value(map, Config),
"john.doe" = ktn_maps:get(user, Map),
"John" = ktn_maps:get(name, Map),
"Doe" = ktn_maps:get(last_name, Map),
"john.doe" = ktn_maps:get([user], Map).
"john.doe" = ktn_maps:get([user], Map),
ok.

-spec dont_find_nested_values(config()) -> ok.
dont_find_nested_values(Config) ->
Expand All @@ -80,7 +82,8 @@ dont_find_nested_values(Config) ->
ktn_maps:get([social, facebook], Map)
catch
error:bad_path -> ok
end.
end,
ok.

-spec dont_find_shallow_values(config()) -> ok.
dont_find_shallow_values(Config) ->
Expand All @@ -99,7 +102,8 @@ dont_find_shallow_values(Config) ->
ktn_maps:get([email], Map)
catch
error:bad_path -> ok
end.
end,
ok.

-spec provide_default(config()) -> ok.
provide_default(Config) ->
Expand All @@ -118,4 +122,5 @@ provide_default(Config) ->

default = ktn_maps:get(username, Map, default),
default = ktn_maps:get(email, Map, default),
default = ktn_maps:get([email], Map, default).
default = ktn_maps:get([email], Map, default),
ok.
23 changes: 8 additions & 15 deletions test/ktn_os_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ command(_Config) ->
ok = try ktn_os:command("sleep 5", #{timeout => 1000})
catch _:timeout -> ok end,

Fun = fun() -> ktn_os:command("cd /; pwd") end,
FilterFun =
fun(Line) ->
case re:run(Line, "=INFO REPORT==== .* ===") of
nomatch -> false;
{match, _}-> true
end
end,
check_some_line_output(Fun, FilterFun),

ct:capture_start(),
{0, "/"} = ktn_os:command("cd /; pwd"),
ct:capture_stop(),
Lines = ct:capture_get([]),
ListFun = fun(Line) -> FilterFun(Line) end,
[_ | _] = lists:filter(ListFun, Lines),

ct:comment("Check result when process is killed"),
Self = self(),
Expand All @@ -67,17 +72,5 @@ command(_Config) ->
end
end,
erlang:spawn_link(YesFun),
os:cmd("pkill yes"),
[] = os:cmd("pkill yes"),
ok = receive X -> X after 1000 -> error end.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Helper functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

check_some_line_output(Fun, FilterFun) ->
ct:capture_start(),
Fun(),
ct:capture_stop(),
Lines = ct:capture_get([]),
ListFun = fun(Line) -> FilterFun(Line) end,
[_ | _] = lists:filter(ListFun, Lines).
13 changes: 5 additions & 8 deletions test/ktn_random_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ init_per_testcase(_, Config) ->
generate(_Config) ->
true = is_list(ktn_random:generate()),
16 = length(ktn_random:generate()),
25 = length(ktn_random:generate(25)).
25 = length(ktn_random:generate(25)),
ok.

-spec uniform(config()) -> ok.
uniform(_Config) ->
Expand All @@ -65,7 +66,8 @@ uniform(_Config) ->

do_times(fun (_) -> in_range(ktn_random:uniform(5, 90), 5, 90) end, Times),
{error, _} = ktn_random:uniform(165, 165),
{error, _} = ktn_random:uniform(15, 5).
{error, _} = ktn_random:uniform(15, 5),
ok.

-spec pick(config()) -> ok.
pick(_Config) ->
Expand All @@ -75,12 +77,7 @@ pick(_Config) ->
List = lists:seq($a, $a + I),
K = ktn_random:pick(List),
true = lists:member(K, List)
end, lists:seq(1, 1000)),
try ktn_random:pick([]) of
K -> ct:fail("Unexpected result: ~p", [K])
catch
_:function_clause -> ok
end.
end, lists:seq(1, 1000)).

do_times(Fun, N) ->
lists:foreach(Fun, lists:seq(1, N)).
Expand Down
2 changes: 2 additions & 0 deletions test/secure_vault.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
, closed/2
]).

-dialyzer({no_missing_calls, [start/2]}).

start(MasterPassword, MaxAttempts) ->
ktn_fsm:start(
?MODULE,
Expand Down

0 comments on commit 9dbfbea

Please sign in to comment.