diff --git a/Makefile b/Makefile index 5901f77..5efdc36 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/ktn_random.erl b/src/ktn_random.erl index d315b78..6e07d64 100644 --- a/src/ktn_random.erl +++ b/src/ktn_random.erl @@ -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}). diff --git a/src/ktn_recipe.erl b/src/ktn_recipe.erl index 0972bde..cbe9d4c 100644 --- a/src/ktn_recipe.erl +++ b/src/ktn_recipe.erl @@ -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()) -> @@ -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) -> diff --git a/src/ktn_recipe_verify.erl b/src/ktn_recipe_verify.erl index cf90b3e..5825939 100644 --- a/src/ktn_recipe_verify.erl +++ b/src/ktn_recipe_verify.erl @@ -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 diff --git a/src/ktn_user_default.erl b/src/ktn_user_default.erl index fa52810..170a1eb 100644 --- a/src/ktn_user_default.erl +++ b/src/ktn_user_default.erl @@ -14,7 +14,7 @@ xref() -> cmd(Cmd) -> io:format("~s~n", [os:cmd(Cmd)]). --spec all_modules() -> module(). +-spec all_modules() -> [module()]. all_modules() -> [ list_to_atom( re:replace( diff --git a/test/ktn_binary_SUITE.erl b/test/ktn_binary_SUITE.erl index 98219f9..22fbdc6 100644 --- a/test/ktn_binary_SUITE.erl +++ b/test/ktn_binary_SUITE.erl @@ -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. diff --git a/test/ktn_code_SUITE.erl b/test/ktn_code_SUITE.erl index d9da80e..ff959ad 100644 --- a/test/ktn_code_SUITE.erl +++ b/test/ktn_code_SUITE.erl @@ -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, diff --git a/test/ktn_lists_SUITE.erl b/test/ktn_lists_SUITE.erl index b206a4e..9adf24d 100644 --- a/test/ktn_lists_SUITE.erl +++ b/test/ktn_lists_SUITE.erl @@ -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) -> @@ -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) -> @@ -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) -> @@ -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. diff --git a/test/ktn_maps_SUITE.erl b/test/ktn_maps_SUITE.erl index 6616fd6..8c89b2a 100644 --- a/test/ktn_maps_SUITE.erl +++ b/test/ktn_maps_SUITE.erl @@ -58,7 +58,8 @@ 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) -> @@ -66,7 +67,8 @@ find_shallow_values(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) -> @@ -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) -> @@ -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) -> @@ -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. diff --git a/test/ktn_os_SUITE.erl b/test/ktn_os_SUITE.erl index ade3147..7850686 100644 --- a/test/ktn_os_SUITE.erl +++ b/test/ktn_os_SUITE.erl @@ -48,7 +48,6 @@ 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 @@ -56,7 +55,13 @@ command(_Config) -> {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(), @@ -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). diff --git a/test/ktn_random_SUITE.erl b/test/ktn_random_SUITE.erl index d406170..16ec3a0 100644 --- a/test/ktn_random_SUITE.erl +++ b/test/ktn_random_SUITE.erl @@ -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) -> @@ -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) -> @@ -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)). diff --git a/test/secure_vault.erl b/test/secure_vault.erl index 2e8a906..cad4278 100644 --- a/test/secure_vault.erl +++ b/test/secure_vault.erl @@ -29,6 +29,8 @@ , closed/2 ]). +-dialyzer({no_missing_calls, [start/2]}). + start(MasterPassword, MaxAttempts) -> ktn_fsm:start( ?MODULE,