From 7e642e3caedffdc524c0eef0df16ed86d9687993 Mon Sep 17 00:00:00 2001 From: Adam Lindberg Date: Wed, 12 Oct 2011 14:57:36 +0200 Subject: [PATCH] Rename count_calls/3+4 to num_calls --- src/meck.erl | 34 +++++++++++++++++----------------- test/meck_tests.erl | 26 +++++++++++++------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/meck.erl b/src/meck.erl index 04f19070..2f60235f 100644 --- a/src/meck.erl +++ b/src/meck.erl @@ -39,8 +39,8 @@ -export([unload/1]). -export([called/3]). -export([called/4]). --export([count_calls/3]). --export([count_calls/4]). +-export([num_calls/3]). +-export([num_calls/4]). %% Callback exports -export([init/1]). @@ -323,18 +323,18 @@ called(Mod, Fun, Args) -> called(Pid, Mod, Fun, Args) -> has_call({Mod, Fun, Args}, meck:history(Pid, Mod)). -%% @spec count_calls(Mod:: atom(), Fun:: atom(), Args:: list(term())) +%% @spec num_calls(Mod:: atom(), Fun:: atom(), Args:: list(term())) %% -> non_neg_integer() %% @doc Returns the number of times `Mod:Func' has been called with `Args'. %% %% This will check the history for the module, `Mod', to determine %% how many times the function, `Fun', was called with arguments, `Args' and %% returns the result. --spec count_calls(Mod::atom(), Fun::atom(), Args::list()) -> non_neg_integer(). -count_calls(Mod, Fun, Args) -> - i_count_calls({Mod, Fun, Args}, meck:history(Mod), 0). +-spec num_calls(Mod::atom(), Fun::atom(), Args::list()) -> non_neg_integer(). +num_calls(Mod, Fun, Args) -> + i_num_calls({Mod, Fun, Args}, meck:history(Mod), 0). -%% @spec count_calls(Pid:: pid(), Mod:: atom(), Fun:: atom(), +%% @spec num_calls(Pid:: pid(), Mod:: atom(), Fun:: atom(), %% Args:: list(term())) -> non_neg_integer() %% @doc Returns the number of times process `Pid' has called `Mod:Func' %% with `Args'. @@ -342,10 +342,10 @@ count_calls(Mod, Fun, Args) -> %% This will check the history for the module, `Mod', to determine how %% many times process `Pid' has called the function, `Fun', with %% arguments, `Args' and returns the result. --spec count_calls(Pid::pid(), Mod::atom(), Fun::atom(), Args::list()) +-spec num_calls(Pid::pid(), Mod::atom(), Fun::atom(), Args::list()) -> non_neg_integer(). -count_calls(Pid, Mod, Fun, Args) -> - i_count_calls({Mod, Fun, Args}, meck:history(Pid, Mod), 0). +num_calls(Pid, Mod, Fun, Args) -> + i_num_calls({Mod, Fun, Args}, meck:history(Pid, Mod), 0). %%============================================================================== %% Callback functions @@ -769,14 +769,14 @@ get_history_without_pid(History) -> remove_first_element(Tuple) when is_tuple(Tuple) -> list_to_tuple(tl(tuple_to_list(Tuple))). -i_count_calls(_MFA, [], Count) -> +i_num_calls(_MFA, [], Count) -> Count; -i_count_calls(MFA, [{MFA, _Result} | Rest], Count) -> - i_count_calls(MFA, Rest, Count + 1); -i_count_calls(MFA, [{MFA, _ExType, _Exception, _Stack} | Rest], Count) -> - i_count_calls(MFA, Rest, Count + 1); -i_count_calls(MFA, [_Call | Rest], Count) -> - i_count_calls(MFA, Rest, Count). +i_num_calls(MFA, [{MFA, _Result} | Rest], Count) -> + i_num_calls(MFA, Rest, Count + 1); +i_num_calls(MFA, [{MFA, _ExType, _Exception, _Stack} | Rest], Count) -> + i_num_calls(MFA, Rest, Count + 1); +i_num_calls(MFA, [_Call | Rest], Count) -> + i_num_calls(MFA, Rest, Count). has_call(FuncMatch, History) -> [] =/= match_history([{{FuncMatch, '_'}, [], ['$_']}, diff --git a/test/meck_tests.erl b/test/meck_tests.erl index ab6c638b..b1df75aa 100644 --- a/test/meck_tests.erl +++ b/test/meck_tests.erl @@ -73,9 +73,9 @@ meck_test_() -> fun called_false_error_/1, fun called_true_error_/1, fun called_with_pid_no_args_/1, - fun count_calls_/1, - fun count_calls_error_/1, - fun count_calls_with_pid_no_args_/1, + fun num_calls_/1, + fun num_calls_error_/1, + fun num_calls_with_pid_no_args_/1, fun called_wildcard_/1, fun sequence_/1, fun sequence_multi_/1, @@ -437,28 +437,28 @@ spawn_caller_and_sync(Mod, Func, Args) -> receive {Pid, done} -> ok end, % sync with the spawned process Pid. -count_calls_(Mod) -> +num_calls_(Mod) -> Args = [], IncorrectArgs = [foo], ok = meck:expect(Mod, test1, length(Args), ok), - ?assertEqual(0, meck:count_calls(Mod, test1, Args)), + ?assertEqual(0, meck:num_calls(Mod, test1, Args)), ok = apply(Mod, test1, Args), - ?assertEqual(1, meck:count_calls(Mod, test1, Args)), - ?assertEqual(0, meck:count_calls(Mod, test1, IncorrectArgs)). + ?assertEqual(1, meck:num_calls(Mod, test1, Args)), + ?assertEqual(0, meck:num_calls(Mod, test1, IncorrectArgs)). -count_calls_error_(Mod) -> +num_calls_error_(Mod) -> Args = [one, "two", {3, 3}], expect_catch_apply(Mod, test, Args), - ?assertEqual(1, meck:count_calls(Mod, test, Args)). + ?assertEqual(1, meck:num_calls(Mod, test, Args)). -count_calls_with_pid_no_args_(Mod) -> +num_calls_with_pid_no_args_(Mod) -> Args = [], ok = meck:expect(Mod, test, length(Args), ok), Pid = spawn_caller_and_sync(Mod, test, Args), - ?assertEqual(0, meck:count_calls(self(), Mod, test, Args)), - ?assertEqual(1, meck:count_calls(Pid, Mod, test, Args)), + ?assertEqual(0, meck:num_calls(self(), Mod, test, Args)), + ?assertEqual(1, meck:num_calls(Pid, Mod, test, Args)), ok = apply(Mod, test, Args), - ?assertEqual(1, meck:count_calls(self(), Mod, test, Args)). + ?assertEqual(1, meck:num_calls(self(), Mod, test, Args)). expect_apply(Mod, Func, Args) -> ok = meck:expect(Mod, Func, length(Args), ok),